123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136 |
- import numpy as np
- import time,sys
- #import requests
- import json
- import matplotlib
- import matplotlib as mpl
- mpl.use('Agg')
- import matplotlib.pyplot as plt
- import datetime
- import os
- import urllib
- import urllib.request
- import urllib.parse
- import base64
- #import cv2
- from PIL import Image
- import time
- import pymysql
- import cv2
- from concurrent.futures import ThreadPoolExecutor
- def img_nbackup(c,x):
- try:
- dress ="C:/Users/NB/Desktop/0/"+c+"/n"+x
- for root, dirs, files in os.walk(dress):
- #print('files: {}'.format(len(files)))
- if len(files) >= 1:
- files.sort()
- for f in files:
- localtime = time.strftime("%Y-%m-%d", time.localtime())
- if f[0:10] == localtime:
- with open(os.path.join(root, f), "rb") as imageFile:
- str = base64.b64encode(imageFile.read())
- url = 'http://60.250.156.230/cust/c1.php'
- values = {'data_ira': str, 'name_ira': f, 'nr': '1'}
- data1 = urllib.parse.urlencode(values)
- data1 = data1.encode('utf-8')
- req = urllib.request.Request(url, data1)
- req.add_header('User-Agent', 'Magic Browser')
- resp = urllib.request.urlopen(req)
- respdata1 = resp.read()
- print(os.path.join(root, f))
- # print(respdata1)
- # os.remove(os.path.join(root, f))
- #print("ok")
- except:
- print('error')
- def img_irbackup(c,x):
- try:
- dress ="C:/Users/NB/Desktop/0/"+c+"/ir"+x
- for root, dirs, files in os.walk(dress):
- #print('files: {}'.format(len(files)))
- if len(files) >= 1:
- files.sort()
- for f in files:
- localtime = time.strftime("%Y-%m-%d", time.localtime())
- if f[0:10] == localtime:
- with open(os.path.join(root, f), "rb") as imageFile:
- str = base64.b64encode(imageFile.read())
- url = 'http://60.250.156.230/cust/c1.php'
- values = {'data_ira': str, 'name_ira': f, 'nr': '1'}
- data1 = urllib.parse.urlencode(values)
- data1 = data1.encode('utf-8')
- req = urllib.request.Request(url, data1)
- req.add_header('User-Agent', 'Magic Browser')
- resp = urllib.request.urlopen(req)
- respdata1 = resp.read()
- print(os.path.join(root, f))
- # print(respdata1)
- # os.remove(os.path.join(root, f))
- #print("ok")
- except:
- print('error')
- def ndvi_backup(c,x):
- try:
- dress ="C:/Users/NB/Desktop/0/"+c+"/ndvi"+x
- for root, dirs, files in os.walk(dress):
- #print('files: {}'.format(len(files)))
- if len(files) >= 1:
- files.sort()
- for f in files:
- localtime = time.strftime("%Y-%m-%d", time.localtime())
- if f[0:10] == localtime:
- with open(os.path.join(root, f), "rb") as imageFile:
- str = base64.b64encode(imageFile.read())
- url = 'http://60.250.156.230/cust/c1.php'
- values = {'data_ira': str, 'name_ira': f, 'nr': '1'}
- data1 = urllib.parse.urlencode(values)
- data1 = data1.encode('utf-8')
- req = urllib.request.Request(url, data1)
- req.add_header('User-Agent', 'Magic Browser')
- resp = urllib.request.urlopen(req)
- respdata1 = resp.read()
- print(os.path.join(root, f))
- # print(respdata1)
- # os.remove(os.path.join(root, f))
- #print("ok")
- except:
- print('error')
- def main():
- start1 = time.time()
- for i in range(19):
- a = str(i)
- for j in range(9):
- b = str(j)
- img_nbackup(a, b)
- img_irbackup(a, b)
- ndvi_backup(a, b)
- end1 = time.time()
- print("time1: " + str(end1 - start1))
- pool = ThreadPoolExecutor(180)
- for i in range(19):
- d = str(i)
- for j in range(9):
- e = str(j)
- pool.submit(img_nbackup,d,e)
- pool.submit(img_irbackup,d,e)
- pool.submit(ndvi_backup,d,e)
- pool.shutdown()
- end3 = time.time()
- print("time3: " + str(end3 - end1))
- while True:
- updatetime = time.strftime("%H:%M", time.localtime())
- print(updatetime)
- if updatetime == "17:11":
- main()
- time.sleep(60)
|