some learning

1、windows下遷移access到mysql

            Windows下 Access 數據 遷移到 Mysql(5.5)數據庫

1. 具體作法
    1. 在access的表中選擇,文件->導出->保存類型->excel->填寫文件名

       - Navicat for mysql的表中,導入嚮導->excel類型-》選中剛纔的文件->下一步->。。。->對應目標欄位和源欄位->開始便可

       前提是:兩個表的字段數據類型一致。主鍵會比較麻煩,能夠先轉化後改動主鍵
    2. ODBC方式鏈接mysql數據庫 ,ODBC 作到access與mysql實時同步更新
    
    比較1和2,1是手動導入的方式,自主性強,可是相互之間不會實時更新,2更優!可是須要注意外鍵的關係
    
    
    
2. Access若存在外鍵關係
    1. 在access中製做表格時如何設置外鍵 
        手動創建兩表一對多參照完整性(關係能夠設定參照完整性,這樣你在其中一個表中更改或刪除記錄時,將同步到另外一個表)
            注:注意設置外鍵前一方表的關聯字段必須是主鍵或建有惟一索引
    2. 
        
    
3. 直接mysql上存access導入過來的表,django能執行嗎?   pymysql    orm   反向生成表
    
    - 將accss的表不用刻意去命名
    - python manage.py inspectdb > models.py 反向生成models.py
    - 替換models.py文件
    - python manage.py migrate
    - 正常ORM調用
    
    遷移過程問題分析:
        - 建表亂碼問題
            去除帶中文字段、手動添加外鍵等關係
        - 先正向生成models文件
        - 在將以前已經創建好關係的表直接粘貼到本數據庫中
        - Python manage.py inspectdb > models.py
        - 再正向生成migrate時會報重複的錯(already exists)
        - 直接 python manage.py migrate myapp --fake
        - 在已有的表上再加入外鍵
            - Dbtestcase
            - App01ProjFunc
        
    
4. 外鍵關係手動添加。。。。。  能使用嗎
    
View Code

2、 index頁面

    index.html設計
1. https://icons8.com/icons/set/find   icon圖標
2.  71.0.3578.98
3. jquery.flexisel.js 是一款響應式旋轉木馬插件,
它能夠擁有幻燈片播放,圖片展現,文章展現等等,
咱們今天手動把這個插件集成到wordpress中。本站
提供了DEMO下載。  
    - http://www.511yj.com/wordpress-flexisel-js.html
4. jqgrid
5. 臺架預定項目須要手動建立數據表 server_calenda 才能啓用
6. gritter 
    邊框提示插件
6. Ubuntu_16_04
    - D:\Documents\Virtual Machines\Ubuntu_16_04
7. 雲服務器的使用
    https://mp.weixin.qq.com/s/-9pqpz5FKTgPUi_1iRYnMQ
    
table 數據表格文檔 - layui.table

redis 
    - 若用戶多,session服務器     
    - 對於常常訪問的如首頁,則用緩存服務器
JWT
https://www.jianshu.com/p/576dbf44b2ae
    第一部分咱們稱它爲頭部(header),第二部分咱們稱其爲載荷
    (payload, 相似於飛機上承載的物品),第三部分是簽證(signature).
gritter
    像logo同樣的廣告顯示
to-do:
    1.設計後臺管理頁面
    2.作好incredidb反向生成的表,並創建外鍵關係正常查詢
        - 考慮建表的優化
    3.虛擬機安裝redis、mysql,正常使用
    4.在線瀏覽asp頁面輪播PPT顯示
        - jquery給將來元素添加style的屬性   https://zhidao.baidu.com/question/431431850462605412.html
        - 
    5.HTML裏面Textarea換行總結
             <script>
                     //換行轉回車
                     var haha=document.getElementById("SendTextArea").value;
                     haha=haha.replace('<br />','/n');
                     document.getElementById("SendTextArea").value=haha;
             </script>
