Пример #1
0
def m1g_ftp_unix(info, src_path):
    ftp = FTP(info[0])
    ftp.login(info[1], info[2])
    ftp.cwd(info[3])
    ftp_list = ftp.nlst(info[3])
    
    # 建立FTP內檔案清單
    ftp_unix =[]
    for file in ftp_list:
        ftp_unix.append(file[-15:])

    # 比對本地端以及遠端檔案內容
    for dat in os.listdir(src_path):

        if dat in ftp_unix:
            pass
        else:
            print('Start   transmission for : '+ dat)
            file2ftp = open(src_path + dat, 'rb')
            try:
                ftp.storbinary('STOR %s' % dat , file2ftp)
                print('Finish  transmission at ' + datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"))
                line_msg.bot().send_text(msg2line + ' sync M1G and FTP successed.')
            except:
                print('Transmission error.')
                line_msg.bot().send_text(msg2line + ' sync error.')
                ftp.quit()
                sys.exit()
    print('sync done.')
Пример #2
0
def m1g_test():
    nowtime = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
    url      = 'http://192.168.10.1/record/'
    url_down = 'http://192.168.10.1/download.php'
    url_stat = 'http://192.168.10.1/#ib-status/'
    name = 'admin'
    pwd  = 'password'
    auth = HTTPBasicAuth(name,pwd)

    res = requests.get(url_down,auth=auth)
    soup = BeautifulSoup(res.text, 'lxml')
    file_info = {}
    dats = soup.select('tr')
    for i in range(len(dats)):
        last_file = dats[len(dats)-1].text[:12]
    for dat in dats[1:]:
        for i in range(len(dat.text)-12):
            num = 0
            if dat.text[12+i] == 'M':
                file_info[dat.text[:12]] = dat.text[12:13+i]
            elif dat.text[12+i] == 'K':
                file_info[dat.text[:12]] = dat.text[12:13+i]
            elif dat.text[12+i] == 'B':
                file_info[dat.text[:12]] = dat.text[12:13+i]
            else:
                pass
    for key in file_info.keys():
        print(key, file_info[key])
    
    size1 = file_info[last_file]
    print('Last file is : ' + last_file + ' ' +file_info[last_file])
    line_msg.bot().send_text(msg2line + 'Last file is : ' + last_file + ' ' +file_info[last_file])
    
    time.sleep(5)
    
    res = requests.get(url_down,auth=auth)
    soup = BeautifulSoup(res.text, 'lxml')
    dats = soup.select('tr')
    for i in range(len(dats)):
        last_file = dats[len(dats)-1].text[:12]
    for dat in dats[1:]:
        for i in range(len(dat.text)-12):
            num = 0
            if dat.text[12+i] == 'M':
                file_info[dat.text[:12]] = dat.text[12:13+i]
            elif dat.text[12+i] == 'K':
                file_info[dat.text[:12]] = dat.text[12:13+i]
    size2 = file_info[last_file]
    print('After 5 seconds : ' + last_file + ' ' +file_info[last_file])
    line_msg.bot().send_text(msg2line + 'After 5 seconds : ' + last_file + ' ' +file_info[last_file])
    if size2[:-1] > size1[:-1]:
        print('M1G is working well.' + datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"))
        line_msg.bot().send_text(msg2line + 'M1G is working well.' + ' ' +datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"))
    else:
        print('M1G 罷工了,檢查一下!' + datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"))
        line_msg.bot().send_text(msg2line + 'M1G 罷工了,檢查一下!' + ' ' +datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"))
Пример #3
0
def m1g_getData(ftp_server):
    nowtime = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
    url  = 'http://192.168.10.1/record/'
    name = 'admin'
    pwd  = 'password'
    auth = HTTPBasicAuth(name,pwd)

    res = requests.get(url,auth=auth)
    soup = BeautifulSoup(res.text, 'lxml')
    dats = soup.select('a')
    # 對要下載的檔案進行控制
    for dat in range(1,len(dats)-1):
        dat = dats[dat].text[1:]

        if dat in os.listdir(data_path):
            pass
        else:
            print('Start to download data.')
            urlretrieve(url+dat, data_path+dat)
            print(url+dat,data_path+dat + ' -> getDATA successed.')
            line_msg.bot().send_text(msg2line + ' get data to pi successed.')
Пример #4
0
def m1g_format():
    requests.post(url_submit, data = {'FORMAT':'DISK'})
    print('[ FORMAT ] M1G successed.' + datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S") + '\n')
    line_msg.bot().send_text(msg2line + '[ 格式化 ] M1G successed.')
Пример #5
0
def m1g_start():
    requests.post(url_submit, data = {'CMD':'DEVICE.RECORD.STARTRECORD'})
    print('Start M1G successed.' + datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S") + '\n')
    line_msg.bot().send_text(msg2line + ' Start M1G successed.')
Пример #6
0
def m1g_reboot():
    requests.post(url_submit, data = {'REBOOT':'TRUE'})
    print('Reboot M1G successed.')
    line_msg.bot().send_text(msg2line + ' Reboot M1G successed.')
Пример #7
0
def m1g_line():
    # line機器人所要傳送的訊息
    line_id_an  = line_msg.bot.an_id
    line_id_ro  = line_msg.bot.root_id
    line_text = 'Line fuction test at ' + datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
    line_msg.bot().send_text(msg2line + line_text)