img_backup .py 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. import numpy as np
  2. import time,sys
  3. #import requests
  4. import json
  5. import matplotlib
  6. import matplotlib as mpl
  7. mpl.use('Agg')
  8. import matplotlib.pyplot as plt
  9. import datetime
  10. import os
  11. import urllib
  12. import urllib.request
  13. import urllib.parse
  14. import base64
  15. #import cv2
  16. from PIL import Image
  17. import time
  18. import pymysql
  19. import cv2
  20. from concurrent.futures import ThreadPoolExecutor
  21. def img_nbackup(c,x):
  22. try:
  23. dress ="C:/Users/NB/Desktop/0/"+c+"/n"+x
  24. for root, dirs, files in os.walk(dress):
  25. #print('files: {}'.format(len(files)))
  26. if len(files) >= 1:
  27. files.sort()
  28. for f in files:
  29. localtime = time.strftime("%Y-%m-%d", time.localtime())
  30. if f[0:10] == localtime:
  31. with open(os.path.join(root, f), "rb") as imageFile:
  32. str = base64.b64encode(imageFile.read())
  33. url = 'http://60.250.156.230/cust/c1.php'
  34. values = {'data_ira': str, 'name_ira': f, 'nr': '1'}
  35. data1 = urllib.parse.urlencode(values)
  36. data1 = data1.encode('utf-8')
  37. req = urllib.request.Request(url, data1)
  38. req.add_header('User-Agent', 'Magic Browser')
  39. resp = urllib.request.urlopen(req)
  40. respdata1 = resp.read()
  41. print(os.path.join(root, f))
  42. # print(respdata1)
  43. # os.remove(os.path.join(root, f))
  44. #print("ok")
  45. except:
  46. print('error')
  47. def img_irbackup(c,x):
  48. try:
  49. dress ="C:/Users/NB/Desktop/0/"+c+"/ir"+x
  50. for root, dirs, files in os.walk(dress):
  51. #print('files: {}'.format(len(files)))
  52. if len(files) >= 1:
  53. files.sort()
  54. for f in files:
  55. localtime = time.strftime("%Y-%m-%d", time.localtime())
  56. if f[0:10] == localtime:
  57. with open(os.path.join(root, f), "rb") as imageFile:
  58. str = base64.b64encode(imageFile.read())
  59. url = 'http://60.250.156.230/cust/c1.php'
  60. values = {'data_ira': str, 'name_ira': f, 'nr': '1'}
  61. data1 = urllib.parse.urlencode(values)
  62. data1 = data1.encode('utf-8')
  63. req = urllib.request.Request(url, data1)
  64. req.add_header('User-Agent', 'Magic Browser')
  65. resp = urllib.request.urlopen(req)
  66. respdata1 = resp.read()
  67. print(os.path.join(root, f))
  68. # print(respdata1)
  69. # os.remove(os.path.join(root, f))
  70. #print("ok")
  71. except:
  72. print('error')
  73. def ndvi_backup(c,x):
  74. try:
  75. dress ="C:/Users/NB/Desktop/0/"+c+"/ndvi"+x
  76. for root, dirs, files in os.walk(dress):
  77. #print('files: {}'.format(len(files)))
  78. if len(files) >= 1:
  79. files.sort()
  80. for f in files:
  81. localtime = time.strftime("%Y-%m-%d", time.localtime())
  82. if f[0:10] == localtime:
  83. with open(os.path.join(root, f), "rb") as imageFile:
  84. str = base64.b64encode(imageFile.read())
  85. url = 'http://60.250.156.230/cust/c1.php'
  86. values = {'data_ira': str, 'name_ira': f, 'nr': '1'}
  87. data1 = urllib.parse.urlencode(values)
  88. data1 = data1.encode('utf-8')
  89. req = urllib.request.Request(url, data1)
  90. req.add_header('User-Agent', 'Magic Browser')
  91. resp = urllib.request.urlopen(req)
  92. respdata1 = resp.read()
  93. print(os.path.join(root, f))
  94. # print(respdata1)
  95. # os.remove(os.path.join(root, f))
  96. #print("ok")
  97. except:
  98. print('error')
  99. def main():
  100. start1 = time.time()
  101. for i in range(19):
  102. a = str(i)
  103. for j in range(9):
  104. b = str(j)
  105. img_nbackup(a, b)
  106. img_irbackup(a, b)
  107. ndvi_backup(a, b)
  108. end1 = time.time()
  109. print("time1: " + str(end1 - start1))
  110. pool = ThreadPoolExecutor(180)
  111. for i in range(19):
  112. d = str(i)
  113. for j in range(9):
  114. e = str(j)
  115. pool.submit(img_nbackup,d,e)
  116. pool.submit(img_irbackup,d,e)
  117. pool.submit(ndvi_backup,d,e)
  118. pool.shutdown()
  119. end3 = time.time()
  120. print("time3: " + str(end3 - end1))
  121. while True:
  122. updatetime = time.strftime("%H:%M", time.localtime())
  123. print(updatetime)
  124. if updatetime == "17:11":
  125. main()
  126. time.sleep(60)