View Code

3、自動化selenium爬

from selenium import webdriver

options = webdriver.ChromeOptions()

prefs = {'profile.default_content_settings.popups': 0,  # 設置爲 0 禁止彈出窗口
         'download.default_directory': 'D:\\chrome_downdir'}  # 設置下載路徑
options.add_experimental_option('prefs', prefs)

driver = webdriver.Chrome(chrome_options=options)
baidu = driver.get('http://www.baidu.com/')
length = len(driver.find_elements_by_tag_name("a"))
print(length)
import time

f = open('news.log', mode='a+')
links = driver.find_elements_by_tag_name("a")
for i in range(0,length):
    link = links[i]
    if not (len(link.get_attribute("href"))<33):
        f.write(str(i) +':'+link.get_attribute("href")+"\n")
        print('1111111111111')
        link.click()
        time.sleep(3)
        print('222222222222')
driver.back()

4、頁面中加入查閱PPT的功能

 <div class="pdf">
    <iframe id="pdf_page" name="pdf_page" style="width:1400px;height:800px">
    </iframe>
 </div>
  <script>
    <%if Request.QueryString("id")= "17113005" then%>  
        $(document).ready(function () {
            var url = "images/media/11111.pdf";//這裏就能夠作url動態切換--主要是使用iframe
            $("#pdf_page").attr("src", url);
            $(".pdf").media();
        });
   
    <%elseif Request.QueryString("id")= "17113004" then%>  
        $(document).ready(function () {
            var url = "images/media/2222.pdf";//這裏就能夠作url動態切換--主要是使用iframe
            $("#pdf_page").attr("src", url);
            $(".pdf").media();
        });
    <%end if%>
  </script>
View Code

5、學習爬蟲

1.commonutils.py


# -*- coding: UTF-8 -*-
import urllib2

#讀取配置文件
def readConfigFile(filename, dataDict):
    CANDataList = []
    VehicleDataList = []
    DataPathList = []
    try:
        configFile = file(filename)
        while True:
            line = configFile.readline()
            if len(line) == 0:
                break
            if line.startswith("CANData"):
                tmpList = line.split("=")[1].split(",")
                for i in tmpList:
                    CANDataList.append(i.strip())
                dataDict["CANData"] = CANDataList
            if line.startswith("VehicleData"):
                tmpList = line.split("=")[1].split(",")
                for i in tmpList:
                    VehicleDataList.append(i.strip())
                dataDict["VehicleData"] = VehicleDataList
            if line.startswith("DataPath"):
                tmpList = line.split("=")[1].split(",")
                for i in tmpList:
                    DataPathList.append(i.strip())
                dataDict["DataPath"] = DataPathList
    except:
        print "Exception: readConfigFile"
    else:
        print "Read config file successfully"
    finally:
        configFile.close()


def proxy_connect():
    proxy_handler = urllib2.ProxyHandler({"http": "http://proxy.baidu.com:8080/"})
    password_mgr = urllib2.HTTPPasswordMgrWithDefaultRealm()
    proxy_auth_handler = urllib2.ProxyBasicAuthHandler(password_mgr)
    proxy_auth_handler.add_password(None, "http://proxy.baidu.com:8080", "w000baidu", "baidu@123,.,")
    opener = urllib2.build_opener(proxy_handler, proxy_auth_handler)
    urllib2.install_opener(opener)

def createHtmlFile(content):
    try:
        hFile = file("htmlFile.txt", "w")
        hFile.write(content)
    except:
        print "Exception: htmlFile"
    else:
        print "htmlFile.txt is ok"
    finally:
        hFile.close()

def getZipList(filename):
    zipList = []
    try:
        hFile = file(filename)
        while True:
            line = hFile.readline()
            if len(line) == 0:
                break
            if ".zip" in line:
                zipName = line.split('">')[0].split("/")[-1]
                zipList.append(zipName)
    except:
        print "Exception: getZipList"
        zipList = []
    else:
        print "zipList is ok"
    finally:
        hFile.close()
    return zipList

2. conf

# -*- coding: UTF-8 -*-

#填寫服務器進行數據分類的CAN,以逗號分隔
#如: CANData = BMS_CHARGE, BmuInner, PowertraintSubnet, SmartSubnet

CANData = BmsCharge, ChargerCAN, BmuInner, BmuInnerCAN, PowertraintSubnet, SmartSubnet, PowertrainSubnet, EnergySubnet, OriginalSubnet

#填寫要獲取數據的車輛,以逗號分隔,以下
#如: VehicleData = 1st_car, 2nd_car, 3rd_car

VehicleData = 1st_car, 2nd_car, secondmodelx, modelx

#填寫服務器存儲數據路徑
#如: DataPath = /opt/BMS_Vehicle_Data/

DataPath = /home/bms/BMS_Vehicle_Data


3.htmlFile.txt


<HTML><HEAD><LINK HREF="jetty-dir.css" REL="stylesheet" TYPE="text/css"/><TITLE>Directory: /MON/secondmodelx/</TITLE></HEAD><BODY>
<H1>Directory: /MON/secondmodelx/</H1>
<TABLE BORDER=0>
<TR><TD><A HREF="/MON/secondmodelx/../">Parent Directory</A></TD><TD></TD><TD></TD></TR>
</TABLE>
</BODY></HTML>


4.index.html



<!DOCTYPE html>
<!--STATUS OK-->
<html>
<head>
    <meta http-equiv=content-type content=text/html;charset=utf-8>
    <meta http-equiv=X-UA-Compatible content=IE=Edge>
    <meta content=always name=referrer>
    <link rel=stylesheet type=text/css href=http://s1.bdstatic.com/r/www/cache/bdorz/baidu.min.css>
    <title>百度一下,你就知道</title></head>
<body link=#0000cc>
<div id=wrapper>
    <div id=head>
        <div class=head_wrapper>
            <div class=s_form>
                <div class=s_form_wrapper>
                    <div id=lg><img hidefocus=true src=//www.baidu.com/img/bd_logo1.png width=270 height=129></div>
                    <form id=form name=f action=//www.baidu.com/s class=fm><input type=hidden name=bdorz_come value=1>
                        <input type=hidden name=ie value=utf-8> <input type=hidden name=f value=8> <input type=hidden
                                                                                                          name=rsv_bp
                                                                                                          value=1>
                        <input type=hidden name=rsv_idx value=1> <input type=hidden name=tn value=baidu><span
                                class="bg s_ipt_wr"><input id=kw name=wd class=s_ipt value maxlength=255
                                                           autocomplete=off autofocus></span><span
                                class="bg s_btn_wr"><input type=submit id=su value=百度一下 class="bg s_btn"></span></form>
                </div>
            </div>
            <div id=u1><a href=http://news.baidu.com name=tj_trnews class=mnav>新聞</a> <a href=http://www.hao123.com
                                                                                         name=tj_trhao123 class=mnav>hao123</a>
                <a href=http://map.baidu.com name=tj_trmap class=mnav>地圖</a> <a href=http://v.baidu.com name=tj_trvideo
                                                                                class=mnav>視頻</a> <a
                        href=http://tieba.baidu.com name=tj_trtieba class=mnav>貼吧</a>
                <noscript><a
                        href=http://www.baidu.com/bdorz/login.gif?login&amp;tpl=mn&amp;u=http%3A%2F%2Fwww.baidu.com%2f%3fbdorz_come%3d1
                        name=tj_login class=lb>登陸</a></noscript>
                <script>document.write('<a href="http://www.baidu.com/bdorz/login.gif?login&tpl=mn&u=' + encodeURIComponent(window.location.href + (window.location.search === "" ? "?" : "&") + "bdorz_come=1") + '" name="tj_login" class="lb">登陸</a>');</script>
                <a href=//www.baidu.com/more/ name=tj_briicon class=bri style="display: block;">更多產品</a></div>
        </div>
    </div>
    <div id=ftCon>
        <div id=ftConw><p id=lh><a href=http://home.baidu.com>關於百度</a> <a href=http://ir.baidu.com>About Baidu</a></p>
            <p id=cp>&copy;2017&nbsp;Baidu&nbsp;<a href=http://www.baidu.com/duty/>使用百度前必讀</a>&nbsp; <a
                    href=http://jianyi.baidu.com/ class=cp-feedback>意見反饋</a>&nbsp;京ICP證030173號&nbsp; <img
                    src=//www.baidu.com/img/gs.gif></p></div>
    </div>
</div>
</body>
</html>




5.synchronizeData.py



# -*- coding: UTF-8 -*-
#!/usr/bin/python
# Filename : obtainData.py

import urllib2, sys, os, time
import commonUtils

def main(url, pathList, oldZipList, bakPath):
    try:
        #創建proxy鏈接
        commonUtils.proxy_connect()
        # 把url頁面源代碼寫入txt文本,並提取zip包名
        f = urllib2.urlopen(url)
        content = f.read()
        commonUtils.createHtmlFile(content)
        zipNameList = commonUtils.getZipList("htmlFile.txt")
        zipList = []
        #排除已經獲取的zip包名
        for i in zipNameList:
            logName = i[:-4] + ".log"
            if logName not in oldZipList:
                zipList.append(i)
        if len(zipList) == 0:
            print "There is no vehicle data to be synchronied."
            return
        #下載zip包並解壓
        for zipName in zipList:
            try:
                zipUrl = url + "/" + zipName
                path = None
                g = urllib2.urlopen(zipUrl)
                data = g.read()
                for i in pathList:
                    if zipName.split("_")[0] in i:
                        path = i
                        break
                serverPath = path + zipName
                with open(serverPath, "wb") as code:
                    code.write(data)
                t = 0
                while True:
                    if os.system("unzip -tq %s" % serverPath) == 0:
                        if os.system("unzip -q %s -d %s" % (serverPath, path)) == 0:
                            if os.system("rm %s" % serverPath) == 0:
                                print "Succeeded in unzip and removing the zip."
                        else:
                            print "Failed to upzip %s" % serverPath
                        break
                    else:
                        time.sleep(1)
                        t += 1
                        print "time.sleep %ds" % t
                        if t > 10:
                            os.system("mv %s %s" % (serverPath, bakPath))
                            break
            except:
                if os.path.isfile(serverPath):
                    print "An exception occurs when getting %s, so delete the zip." % serverPath
                    os.system("rm -r %s" % serverPath)
    except:
        print "There is an exception when synchronizing data."

if __name__ == "__main__":
    dataDict = {}
    sourceUrl = "http://1.2.3.4:8084/"
    while True:
        time.sleep(5)
        # 讀取配置文件
        commonUtils.readConfigFile("conf", dataDict)
        print dataDict
        CANDataList = dataDict["CANData"]
        VehicleDataList = dataDict["VehicleData"]
        DataPath = dataDict["DataPath"][0]
        #根據配置文件內容獲取數據
        for vehicle in VehicleDataList:
            bakPath = DataPath + os.sep + vehicle + os.sep + "bak" + os.sep
            if not os.path.isdir(bakPath):
                os.makedirs(bakPath)
            pathList = []
            oldZipList = []
            targetUrl = sourceUrl + "MON/" + vehicle
            for CAN in CANDataList:
                path = DataPath + os.sep + vehicle + os.sep + CAN + os.sep
                if not os.path.isdir(path):
                    os.makedirs(path)
                pathList.append(path)
                # 查找已經獲取過的zip包名
                oldZipList.extend(os.listdir(path))

            #處理已經獲取過的zip包名
            #oldZipFile = vehicle + "_" + CAN
            #oldZipList = []
            #if os.path.exists(oldZipFile):
            #    f = file(oldZipFile)
            #    oldZipList = cPickle.load(f)
            #    f.close()
            main(targetUrl, pathList, oldZipList, bakPath)
            #f = file(oldZipFile, "w")
            #cPickle.dump(templist, f)
            #f.close()


6.temp.log

# -*- coding: UTF-8 -*-
#!/usr/bin/python
# Filename : obtainData.py

import urllib2, sys, os, time
import commonUtils

def main(url, pathList, oldZipList, bakPath):
    try:
        #創建proxy鏈接
        commonUtils.proxy_connect()
        # 把url頁面源代碼寫入txt文本,並提取zip包名
        f = urllib2.urlopen(url)
        content = f.read()
        commonUtils.createHtmlFile(content)
        zipNameList = commonUtils.getZipList("htmlFile.txt")
        zipList = []
        #排除已經獲取的zip包名
        for i in zipNameList:
            logName = i[:-4] + ".log"
            if logName not in oldZipList:
                zipList.append(i)
        if len(zipList) == 0:
            print "There is no vehicle data to be synchronied."
            return
        #下載zip包並解壓
        for zipName in zipList:
            try:
                zipUrl = url + "/" + zipName
                path = None
                g = urllib2.urlopen(zipUrl)
                data = g.read()
                for i in pathList:
                    if zipName.split("_")[0] in i:
                        path = i
                        break
                serverPath = path + zipName
                with open(serverPath, "wb") as code:
                    code.write(data)
                t = 0
                while True:
                    if os.system("unzip -tq %s" % serverPath) == 0:
                        if os.system("unzip -q %s -d %s" % (serverPath, path)) == 0:
                            if os.system("rm %s" % serverPath) == 0:
                                print "Succeeded in unzip and removing the zip."
                        else:
                            print "Failed to upzip %s" % serverPath
                        break
                    else:
                        time.sleep(1)
                        t += 1
                        print "time.sleep %ds" % t
                        if t > 10:
                            os.system("mv %s %s" % (serverPath, bakPath))
                            break
            except:
                if os.path.isfile(serverPath):
                    print "An exception occurs when getting %s, so delete the zip." % serverPath
                    os.system("rm -r %s" % serverPath)
    except:
        print "There is an exception when synchronizing data."

if __name__ == "__main__":
    dataDict = {}
    sourceUrl = "http://1.2.3.4:8084/"
    while True:
        time.sleep(5)
        # 讀取配置文件
        commonUtils.readConfigFile("conf", dataDict)
        print dataDict
        CANDataList = dataDict["CANData"]
        VehicleDataList = dataDict["VehicleData"]
        DataPath = dataDict["DataPath"][0]
        #根據配置文件內容獲取數據
        for vehicle in VehicleDataList:
            bakPath = DataPath + os.sep + vehicle + os.sep + "bak" + os.sep
            if not os.path.isdir(bakPath):
                os.makedirs(bakPath)
            pathList = []
            oldZipList = []
            targetUrl = sourceUrl + "MON/" + vehicle
            for CAN in CANDataList:
                path = DataPath + os.sep + vehicle + os.sep + CAN + os.sep
                if not os.path.isdir(path):
                    os.makedirs(path)
                pathList.append(path)
                # 查找已經獲取過的zip包名
                oldZipList.extend(os.listdir(path))

            #處理已經獲取過的zip包名
            #oldZipFile = vehicle + "_" + CAN
            #oldZipList = []
            #if os.path.exists(oldZipFile):
            #    f = file(oldZipFile)
            #    oldZipList = cPickle.load(f)
            #    f.close()
            main(targetUrl, pathList, oldZipList, bakPath)
            #f = file(oldZipFile, "w")
            #cPickle.dump(templist, f)
            #f.close()
View Code
相關文章
相關標籤/搜索