test.py 82 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125
  1. from qcloudsms_py import SmsSingleSender
  2. from qcloudsms_py.httpclient import HTTPError
  3. from qcloudsms_py import SmsMultiSender
  4. import os
  5. import django
  6. import sys
  7. BASE_DIR = os.path.dirname(os.path.abspath(__file__)) # 定位到你的django根目录
  8. sys.path.append(os.path.abspath(os.path.join(BASE_DIR, os.pardir)))
  9. os.environ.setdefault("DJANGO_SETTINGS_MODULE",
  10. "yfwlw_pro.settings") # project_name 项目名称
  11. django.setup()
  12. import json
  13. import time
  14. import requests
  15. import datetime
  16. from apps.ReportManage.all_dict import mobile_list, insect_dict_new, qxz_dict
  17. from apps.AppInfoManage.models import Equip, Equip_type, CBDphoto, Msg_Send, Msg_Conf, Equip_SimInfo, SCDstatus, CBDstatus, RecentCBDdata, MyUser,JKphoto, BZYdata, QXZstatus,QXZdata,\
  18. QXZstatus_New, QXZ_Conf, QXZ_Default_Conf, JKphoto, Alarm_record, SCDdata, SCDstatus_all, QXZdata_New, CBDphoto_desc,BZYphoto, JKdata, User_Log, CBDstatus_all,\
  19. SCDstatus_all, YBQstatus, YBQphoto
  20. from apps.SimInfo.views import get_siminfo
  21. import paho.mqtt.client as mqtt
  22. # 短信应用 SDK AppID
  23. appid = 1400227496 # SDK AppID 以1400开头
  24. # 短信应用 SDK AppKey
  25. appkey = "c9aba961bd30072f1e1b9272077abaea"
  26. from requests.auth import HTTPBasicAuth
  27. from imutils import paths
  28. import cv2
  29. import shutil
  30. import random
  31. from django.db import transaction
  32. # print(random.randint(10,30))
  33. # 测试1
  34. import xlrd
  35. import xlwt
  36. import socket
  37. import re
  38. import random
  39. from PIL import Image
  40. from io import BytesIO
  41. from django.db.models import Q
  42. from operator import itemgetter
  43. def TimeStampToTime(timestamp):
  44. timeStruct = time.localtime(timestamp)
  45. str_p = time.strftime('%Y-%m-%d %H:%M:%S',timeStruct)
  46. dateTime_p = datetime.datetime.strptime(str_p,'%Y-%m-%d %H:%M:%S')
  47. return dateTime_p
  48. def get_FileCreateTime(filePath):
  49. # filePath = unicode(filePath,'utf8')
  50. t = os.path.getmtime(filePath)
  51. return TimeStampToTime(t)
  52. # aa = "/data/yfwlw/pyftp/ftp_file/ykm_cbd/868575028856005/20190317/03:22:36.jpg"
  53. # print(get_FileCreateTime(aa))
  54. imei = "868575028856005"
  55. equip_obj = Equip.objects.get(equip_id=imei)
  56. print(CBDphoto.objects.filter(equip_id=equip_obj).count())
  57. for i in CBDphoto.objects.filter(equip_id=equip_obj):
  58. print(i.addr)
  59. if "pyftp" in i.addr:
  60. print("---------->>",i.addr)
  61. # 9.24号查找出所有的害虫种类、和害虫数据
  62. # data = []
  63. # equip_list = Equip.objects.filter(equip_type="3")
  64. # for x in equip_list:
  65. # data.append(x.equip_id)
  66. # print(len(data))
  67. # # print(data)
  68. # pes_dp = [] # 害虫种类
  69. # pests_num = [] # 害虫数量
  70. # # data = ["868956044831316"]
  71. # # sum = 0
  72. # num = 0
  73. # for i in data:
  74. # pest_photo = CBDphoto.objects.filter(equip_id=i)
  75. # if pest_photo:
  76. # pests = [] # 害虫种类
  77. # pests_num = [] # 害虫数量
  78. # sum = 0
  79. # num = 0
  80. # for y in pest_photo:
  81. # if y.indentify_result:
  82. # if y.indentify_result.find("#") != -1:
  83. # xx_result = y.indentify_result.split("#")
  84. # for yy in xx_result:
  85. # yy_result = yy.split(",")
  86. # if yy_result[0] not in pests:
  87. # pests.append(yy_result[0])
  88. # sum = sum + int(yy_result[1])
  89. # else:
  90. # yy_result = y.indentify_result.split(",")
  91. # if len(yy_result) >= 2:
  92. # # print(yy_result[1])
  93. # if yy_result[0] not in pests:
  94. # pests.append(yy_result[0])
  95. # num = num + int(yy_result[1])
  96. # sp = {"equip_id":y.equip_id,"spt":sum+num}
  97. # pes_dp.append(sp)
  98. # nums = 0
  99. # print(pes_dp[:5])
  100. # for xx in pes_dp:
  101. # nums = nums + int(xx["spt"])
  102. # print(nums)
  103. # sum = 0
  104. # cbd_photo = CBDphoto.objects.all()
  105. # for yy in cbd_photo:
  106. # # 判断识别不未空的数据
  107. # if yy.indentify_result:
  108. # pest_photo = yy.indentify_result.split("#")
  109. # for xx in pest_photo:
  110. # xx_result = xx.split(',')
  111. # if xx_result[0] not in pests:
  112. # pests.append(xx_result[0])
  113. # sum = sum + int(xx_result[1])
  114. # st = {"equip_id":y,"dat":len(pests)}
  115. # sp = {"equip_id":y,"spt":sum}
  116. # pes_da.append(st)
  117. # pes_dp.append(sp)
  118. # rows = sorted(pes_da, key=itemgetter("dat"),reverse=True)[:20]
  119. # num = sorted(pes_dp, key=itemgetter("spt"),reverse=True)[:20]
  120. # print("害虫种类",rows)
  121. # print("害虫数量",num)
  122. # etype = "4.0测报灯"
  123. # sta1 = CBDstatus.objects.filter(etype=etype)
  124. # is_online = "0"
  125. # sta3 = []
  126. # # sta1 = sta1.filter(etype=etype)
  127. # for i in sta1:
  128. # fir_v = eval(i.cbd_status)["dver"]
  129. # if i.is_online == is_online:
  130. # sta3.append({"equip_id":i.equip_id_id,"lng":i.lng,"lat":i.lat, "fir_v":fir_v,
  131. # "is_online":i.is_online,"off_time":i.off_time})
  132. # print(sta3)
  133. # data1 = []
  134. # for x in sta3:
  135. # if x["lat"]:
  136. # res = requests.post("http://api.map.baidu.com/geocoder?location=%s,%s&coord_type=gcj02&output=json"%(x["lat"],x["lng"]))
  137. # try:
  138. # print(eval(res.text))
  139. # print((eval(res.text))["result"]["addressComponent"]["province"])
  140. # # print((eval(res.text))["result"]["formatted_address"])
  141. # except:
  142. # continue
  143. # location = (eval(res.text))["result"]["addressComponent"]["province"] + (eval(res.text))["result"]["addressComponent"]["city"] + (eval(res.text))["result"]["addressComponent"]["district"]
  144. # data1.append({"equip_id":x["equip_id"],"fir_v":x["fir_v"],"location":location,"is_online":x["is_online"],"off_time":x["off_time"]})
  145. # # print("=============>>",sta3)
  146. # title = ["设备id","设备版本","设备位置","是否在线","离线时间"]
  147. # book = xlwt.Workbook() # 创建一个excel对象
  148. # sheet = book.add_sheet('Sheet1',cell_overwrite_ok=True) # 添加一个sheet页
  149. # for i in range(len(title)): # 遍历列
  150. # # sheet.write(0,i,title[i],style) # 将title数组中的字段写入到0行i列中
  151. # sheet.write(0,i,title[i]) # 将title数组中的字段写入到0行i列中
  152. # # print(sta2)
  153. # for xx in range(len(data1)): # 遍历列表
  154. # if data1[xx]['is_online'] == "0":
  155. # is_online = "离线"
  156. # off_time = datetime.datetime.strftime(data1[xx]['off_time'],'%Y-%m-%d %H:%M:%S')
  157. # else:
  158. # is_online = "在线"
  159. # off_time = ""
  160. # sheet.write(xx+1,0,data1[xx]['equip_id']) # 将equip_id写入到第x+1行,第0列中
  161. # sheet.write(xx+1,1,data1[xx]['fir_v'])
  162. # sheet.write(xx+1,2,data1[xx]['location'])
  163. # sheet.write(xx+1,3,is_online)
  164. # sheet.write(xx+1,4,off_time)
  165. # sheet.col(0).width = 256 * 18
  166. # sheet.col(1).width = 256 * 11
  167. # sheet.col(2).width = 256 * 24
  168. # sheet.col(3).width = 256 * 8
  169. # sheet.col(4).width = 256 * 11
  170. # book.save("654321.xlsx")
  171. # 9.21号
  172. # 查找害虫种类最多
  173. #1、查找区分设备是圆盘还是方形盘
  174. # equip_list = Equip.objects.filter(equip_type__type_id="3")
  175. # print(len(equip_list))
  176. # data = [] # 海康圆盘
  177. # date = [] # 方盘
  178. # cbd_status = CBDstatus.objects.all()
  179. # for x in cbd_status:
  180. # dver = eval(x.cbd_status)["dver"]
  181. # if dver.startswith("5") and dver.endswith("HK"):
  182. # data.append(x.equip_id)
  183. # else:
  184. # date.append(x.equip_id)
  185. # #2、查看圆盘种类数量最多的设备
  186. # #害虫种类
  187. # da = []
  188. # dp = []
  189. # # data = ["868956044831316","862991419825259"]
  190. # # 害虫数量
  191. # pes_da = []
  192. # pes_dp = []
  193. # # pests = [] # 害虫种类
  194. # # pests_num = [] # 害虫数量
  195. # for y in date:
  196. # cbd_photo = CBDphoto.objects.filter(equip_id=y)
  197. # pests = [] # 害虫种类
  198. # pests_num = [] # 害虫数量
  199. # sum = 0
  200. # for yy in cbd_photo:
  201. # # 判断识别不未空的数据
  202. # if yy.indentify_result:
  203. # #判断识别结果包含多个的
  204. # # pest_dat = [] # 害虫种类
  205. # # pest_num = [] # 害虫数量\
  206. # # pests = [] # 害虫种类
  207. # # pests_num = [] # 害虫数量
  208. # pest_photo = yy.indentify_result.split("#")
  209. # for xx in pest_photo:
  210. # xx_result = xx.split(',')
  211. # if xx_result[0] not in pests:
  212. # pests.append(xx_result[0])
  213. # sum = sum + int(xx_result[1])
  214. # st = {"equip_id":y,"dat":len(pests)}
  215. # sp = {"equip_id":y,"spt":sum}
  216. # pes_da.append(st)
  217. # pes_dp.append(sp)
  218. # rows = sorted(pes_da, key=itemgetter("dat"),reverse=True)[:20]
  219. # num = sorted(pes_dp, key=itemgetter("spt"),reverse=True)[:20]
  220. # print("害虫种类",rows)
  221. # print("害虫数量",num)
  222. # #排序 害虫种类
  223. # rows = sorted(pests, key=itemgetter("dat"),reverse=True)
  224. # for x in rows:
  225. # if x["equip_id"] not in da:
  226. # da.append(x["equip_id"])
  227. # dp.append(x)
  228. # # print(pests_num)
  229. # #排序害虫数量
  230. # rowss = sorted(pests_num, key=itemgetter("sp"),reverse=True)
  231. # # print(rowss)
  232. # for x in rowss:
  233. # if x["equip_id"] not in pes_da:
  234. # pes_da.append(x["equip_id"])
  235. # pes_dp.append(x)
  236. # num = sorted(dp, key=itemgetter("dat"),reverse=True)[:20]
  237. # nums = sorted(pes_dp, key=itemgetter("sp"),reverse=True)[:20]
  238. # print("害虫种类",num)
  239. # print("害虫数量",nums)
  240. # pests.append(st)
  241. # print(num)
  242. # pest.append(pests)
  243. # pests = []
  244. # else:
  245. # print("11")
  246. # pests.append(xx_result[0])
  247. # print(pests)
  248. # pest.append(pests)
  249. # print(pest)
  250. # cbd_photo = CBDphoto.objects.all()
  251. # for i in cbd_photo:
  252. # import oss2
  253. # print(CBDphoto.objects.filter(addr__contains="cbd_img").count())
  254. # print(datetime.datetime.now())
  255. # current_user = MyUser.objects.get(username=current_user)
  256. # equip_list = Equip.objects.filter(equip_user=current_user)
  257. # data = []
  258. # for i in equip_list:
  259. # if i.equip_type_id in data:
  260. # continue
  261. # data.append(i.equip_type_id)
  262. # if current_user.is_superuser:
  263. # data = []
  264. # type_list = Equip_type.objects.all()
  265. # for x in type_list:
  266. # data.append(x.type_id)
  267. # elif current_user.is_agency:
  268. # data = []
  269. # equip_list = Equip.objects.filter(equip_agency=current_user.user_agency)
  270. # for i in equip_list:
  271. # if i.equip_type_id in data:
  272. # continue
  273. # data.append(i.equip_type_id)
  274. # print(Equip.objects.values('equip_type_id').distinct())
  275. # path = "/data/yfwlw/pyftp/ftp_file/bzy_photo"
  276. # # path = "/home/web/yfwlw/pyftp/ftp_file/bzy_test"
  277. # dirs = os.walk(path)
  278. # for root,dir1,files in dirs:
  279. # # print("root",root)
  280. # # print("dir1",dir1)
  281. # # print("files",files)
  282. # if files != [] and "jpg" in files[0]:
  283. # for i in files:
  284. # imgaddr = root + "/" + i
  285. # print("------->>",imgaddr)
  286. # print(imgaddr.split('/')[6])
  287. #9.11号测试sim入库剩余流量和已用流量保存两位小数
  288. # iccid = "89860439101880591280"
  289. # imei = "860344048805221"
  290. # res = get_siminfo(iccid)
  291. # sim_res = res.text.encode('utf-8').decode('unicode_escape')
  292. # print(sim_res)
  293. # data_usage = float('%.2f' % eval(sim_res)["data"]["data_usage"])
  294. # data_balance = float('%.2f' % eval(sim_res)["data"]["data_balance"])
  295. # print(data_balance)
  296. # print(data_usage)
  297. # print(type(data_usage))
  298. # # 9.10号分配邱玲195台设备
  299. # username = MyUser.objects.get(username="南京睿泽生物技术有限公司")
  300. # book=xlrd.open_workbook('邱玲.xlsx')
  301. # sheet=book.sheet_by_name('Sheet1')
  302. # lists = sheet.col_values(0)#获取到整列的内容
  303. # datt = [] #已绑定用户
  304. # dat = [] #未找到设备号
  305. # for i in lists:
  306. # equip_list = Equip.objects.filter(equip_id=str(int(i)))
  307. # if equip_list:
  308. # for x in equip_list:
  309. # if x.equip_user:
  310. # datt.append(x.equip_id)
  311. # else:
  312. # x.equip_user = username
  313. # x.save()
  314. # else:
  315. # dat.append(str(int(i)))
  316. # print("设备已绑定用户=====",datt)
  317. # print("未找到设备号=====",dat)
  318. # auth = oss2.Auth('LTAI4G7tFh5Nk4KXZoSPk1D8', 'RV4S2SfbLPoFNjlI4uIOoA0J1LQPQc')
  319. # # Endpoint以杭州为例,其它Region请按实际情况填写。
  320. # # bucket = oss2.Bucket(auth, 'http://oss-cn-hangzhou.aliyuncs.com', '<yourBucketName>')
  321. # # bucket = oss2.Bucket(auth, 'https://cbdphoto.oss-cn-hangzhou.aliyuncs.com', 'cbdphoto')
  322. # bucket = oss2.Bucket(auth, 'http://oss-cn-hangzhou.aliyuncs.com', 'bzypic')
  323. # def TimeStampToTime(timestamp):
  324. # timeStruct = time.localtime(timestamp)
  325. # str_p = time.strftime('%Y-%m-%d %H:%M:%S',timeStruct)
  326. # dateTime_p = datetime.datetime.strptime(str_p,'%Y-%m-%d %H:%M:%S')
  327. # return dateTime_p
  328. # def get_FileCreateTime(filePath):
  329. # # filePath = unicode(filePath,'utf8')
  330. # t = os.path.getctime(filePath)
  331. # return TimeStampToTime(t)
  332. # #8.31好删除害虫编号为36的识别结果
  333. # imei = "866262040450529"
  334. # equip_obj = Equip.objects.get(equip_id=imei)
  335. # file_dir = "../pyftp/ftp_file/bzy_photo/%s"%imei
  336. # for root, dirs, file in os.walk(file_dir):
  337. # if file != [] and "jpg" in file[0]:
  338. # # print("当前路径下所有非目录子文件>>",file)
  339. # for i in file:
  340. # pic_addr_1 = root + "/" + i
  341. # pic_addr = pic_addr_1.replace("../","")
  342. # picname_1 = get_FileCreateTime(pic_addr_1)
  343. # print("文件时间为",picname_1)
  344. # # now = datetime.datetime.now()
  345. # strnow = datetime.datetime.strftime(picname_1,'%Y%m')
  346. # picname = datetime.datetime.strftime(picname_1,'%Y%m%d%H%M%S')
  347. # # bucket_pic = bucket.put_object_from_file(strnow + '/' + imei + '/'+ picname + '.jpg', pic_addr_1)
  348. # print("图片数据库路径为pic_addr",pic_addr)
  349. # new_addr = "https://bzypic.oss-cn-hangzhou.aliyuncs.com/" + strnow + '/' + imei + '/'+ picname + '.jpg'
  350. # exist = bucket.object_exists(strnow + '/' + imei + '/'+ picname + '.jpg')
  351. # if BZYphoto.objects.filter(addr=pic_addr).exists():
  352. # print("照片存在")
  353. # print("新的照片路径为",new_addr)
  354. # # 返回值为true表示文件存在,false表示文件不存在。
  355. # if exist:
  356. # if BZYphoto.objects.filter(addr=new_addr).exists():
  357. # BZYphoto.objects.filter(addr=new_addr).update(equip_id=equip_obj,upl_time=picname_1)
  358. # print('object exist')
  359. # BZYphoto.objects.filter(addr=pic_addr).update(equip_id=equip_obj,addr=new_addr,upl_time=picname_1)
  360. # else:
  361. # BZYphoto.objects.filter(addr=pic_addr).update(equip_id=equip_obj,addr=new_addr,upl_time=picname_1)
  362. # bucket_pic = bucket.put_object_from_file(strnow + '/' + imei + '/'+ picname + '.jpg', pic_addr_1)
  363. # print("oss传输成功")
  364. # print('object not exist')
  365. # else:
  366. # print("照片不存在")
  367. # # print("图片时间为",get_FileCreateTime(picname))
  368. # if exist:
  369. # if BZYphoto.objects.filter(addr=new_addr).exists():
  370. # BZYphoto.objects.filter(addr=new_addr).update(equip_id=equip_obj,upl_time=_time)
  371. # else:
  372. # print('object exist')
  373. # BZYphoto.objects.create(equip_id=imei,addr=new_addr,upl_time=picname_1)
  374. # else:
  375. # if BZYphoto.objects.filter(addr=new_addr).exists():
  376. # print("新照片链接存在更新时间")
  377. # BZYphoto.objects.filter(addr=new_addr).update(equip_id=equip_obj,upl_time=picname_1)
  378. # else:
  379. # print("新照片链接不存在新建")
  380. # print('object exist')
  381. # BZYphoto.objects.create(equip_id=imei,addr=new_addr,upl_time=picname_1)
  382. # # BZYphoto.objects.create(equip_id=imei,addr=new_addr,upl_time=picname)
  383. # bucket_pic = bucket.put_object_from_file(strnow + '/' + imei + '/'+ picname + '.jpg', pic_addr_1)
  384. # print("oss传输成功")
  385. # print('object not exist')
  386. # equip = "867814040037125"
  387. # equip_list = CBDphoto.objects.filter(equip_id=equip)
  388. # # equip_lists = CBDphoto.objects.filter(~Q(indentify_result=None) and ~Q(indentify_result=),equip_id=equip)
  389. # data = []
  390. # date = []
  391. # da = []
  392. # d = []
  393. # print("总数",equip_list.count())
  394. # # print(len(equip_lists))
  395. # for i in equip_list:
  396. # if i.indentify_result:
  397. # if i.indentify_result.find("#") >=0:
  398. # pest = i.indentify_result.split("#")
  399. # else:
  400. # pest = []
  401. # pest.append(i.indentify_result)
  402. # print("删除前",pest)
  403. # for x in pest:
  404. # if x.find("36") >=0:
  405. # pest.remove(x)
  406. # else:
  407. # print("88")
  408. # # pest.append("89")
  409. # # print("#".join(pest))
  410. # print("删除后",pest)
  411. # i.indentify_result = "#".join(pest)
  412. # i.save()
  413. # da.append(i.indentify_result)
  414. # if i.indentify_result.find("#") >=0:
  415. # pest = i.indentify_result.split("#")
  416. # else:
  417. # pest = []
  418. # pest.append(i.indentify_result)
  419. # # print("删除前",pest)
  420. # for x in pest:
  421. # if x.find("36") >=0:
  422. # # pest.remove(x)
  423. # date.append(x)
  424. # else:
  425. # data.append(x)
  426. # else:
  427. # d.append(i.indentify_result)
  428. # print("不为空的总数",len(da))
  429. # print("包含36",len(date))
  430. # print("不包含36",len(data))
  431. # print("空总数",len(d))
  432. # if i.indentify_result.find("#") >=0:
  433. # pest = i.indentify_result.split("#")
  434. # else:
  435. # pest = []
  436. # pest.append(i.indentify_result)
  437. # print("删除前",pest)
  438. # for x in pest:
  439. # if x.find("36") >=0:
  440. # pest.remove(x)
  441. # else:
  442. # print("88")
  443. # # pest.append("89")
  444. # # print("#".join(pest))
  445. # print("删除后",pest)
  446. # i.indentify_result = "#".join(pest)
  447. # i.save()
  448. # print(len(data))
  449. # #8.12号生成测报灯识别图片
  450. # equip_list = [
  451. # "868956044806713",
  452. # "868956044823551",
  453. # ]
  454. # url = 'http://60.166.14.184:9143/upload'
  455. # for i in equip_list:
  456. # cbd_list = CBDphoto.objects.filter(equip_id=i)
  457. # lng = CBDstatus.objects.get(equip_id=i).lng
  458. # lat = CBDstatus.objects.get(equip_id=i).lat
  459. # for x in cbd_list:
  460. # print("原图",x.addr)
  461. # print("识别后的图片",x.indentify_photo)
  462. # if x.indentify_photo:
  463. # tes = x.indentify_photo.split("/")
  464. # try:
  465. # # print("/home/web/yfwlw/" + x.addr)
  466. # print("/data/yfwlw/" + x.addr)
  467. # # 测试服务器路径
  468. # # imageFile = {'imageFile':('pic.jpg',open("/home/web/yfwlw/" + x.addr,'rb'),'image/jpeg')}
  469. # imageFile = {'imageFile':('pic.jpg',open("/data/yfwlw/" + x.addr,'rb'),'image/jpeg')}
  470. # data = {'longitude':lng,'latitude':lat}
  471. # print('data:',data)
  472. # res = requests.post(url,data=data,files=imageFile,timeout=10)
  473. # print("res:",res.text)
  474. # resp = json.loads(res.text)
  475. # print("resp------------",resp)
  476. # img_src = resp["returnResult"]["returnImageUrl"]
  477. # response = requests.get(img_src)
  478. # print("img_src-------------",img_src)
  479. # print(response)
  480. # code = 1
  481. # except Exception as e:
  482. # print(e)
  483. # code = 0
  484. # if code == 1:
  485. # try:
  486. # if resp["returnResult"]["returnStatus"] == "0":
  487. # print("识别结果为空,不进行保存")
  488. # else:
  489. # # 将识别结果中的链接中的图片存入本地 测试服务器
  490. # # pic_dir_1 = "/home/web/yfwlw/result_pyftp/ftp_file/ykm_cbd/" + i + "/"
  491. # #正式服务器
  492. # pic_dir_1 = "/data/yfwlw/result_pyftp/ftp_file/ykm_cbd/" + i + "/"
  493. # print("pic_dir_1:",pic_dir_1)
  494. # if os.path.exists(pic_dir_1) == False:
  495. # os.makedirs(pic_dir_1)
  496. # response = requests.get(img_src)
  497. # image = Image.open(BytesIO(response.content))
  498. # insect_image_addr = pic_dir_1 + tes[-1]
  499. # print("insect_image_addr:",insect_image_addr)
  500. # image.save(insect_image_addr)
  501. # print("------------------图片保存成功")
  502. # except Exception as e:
  503. # print(e)
  504. # equip_obj = Equip.objects.get(equip_id="867814040037125")
  505. # cbd_photo_list = CBDphoto.objects.filter(equip_id="869300039253749")
  506. # for i in cbd_photo_list:
  507. # addr = i.addr.replace("869300039253749","867814040037125")
  508. # i.equip_id = equip_obj
  509. # i.addr = addr
  510. # i.save()
  511. # _list = YBQstatus.objects.all()
  512. # for i in _list:
  513. # # print(eval(i.ybq_status)['iccid'])
  514. # iccid = eval(i.ybq_status)['iccid']
  515. # if len(iccid) == 20:
  516. # print(iccid)
  517. # sta1 = RecentCBDdata.objects.all().values()
  518. # for x in sta1:
  519. # print("lng",eval(x['cbd_data'])['lng'])
  520. # print("lat",eval(x['cbd_data'])['lat'])
  521. # try:
  522. # sta2.append({
  523. # "equip_id": x['equip_id_id'],
  524. # "equip_type": 3,
  525. # "equip_name": x['equip_name'],
  526. # "gps": eval(x['cbd_data'])['gps'],
  527. # "lng": eval(x['cbd_data'])['lng'],
  528. # "lat": eval(x['cbd_data'])['lat']
  529. # })
  530. # except:
  531. # sta2.append({
  532. # "equip_id": x['equip_id_id'],
  533. # "equip_type": 3,
  534. # "equip_name": x['equip_name'],
  535. # "gps": 2,
  536. # "lng": eval(x['cbd_data'])['lng'],
  537. # "lat": eval(x['cbd_data'])['lat']
  538. # })
  539. # dver = "5.9.9-03(1)HK"
  540. # _list = "5.9.9-03HK"
  541. # a = re.sub('\\(.*?\\)','',_list)
  542. # print(a)
  543. #7.3号 分配账号脚本
  544. # equip_list = Equip.objects.filter(equip_id=i)
  545. # if equip_list:
  546. # for x in equip_list:
  547. # if x.equip_user:
  548. # datt.append(x.equip_id)
  549. # else:
  550. # x.equip_user = username
  551. # x.save()
  552. # else:
  553. # dat.append(i)
  554. # print("设备已绑定用户=====",datt)
  555. # print("未找到设备号=====",dat)
  556. # start_time = '2020-01-01'
  557. # end_time = '2020-05-30'
  558. # start_time = datetime.datetime.strptime(start_time,'%Y-%m-%d')
  559. # end_time = datetime.datetime.strptime(end_time,'%Y-%m-%d')
  560. # print(start_time)
  561. # _list = []
  562. # equip_list = Equip.objects.filter(equip_type=3,equip_add_time__range=(start_time,end_time))
  563. # for i in equip_list:
  564. # if CBDphoto.objects.filter(equip_id=i,upl_time__range=(start_time,end_time)).exists():
  565. # print("有照片")
  566. # _list.append(i.equip_id)
  567. # print("====>>",i.equip_id)
  568. # print(_list)
  569. # start_time = '2020-04-20'
  570. # end_time = '2020-05-30'
  571. # start_time = datetime.datetime.strptime(start_time,'%Y-%m-%d')
  572. # end_time = datetime.datetime.strptime(end_time,'%Y-%m-%d')
  573. # Equip.objects.get(equip_id=866714042686849).delete()
  574. # print("操作成功")
  575. # 物联网自动虫情信息采集设备(4.0)  对应的版本是5版本带HK的,如5.9.9HK
  576. # 物联网自动虫情信息采集设备(3.0)  对应的版本是4版本带re,hk的,如4.2.37re,4.1HK
  577. # 物联网自动虫情信息采集设备(2.0)  对应版本是1,2,3版本,如1.0.0;2.2.14;3.2.0
  578. # 自动虫情测报灯(1.0)             对应有4版本,5版本带ZP
  579. # 高空测报灯(1.0)                 对应4版本带GK,5版本的高空和转盘使用同一版本号,无法区分.
  580. # 糖醋测报                          对应1版本带TC,
  581. # 简易高空                          对应5版本带gk(区分大小写)
  582. # 定制版本                          其他版本
  583. # _list = CBDstatus.objects.all()
  584. # for i in _list:
  585. # print("equip_id",i.equip_id)
  586. # try:
  587. # cbddataobj = RecentCBDdata.objects.get(equip_id=i.equip_id)
  588. # except:
  589. # continue
  590. # # print(eval(i.cbd_status)['dver'])
  591. # dver = eval(i.cbd_status)['dver']
  592. # if dver.startswith("5") and dver.endswith("HK"):
  593. # i.etype = "4.0测报灯"
  594. # i.save()
  595. # cbddataobj.etype = "4.0测报灯"
  596. # cbddataobj.save()
  597. # print("4.0测报灯",dver)
  598. # elif dver.startswith("4") and dver.endswith("HK"):
  599. # i.etype = "3.0测报灯"
  600. # i.save()
  601. # cbddataobj.etype = "3.0测报灯"
  602. # cbddataobj.save()
  603. # print("3.0测报灯",dver)
  604. # elif dver.startswith("4") and dver.endswith("re"):
  605. # i.etype = "3.0测报灯"
  606. # i.save()
  607. # cbddataobj.etype = "3.0测报灯"
  608. # cbddataobj.save()
  609. # print("3.0测报灯",dver)
  610. # elif dver.startswith("1") or dver.startswith("2") or dver.startswith("3"):
  611. # i.etype = "2.0测报灯"
  612. # i.save()
  613. # cbddataobj.etype = "2.0测报灯"
  614. # cbddataobj.save()
  615. # print("2.0测报灯",dver)
  616. # elif dver.endswith("ZP"):
  617. # i.etype = "1.0测报灯"
  618. # i.save()
  619. # cbddataobj.etype = "1.0测报灯"
  620. # cbddataobj.save()
  621. # print("1.0测报灯",dver)
  622. # elif dver.startswith("4") and dver.endswith("GK"):
  623. # i.etype = "高空测报灯"
  624. # i.save()
  625. # cbddataobj.etype = "高空测报灯"
  626. # cbddataobj.save()
  627. # print("高空测报灯",dver)
  628. # elif dver.endswith("TC"):
  629. # i.etype = "糖醋测报灯"
  630. # i.save()
  631. # cbddataobj.etype = "糖醋测报灯"
  632. # cbddataobj.save()
  633. # print("糖醋测报灯",dver)
  634. # elif dver.startswith("5") and dver.endswith("gk"):
  635. # i.etype = "简易高空测报灯"
  636. # i.save()
  637. # cbddataobj.etype = "简易高空测报灯"
  638. # cbddataobj.save()
  639. # print("简易高空测报灯",dver)
  640. # def on_connect(client, userdata, flags, rc):
  641. # print("Connected with result code "+str(rc))
  642. # client.subscribe("api/v1/iot/dragon/868956044807455") # 订阅消息
  643. # def on_message(client, userdata, msg):
  644. # print("主题:"+msg.topic+" 消息:"+str(msg.payload.decode('utf-8')))
  645. # def on_subscribe(client, userdata, mid, granted_qos):
  646. # print("On Subscribed: qos = %d" % granted_qos)
  647. # def on_disconnect(client, userdata, rc):
  648. # if rc != 0:
  649. # print("Unexpected disconnection %s" % rc)
  650. # for i in YBQphoto.objects.all():
  651. # i.real_time = i.upl_time
  652. # i.save()
  653. # print("---处理完毕")
  654. # # HOST = "aftrnmynhcbc5elv-master-nlb-FI.jvessel-open-hb.jdcloud.com"
  655. # # HOST = "120.27.222.26"
  656. # HOST = "39.104.94.153"
  657. # PORT = 1883
  658. # # client_id = "1083421xxxxx" # 没有就不写,此处部分内容用xxx代替原内容,下同
  659. # client_id = time.strftime('%Y%m%d%H%M%S', time.localtime(time.time()))
  660. # imei = "868956044830994"
  661. # data = {
  662. # "devId": imei,
  663. # "ossPath": "http://120.27.222.26/" + "pyftp/ftp_file/ykm_cbd/868956044830994/192.168.1.100_01_20200601022407693_ALARM_INPUT.jpg",
  664. # "collectDT": time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time())),
  665. # "manuCode": "10014",
  666. # "result": "",
  667. # "resultImage": ""
  668. # }
  669. # TASK_TOPIC = "api/v1/iot/dragon/" + imei + "/telemetry" # 客户端发布消息主题
  670. # """
  671. # 客户端发布消息
  672. # :param message: 消息主体
  673. # :return:
  674. # """
  675. # payload = data
  676. # # publish(主题:Topic; 消息内容)
  677. # client_id = time.strftime('%Y%m%d%H%M%S', time.localtime(time.time()))
  678. # client = mqtt.Client(client_id, transport='tcp')
  679. # client.username_pw_set(imei, imei)
  680. # client.connect("aftrnmynhcbc5elv-master-nlb-FI.jvessel-open-hb.jdcloud.com", 1883, 60) # 此处端口默认为1883,通信端口期keepalive默认60
  681. # # client.connect("120.27.222.26", 1883, 60) # 此处端口默认为1883,通信端口期keepalive默认60
  682. # bb = client.loop_start()
  683. # aa = client.publish(TASK_TOPIC, json.dumps(payload, ensure_ascii=False),qos=0)
  684. # print("aa",aa)
  685. # print("bb",bb)
  686. # print("京东信息发送成功",data)
  687. # print(datetime.datetime.now())
  688. # data = {
  689. # "devId": "868956044807455",
  690. # "ossPath": "http:\/\/120.27.222.26\/pyftp\/ftp_file\/ykm_cbd\/868956044807455\/192.168.1.100_01_20200612104405264_ALARM_INPUT.jpg",
  691. # "collectDT": "2020-06-12 10:43:05",
  692. # "manuCode": "10014",
  693. # "result": "",
  694. # "resultImage": ""
  695. # }
  696. # param = json.dumps(data)
  697. # client = mqtt.Client(client_id)
  698. # client.username_pw_set("868956044807455", "")
  699. # client.on_connect = on_connect
  700. # client.on_message = on_message
  701. # client.on_subscribe = on_subscribe
  702. # client.on_disconnect = on_disconnect
  703. # aa = client.connect(HOST, PORT, 60)
  704. # print("---------->>",aa)
  705. # client.publish("api/v1/iot/dragon/868956044807455", payload=param, qos=0) # 发送消息
  706. # client.loop_start()
  707. # print("执行完毕")
  708. # data = {
  709. # "devId": "868956044807455",
  710. # "ossPath": "http:\/\/120.27.222.26\/pyftp\/ftp_file\/ykm_cbd\/868956044807455\/192.168.1.100_01_20200612104405263_ALARM_INPUT.jpg",
  711. # "collectDT": "2020-06-12 10:43:05",
  712. # "manuCode": "10014",
  713. # "result": "",
  714. # "resultImage": ""
  715. # }
  716. # TASK_TOPIC = 'api/v1/iot/dragon/868956044807455' # 客户端发布消息主题
  717. # """
  718. # 客户端发布消息
  719. # :param message: 消息主体
  720. # :return:
  721. # """
  722. # payload = data
  723. # # publish(主题:Topic; 消息内容)
  724. # client_id = time.strftime('%Y%m%d%H%M%S', time.localtime(time.time()))
  725. # client = mqtt.Client(client_id, transport='tcp')
  726. # client.username_pw_set("868956044807455", "868956044807455")
  727. # # client.connect("aftrnmynhcbc5elv-master-nlb-FI.jvessel-open-hb.jdcloud.com", 1883, 60) # 此处端口默认为1883,通信端口期keepalive默认60
  728. # client.connect("120.27.222.26", 1883, 60) # 此处端口默认为1883,通信端口期keepalive默认60
  729. # aa = client.publish(TASK_TOPIC, json.dumps(payload, ensure_ascii=False, qos=0))
  730. # bb = client.loop_start()
  731. # print(bb)
  732. # print(aa)
  733. # print("京东信息发送成功",data)
  734. # print(datetime.datetime.now())
  735. # data = []
  736. # data1 = []
  737. # simlist = Equip_SimInfo.objects.filter(data_plan="10",account_status="3")
  738. # for i in simlist:
  739. # print("------->>",i.iccid)
  740. # data1.append({"equip_id":i.equip_id_id,"equip_type":i.equip_type,"iccid":i.iccid,"data_usage":i.data_usage,"data_balance":i.data_balance})
  741. # title = ["设备id","设备类型","iccid","已用","剩余"]
  742. # book = xlwt.Workbook() # 创建一个excel对象
  743. # sheet = book.add_sheet('Sheet1',cell_overwrite_ok=True) # 添加一个sheet页
  744. # for i in range(len(title)): # 遍历列
  745. # # sheet.write(0,i,title[i],style) # 将title数组中的字段写入到0行i列中
  746. # sheet.write(0,i,title[i]) # 将title数组中的字段写入到0行i列中
  747. # # print(sta2)
  748. # for xx in range(len(data1)): # 遍历列表
  749. # if data1[xx]['equip_type'] == "3":
  750. # _type = "测报灯"
  751. # # off_time = datetime.datetime.strftime(data1[xx]['off_time'],'%Y-%m-%d')
  752. # else:
  753. # _type = "杀虫灯"
  754. # # off_time = ""
  755. # # creat_time = datetime.datetime.strftime(data1[xx]['creat_time'],'%Y-%m-%d')
  756. # sheet.write(xx+1,0,data1[xx]['equip_id']) # 将equip_id写入到第x+1行,第0列中
  757. # sheet.write(xx+1,1,_type)
  758. # sheet.write(xx+1,2,data1[xx]['iccid'])
  759. # sheet.write(xx+1,3,data1[xx]['data_usage'])
  760. # sheet.write(xx+1,4,data1[xx]['data_balance'])
  761. # book.save("654321.xlsx")
  762. # one_month = datetime.timedelta(days=30)
  763. # nowtime = datetime.datetime.now()
  764. # end_time = nowtime
  765. # start_time = nowtime - one_month
  766. # print(start_time)
  767. # aabbcc = Alarm_record.objects.all().exclude(alarm_time__range=(start_time,end_time)).delete()
  768. # for i in aabbcc:
  769. # i.delete()
  770. # print(i.alarm_time)
  771. # print(CBDstatus.objects.get(equip_id_id="865650044552954").rtuinfo)
  772. # def mkdir(path):
  773. # # 去除首位空格
  774. # path=path.strip()
  775. # # 去除尾部 \ 符号
  776. # path=path.rstrip("\\")
  777. # # 判断路径是否存在
  778. # # 存在 True
  779. # # 不存在 False
  780. # isExists=os.path.exists(path)
  781. # # 判断结果
  782. # if not isExists:
  783. # # 如果不存在则创建目录
  784. # # 创建目录操作函数
  785. # os.makedirs(path)
  786. # print(path+' 创建成功')
  787. # return True
  788. # else:
  789. # # 如果目录存在则不创建,并提示目录已存在
  790. # print(path+' 目录已存在')
  791. # return False
  792. # def variance_of_laplacian(image):
  793. # # 拉普拉斯的方差
  794. # return cv2.Laplacian(image, cv2.CV_64F).var()
  795. # imei = "865650043208251"
  796. # print('=================================================')
  797. # print("<-----imei:\n" + imei + ';\n')
  798. # print("Message:\n" + "http:bzyphoto" + "----->\n")
  799. # print("%s"%datetime.datetime.now())
  800. # print('=================================================')
  801. # pic_name = datetime.datetime.now().strftime('%Y%m')
  802. # try:
  803. # pic_name = datetime.datetime.now().strftime('%Y%m')
  804. # args = "pyftp/ftp_file/bzy_test/" + imei
  805. # cv_num_list = []
  806. # file_list1 = list(paths.list_images(args))
  807. # print("\n===========================")
  808. # print("file_list1:",file_list1)
  809. # print("type file_list1:",type(file_list1))
  810. # cv_num_list1 = []
  811. # for imagePath1 in file_list1[::]:
  812. # # fm = get_value(imagePath)
  813. # # 孢子仪图片过小删除
  814. # if os.path.getsize(imagePath1) <= 10:
  815. # file_list1.remove(imagePath1)
  816. # img1 = cv2.imread(imagePath1)
  817. # img1 = cv2.resize(img1, (800, 600))
  818. # gray = cv2.cvtColor(img1, cv2.COLOR_BGR2GRAY)
  819. # # 创建SIFT对象
  820. # sift = cv2.xfeatures2d.SIFT_create()
  821. # keypoints, descriptor = sift.detectAndCompute(gray, None)
  822. # img1 = cv2.drawKeypoints(image=img1, outImage=img1, keypoints=keypoints,flags=cv2.DRAW_MATCHES_FLAGS_DEFAULT, color=(0, 0, 255))
  823. # fm1 = len(keypoints)
  824. # cv_num_list1.append(fm1)
  825. # # 打印清晰度值:
  826. # print("fm1",fm1)
  827. # # 打印文件路径
  828. # print("imagePath1",imagePath1)
  829. # file_cv_tuple1 = tuple(zip(cv_num_list1,file_list1))
  830. # print("file_cv_tuple1:\n",file_cv_tuple1)
  831. # print("=========================================/n")
  832. # file_cv_tuple_list1 = list(file_cv_tuple1)
  833. # print("file_cv_tuple_list1:\n",file_cv_tuple_list1)
  834. # print("*****************************************/n")
  835. # # 按照清晰度排序:, reverse=True降序
  836. # result1 = sorted(file_cv_tuple_list1, key=lambda s: s[0],reverse=True)
  837. # print("result1:\n",result1)
  838. # # 切片取清晰度最高的前五张图片:
  839. # result1_5 = result1[0:3]
  840. # # result5 = result[0:1]
  841. # print("result1_5:\n",result1_5)
  842. # pic_name = datetime.datetime.now().strftime('%Y%m')
  843. # # 定义要创建的目录:
  844. # mkpath="./pyftp/ftp_file/bzy_photo/" + imei + "/" + pic_name
  845. # # 调用函数,创建目录:
  846. # mkdir(mkpath)
  847. # for i in result1_5:
  848. # # for i in result5:
  849. # #i值:(137.06453470539032, 'images\\192.168.2.64_01_20190802095315882_ALARM_INPUT.jpg')
  850. # print("file path:",i[1])
  851. # #复制文件:
  852. # shutil.copy(i[1],mkpath)
  853. # # os.system("rm ./pyftp/ftp_file/bzy_test/%s/*.jpg -rf"%imei)
  854. # os.system("mv ./pyftp/ftp_file/bzy_test/%s ./pyftp/ftp_file/bzy_test/%s_%s"%(imei,imei,datetime.datetime.now().strftime("%Y%m%d%H%M%S")))
  855. # print("-----------------image move success----------------------")
  856. # equip = Equip.objects.get(equip_id=imei)
  857. # file_dir="pyftp/ftp_file/bzy_photo/" + imei + "/" + pic_name
  858. # for root, dirs, files in os.walk(file_dir):
  859. # print("当前目录为=========>>",root) #当前目录路径
  860. # print("当前子目录为=========>>",dirs) #当前路径下所有子目录
  861. # print("当前目录文件为=========>>",files) #当前路径下所有非目录子文件
  862. # for i in files:
  863. # photo_addr = file_dir + "/" + i
  864. # print("文件夹图片路径===========》》",photo_addr)
  865. # if BZYphoto.objects.filter(addr=photo_addr).exists():
  866. # print("照片存在")
  867. # else:
  868. # BZYphoto.objects.create(equip_id=equip, addr=photo_addr)
  869. # print("照片不存在")
  870. # except Exception as a:
  871. # print('=================================================')
  872. # print("<-----imei:\n" + imei + ';\n')
  873. # print("Message:\n" + "http:bzyphoto" + "----->\n")
  874. # print("%s"%datetime.datetime.now())
  875. # print("==========%s========"%a)
  876. # print("-----------------image move default----------------------")
  877. # lat = "37.56"
  878. # lng = "115.28"
  879. # data = []
  880. # data1 = []
  881. # # res = requests.post("http://api.map.baidu.com/geocoder?location=%s,%s&coord_type=gcj02&output=json"%(lat,lng))
  882. # # location = (eval(res.text))["result"]["addressComponent"]["province"]+eval(res.text)["result"]["addressComponent"]["district"]
  883. # # print(location)
  884. # # 大新县农业农村局
  885. # # user_obj = MyUser.objects.get(username="大新县农业农村局")
  886. # for i in CBDstatus.objects.all().values():
  887. # try:
  888. # lng = i["lng"]
  889. # lat = i["lat"]
  890. # except:
  891. # lng = ""
  892. # lat = ""
  893. # print("设备版本号",eval(i["cbd_status"])["dver"].split(".")[0])
  894. # print("照片是否存在",CBDphoto.objects.filter(equip_id=i["equip_id_id"]).exists())
  895. # if eval(i["cbd_status"])["dver"].split(".")[0] == "5" and CBDphoto.objects.filter(equip_id=i["equip_id_id"]).exists():
  896. # data.append({"equip_id":i["equip_id_id"],"lng":lng,"lat":lat,"is_online":i["is_online"],"off_time":i["off_time"],"creat_time":Equip.objects.get(equip_id=i["equip_id_id"]).equip_add_time})
  897. # # print(data)
  898. # for x in data:
  899. # if x["lat"]:
  900. # res = requests.post("http://api.map.baidu.com/geocoder?location=%s,%s&coord_type=gcj02&output=json"%(x["lat"],x["lng"]))
  901. # try:
  902. # print(eval(res.text))
  903. # print((eval(res.text))["result"]["addressComponent"]["province"])
  904. # # print((eval(res.text))["result"]["formatted_address"])
  905. # except:
  906. # continue
  907. # # if (eval(res.text))["result"]["addressComponent"]["province"] == "河南省":
  908. # location = (eval(res.text))["result"]["addressComponent"]["province"] + (eval(res.text))["result"]["addressComponent"]["city"] + (eval(res.text))["result"]["addressComponent"]["district"]
  909. # # location = (eval(res.text))["result"]["formatted_address"]
  910. # data1.append({"equip_id":x["equip_id"],"location":location,"is_online":x["is_online"],"off_time":x["off_time"],"creat_time":x["creat_time"]})
  911. # # print(data1)
  912. # title = ["设备id","设备位置","是否在线","离线时间","设备创建时间"]
  913. # book = xlwt.Workbook() # 创建一个excel对象
  914. # sheet = book.add_sheet('Sheet1',cell_overwrite_ok=True) # 添加一个sheet页
  915. # for i in range(len(title)): # 遍历列
  916. # # sheet.write(0,i,title[i],style) # 将title数组中的字段写入到0行i列中
  917. # sheet.write(0,i,title[i]) # 将title数组中的字段写入到0行i列中
  918. # # print(sta2)
  919. # for xx in range(len(data1)): # 遍历列表
  920. # if data1[xx]['is_online'] == "0":
  921. # is_online = "离线"
  922. # off_time = datetime.datetime.strftime(data1[xx]['off_time'],'%Y-%m-%d')
  923. # else:
  924. # is_online = "在线"
  925. # off_time = ""
  926. # creat_time = datetime.datetime.strftime(data1[xx]['creat_time'],'%Y-%m-%d')
  927. # sheet.write(xx+1,0,data1[xx]['equip_id']) # 将equip_id写入到第x+1行,第0列中
  928. # sheet.write(xx+1,1,data1[xx]['location'])
  929. # sheet.write(xx+1,2,is_online)
  930. # sheet.write(xx+1,3,off_time)
  931. # sheet.write(xx+1,4,creat_time)
  932. # book.save("654321.xlsx")
  933. # sta = [{'equip_id': '865650043164355', 'location': '河北省易县'}, {'equip_id': '865650042837811', 'location': '河北省桥西区'}, {'equip_id': '860344048820691', 'location': '河北省武强县'}, {'equip_id': '865650041090206', 'location': '河北省武强县'}, {'equip_id': '865650041021268', 'location': '河北省武强县'}, {'equip_id': '868575028847277', 'location': '河北省赤城县'}, {'equip_id': '865650041020971', 'location': '河北省深州市'}, {'equip_id': '865650041089497', 'location': '河北省迁安市'}, {'equip_id': '868575028850214', 'location': '河北省涉县'}, {'equip_id': '860344048805221', 'location': '河北省易县'}, {'equip_id': '868575028846592', 'location': '河北省围场满族蒙古族自治县'}, {'equip_id': '868575028857953', 'location': '河北省曲周县'}, {'equip_id': '868575028850917', 'location': '河北省围场满族蒙古族自治县'}, {'equip_id': '868575028847798', 'location': '河北省曹妃甸区'}, {'equip_id': '869300039255967', 'location': '河北省晋州市'}, {'equip_id': '868575028855387', 'location': '河北省曹妃甸区'}, {'equip_id': '868575028869040', 'location': '河北省平泉县'}, {'equip_id': '868575028850925', 'location': '河北省隆尧县'}, {'equip_id': '868575028868927', 'location': '河北省隆尧县'}, {'equip_id': '868575028855148', 'location': '河北省玉田县'}, {'equip_id': '868575028845875', 'location': '河北省辛集市'}, {'equip_id': '868575028850479', 'location': '河北省赵县'}, {'equip_id': '868575028846048', 'location': '河北省围场满族蒙古族自治县'}, {'equip_id': '868575028847640', 'location': '河北省曲周县'}, {'equip_id': '868575028846089', 'location': '河北省香河县'}, {'equip_id': '868575028858035', 'location': '河北省围场满族蒙古族自治县'}, {'equip_id': '868575028857656', 'location': '河北省阜城县'}, {'equip_id': '868575028810101', 'location': '河北省永清县'}, {'equip_id': '868575028868463', 'location': '河北省赤城县'}, {'equip_id': '869300039256064', 'location': '河北省玉田县'}, {'equip_id': '869300039255900', 'location': '河北省迁西县'}, {'equip_id': '868575028857318', 'location': '河北省辛集市'}, {'equip_id': '868575028850727', 'location': '河北省承德县'}]
  934. # print(len(sta))
  935. # imei = "D75675201"
  936. # file_dir = "../pyftp/ftp_file/jk_photo1/%s"%imei
  937. # print("file_dir",file_dir)
  938. # for root, dirs, files in os.walk(file_dir):
  939. # for i in files:
  940. # file = root + "/" + i
  941. # # st = root.split("/")[-1] + i.split(".")[0]
  942. # file = file[3:]
  943. # st = i.split(".")[3].split("_")[2][0:14]
  944. # print("st",st)
  945. # print("file====>>",file)
  946. # try:
  947. # pic_time = datetime.datetime.strptime(st,"%Y%m%d%H%M%S")
  948. # except Exception as eeex:
  949. # print("错误信息为",eeex)
  950. # continue
  951. # if JKphoto.objects.filter(addr=file).exists():
  952. # photoobj = JKphoto.objects.get(addr=file)
  953. # photoobj.upl_time = pic_time
  954. # photoobj.save()
  955. # print("照片存在")
  956. # else:
  957. # print("照片不存在")
  958. # try:
  959. # imei_obj = Equip.objects.get(equip_id=imei)
  960. # JKphoto.objects.create(equip_id=imei_obj,addr=file,upl_time=pic_time)
  961. # except Exception as e:
  962. # print("错误信息为",e)
  963. # equip_obj = Equip.objects.get(equip_id=160648091112227)
  964. # equip_obj2 = QXZstatus_New.objects.get(equip_id=16064809)
  965. # conf_obj = QXZ_Conf.objects.get(equip_id=16064809)
  966. # conf_obj2 = QXZ_Default_Conf.objects.get(equip_id=16064809)
  967. # aa = QXZstatus_New.objects.create(equip_id=equip_obj,e1=equip_obj2.e1,e2=equip_obj2.e2,e3=equip_obj2.e3,e4=equip_obj2.e4,e5=equip_obj2.e5,e6=equip_obj2.e6,e7=equip_obj2.e7,e8=equip_obj2.e8,e9=equip_obj2.e9,e10=equip_obj2.e10,e11=equip_obj2.e11,e12=equip_obj2.e12,e13=equip_obj2.e13,e14=equip_obj2.e14,e15=equip_obj2.e15,e16=equip_obj2.e16)
  968. # bb = QXZdata_New.objects.create(equip_id=equip_obj,e1=equip_obj2.e1,e2=equip_obj2.e2,e3=equip_obj2.e3,e4=equip_obj2.e4,e5=equip_obj2.e5,e6=equip_obj2.e6,e7=equip_obj2.e7,e8=equip_obj2.e8,e9=equip_obj2.e9,e10=equip_obj2.e10,e11=equip_obj2.e11,e12=equip_obj2.e12,e13=equip_obj2.e13,e14=equip_obj2.e14,e15=equip_obj2.e15,e16=equip_obj2.e16)
  969. # cc = QXZ_Conf.objects.create(equip_id=equip_obj,e1=conf_obj.e1,e2=conf_obj.e2,e3=conf_obj.e3,e4=conf_obj.e4,e5=conf_obj.e5,e6=conf_obj.e6,e7=conf_obj.e7,e8=conf_obj.e8,e9=conf_obj.e9,e10=conf_obj.e10,e11=conf_obj.e11,e12=conf_obj.e12,e13=conf_obj.e13,e14=conf_obj.e14,e15=conf_obj.e15,e16=conf_obj.e16)
  970. # dd = QXZ_Default_Conf.objects.create(equip_id=equip_obj,e1=conf_obj2.e1,e2=conf_obj2.e2,e3=conf_obj2.e3,e4=conf_obj2.e4,e5=conf_obj2.e5,e6=conf_obj2.e6,e7=conf_obj2.e7,e8=conf_obj2.e8,e9=conf_obj2.e9,e10=conf_obj2.e10,e11=conf_obj2.e11,e12=conf_obj2.e12,e13=conf_obj2.e13,e14=conf_obj2.e14,e15=conf_obj2.e15,e16=conf_obj2.e16)
  971. # print("操作完毕")
  972. # print(QXZstatus_New.objects.get(equip_id_id=16064808).upl_time)
  973. # workbook = xlrd.open_workbook('物联网杀虫灯发货统计(2).xlsx')
  974. # print(workbook.sheet_names())
  975. # sheet11 = workbook.sheet_by_name('11 月发货统计')
  976. # nro = sheet11.nrows
  977. # print(nro)
  978. # list_e = []
  979. # user_obj = MyUser.objects.get(username="大新县农业农村局")
  980. # cell_a = sheet11.cell(0,2).value # 括号内第一位数字为行,第二位为列
  981. # for i in range(146):
  982. # cell_a = sheet11.cell(i,2).value
  983. # # print(cell_a)
  984. # try:
  985. # equip_obj = Equip.objects.get(equip_id=cell_a)
  986. # equip_obj.equip_user = user_obj
  987. # equip_obj.save()
  988. # print("分配成功")
  989. # except:
  990. # print("设备不存在")
  991. # print(cell_a)
  992. # list_e.append(cell_a)
  993. # print(list_e)
  994. # list_e = []
  995. # for i in CBDstatus.objects.all():
  996. # is_hk = eval(i.cbd_status)["dver"]
  997. # # print(is_hk)
  998. # if "HK" in is_hk:
  999. # print(is_hk)
  1000. # list_e.append(i)
  1001. # # else:
  1002. # # print("不是hk")
  1003. # # print(list_e)
  1004. # list_n = []
  1005. # for x in list_e:
  1006. # # print(x.simid)
  1007. # if x.simid:
  1008. # print("===>>",x.equip_id_id)
  1009. # equip_obj2 = RecentCBDdata.objects.get(equip_id_id=x.equip_id_id)
  1010. # equip_obj = CBDstatus.objects.filter(equip_id_id=x.equip_id_id).update(upl_time=equip_obj2.upl_time)
  1011. # print("操作成功")
  1012. # else:
  1013. # # print("为空的设备",x.equip_id_id)
  1014. # # list_n.append(x.equip_id_id)
  1015. # # x.simid = '12345678901234567890'
  1016. # # x.save()
  1017. # equip_obj2 = RecentCBDdata.objects.get(equip_id_id=x.equip_id_id)
  1018. # equip_obj = CBDstatus.objects.filter(equip_id_id=x.equip_id_id).update(upl_time=equip_obj2.upl_time)
  1019. # print("操作成功")
  1020. # print(list_n)
  1021. # equip_obj2 = RecentCBDdata.objects.get(equip_id_id=i)
  1022. # equip_obj = CBDstatus.objects.filter(equip_id_id=i).update(upl_time=equip_obj2.upl_time)
  1023. # e1 = ''
  1024. # e2 = ''
  1025. # e3 = ''
  1026. # e4 = ''
  1027. # e5 = ''
  1028. # e6 = ''
  1029. # e7 = ''
  1030. # e8 = ''
  1031. # e9 = ''
  1032. # e10 = ''
  1033. # e11 = ''
  1034. # e12 = ''
  1035. # e13 = ''
  1036. # e14 = ''
  1037. # e15 = ''
  1038. # e16 = ''
  1039. # e17 = ''
  1040. # e18 = ''
  1041. # e19 = ''
  1042. # e20 = ''
  1043. # e21 = ''
  1044. # e22 = ''
  1045. # e23 = ''
  1046. # e24 = ''
  1047. # e25 = ''
  1048. # e26 = ''
  1049. # e27 = ''
  1050. # e28 = ''
  1051. # e29 = ''
  1052. # e30 = ''
  1053. # conf1 = ''
  1054. # conf2 = ''
  1055. # conf3 = ''
  1056. # conf4 = ''
  1057. # conf5 = ''
  1058. # conf6 = ''
  1059. # conf7 = ''
  1060. # conf8 = ''
  1061. # conf9 = ''
  1062. # conf10 = ''
  1063. # conf11 = ''
  1064. # conf12 = ''
  1065. # conf13 = ''
  1066. # conf14 = ''
  1067. # conf15 = ''
  1068. # conf16 = ''
  1069. # conf17 = ''
  1070. # conf18 = ''
  1071. # conf19 = ''
  1072. # conf20 = ''
  1073. # conf21 = ''
  1074. # conf22 = ''
  1075. # conf23 = ''
  1076. # conf24 = ''
  1077. # conf25 = ''
  1078. # conf26 = ''
  1079. # conf27 = ''
  1080. # conf28 = ''
  1081. # conf29 = ''
  1082. # conf30 = ''
  1083. # for x in QXZstatus.objects.all():
  1084. # e_id = x.equip_id_id
  1085. # upl_time = QXZstatus.objects.get(equip_id=e_id).upl_time
  1086. # qxz_picture = QXZstatus.objects.get(equip_id=e_id).qxz_picture
  1087. # qxzstatus = eval(QXZstatus.objects.get(equip_id=e_id).qxz_status)['data']
  1088. # for i in qxzstatus:
  1089. # if i['eKey'] == 'e1':
  1090. # e1 = i['eValue'] + '#' + i['eNum'] + '#' + i['eKey']
  1091. # conf1 = qxz_dict[i['eNum']][1] + '#' + qxz_dict[i['eNum']][2]
  1092. # elif i['eKey'] == 'e2':
  1093. # e2 = i['eValue'] + '#' + i['eNum'] + '#' + i['eKey']
  1094. # conf2 = qxz_dict[i['eNum']][1] + '#' + qxz_dict[i['eNum']][2]
  1095. # elif i['eKey'] == 'e3':
  1096. # e3 = i['eValue'] + '#' + i['eNum'] + '#' + i['eKey']
  1097. # conf3 = qxz_dict[i['eNum']][1] + '#' + qxz_dict[i['eNum']][2]
  1098. # elif i['eKey'] == 'e4':
  1099. # e4 = i['eValue'] + '#' + i['eNum'] + '#' + i['eKey']
  1100. # conf4 = qxz_dict[i['eNum']][1] + '#' + qxz_dict[i['eNum']][2]
  1101. # elif i['eKey'] == 'e5':
  1102. # e5 = i['eValue'] + '#' + i['eNum'] + '#' + i['eKey']
  1103. # conf5 = qxz_dict[i['eNum']][1] + '#' + qxz_dict[i['eNum']][2]
  1104. # elif i['eKey'] == 'e6':
  1105. # e6 = i['eValue'] + '#' + i['eNum'] + '#' + i['eKey']
  1106. # conf6 = qxz_dict[i['eNum']][1] + '#' + qxz_dict[i['eNum']][2]
  1107. # elif i['eKey'] == 'e7':
  1108. # e7 = i['eValue'] + '#' + i['eNum'] + '#' + i['eKey']
  1109. # conf7 = qxz_dict[i['eNum']][1] + '#' + qxz_dict[i['eNum']][2]
  1110. # elif i['eKey'] == 'e8':
  1111. # e8 = i['eValue'] + '#' + i['eNum'] + '#' + i['eKey']
  1112. # conf8 = qxz_dict[i['eNum']][1] + '#' + qxz_dict[i['eNum']][2]
  1113. # elif i['eKey'] == 'e9':
  1114. # e9 = i['eValue'] + '#' + i['eNum'] + '#' + i['eKey']
  1115. # conf9 = qxz_dict[i['eNum']][1] + '#' + qxz_dict[i['eNum']][2]
  1116. # elif i['eKey'] == 'e10':
  1117. # e10 = i['eValue'] + '#' + i['eNum'] + '#' + i['eKey']
  1118. # conf10 = qxz_dict[i['eNum']][1] + '#' + qxz_dict[i['eNum']][2]
  1119. # elif i['eKey'] == 'e11':
  1120. # e11 = i['eValue'] + '#' + i['eNum'] + '#' + i['eKey']
  1121. # conf11 = qxz_dict[i['eNum']][1] + '#' + qxz_dict[i['eNum']][2]
  1122. # elif i['eKey'] == 'e12':
  1123. # e12 = i['eValue'] + '#' + i['eNum'] + '#' + i['eKey']
  1124. # conf12 = qxz_dict[i['eNum']][1] + '#' + qxz_dict[i['eNum']][2]
  1125. # elif i['eKey'] == 'e13':
  1126. # e13 = i['eValue'] + '#' + i['eNum'] + '#' + i['eKey']
  1127. # conf13 = qxz_dict[i['eNum']][1] + '#' + qxz_dict[i['eNum']][2]
  1128. # elif i['eKey'] == 'e14':
  1129. # e14 = i['eValue'] + '#' + i['eNum'] + '#' + i['eKey']
  1130. # conf14 = qxz_dict[i['eNum']][1] + '#' + qxz_dict[i['eNum']][2]
  1131. # elif i['eKey'] == 'e15':
  1132. # e15 = i['eValue'] + '#' + i['eNum'] + '#' + i['eKey']
  1133. # conf15 = qxz_dict[i['eNum']][1] + '#' + qxz_dict[i['eNum']][2]
  1134. # elif i['eKey'] == 'e16':
  1135. # e16 = i['eValue'] + '#' + i['eNum'] + '#' + i['eKey']
  1136. # conf16 = qxz_dict[i['eNum']][1] + '#' + qxz_dict[i['eNum']][2]
  1137. # elif i['eKey'] == 'e17':
  1138. # e17 = i['eValue'] + '#' + i['eNum'] + '#' + i['eKey']
  1139. # conf17 = qxz_dict[i['eNum']][1] + '#' + qxz_dict[i['eNum']][2]
  1140. # elif i['eKey'] == 'e18':
  1141. # e18 = i['eValue'] + '#' + i['eNum'] + '#' + i['eKey']
  1142. # conf18 = qxz_dict[i['eNum']][1] + '#' + qxz_dict[i['eNum']][2]
  1143. # elif i['eKey'] == 'e19':
  1144. # e19 = i['eValue'] + '#' + i['eNum'] + '#' + i['eKey']
  1145. # conf19 = qxz_dict[i['eNum']][1] + '#' + qxz_dict[i['eNum']][2]
  1146. # elif i['eKey'] == 'e20':
  1147. # e20 = i['eValue'] + '#' + i['eNum'] + '#' + i['eKey']
  1148. # conf20 = qxz_dict[i['eNum']][1] + '#' + qxz_dict[i['eNum']][2]
  1149. # elif i['eKey'] == 'e21':
  1150. # e21 = i['eValue'] + '#' + i['eNum'] + '#' + i['eKey']
  1151. # conf21 = qxz_dict[i['eNum']][1] + '#' + qxz_dict[i['eNum']][2]
  1152. # elif i['eKey'] == 'e22':
  1153. # e22 = i['eValue'] + '#' + i['eNum'] + '#' + i['eKey']
  1154. # conf22 = qxz_dict[i['eNum']][1] + '#' + qxz_dict[i['eNum']][2]
  1155. # elif i['eKey'] == 'e23':
  1156. # e23 = i['eValue'] + '#' + i['eNum'] + '#' + i['eKey']
  1157. # conf23 = qxz_dict[i['eNum']][1] + '#' + qxz_dict[i['eNum']][2]
  1158. # elif i['eKey'] == 'e24':
  1159. # e24 = i['eValue'] + '#' + i['eNum'] + '#' + i['eKey']
  1160. # conf24 = qxz_dict[i['eNum']][1] + '#' + qxz_dict[i['eNum']][2]
  1161. # elif i['eKey'] == 'e25':
  1162. # e25 = i['eValue'] + '#' + i['eNum'] + '#' + i['eKey']
  1163. # conf25 = qxz_dict[i['eNum']][1] + '#' + qxz_dict[i['eNum']][2]
  1164. # elif i['eKey'] == 'e26':
  1165. # e26 = i['eValue'] + '#' + i['eNum'] + '#' + i['eKey']
  1166. # conf26 = qxz_dict[i['eNum']][1] + '#' + qxz_dict[i['eNum']][2]
  1167. # elif i['eKey'] == 'e27':
  1168. # e27 = i['eValue'] + '#' + i['eNum'] + '#' + i['eKey']
  1169. # conf27 = qxz_dict[i['eNum']][1] + '#' + qxz_dict[i['eNum']][2]
  1170. # elif i['eKey'] == 'e28':
  1171. # e28 = i['eValue'] + '#' + i['eNum'] + '#' + i['eKey']
  1172. # conf28 = qxz_dict[i['eNum']][1] + '#' + qxz_dict[i['eNum']][2]
  1173. # elif i['eKey'] == 'e29':
  1174. # e29 = i['eValue'] + '#' + i['eNum'] + '#' + i['eKey']
  1175. # conf29 = qxz_dict[i['eNum']][1] + '#' + qxz_dict[i['eNum']][2]
  1176. # elif i['eKey'] == 'e30':
  1177. # e30 = i['eValue'] + '#' + i['eNum'] + '#' + i['eKey']
  1178. # conf30 = qxz_dict[i['eNum']][1] + '#' + qxz_dict[i['eNum']][2]
  1179. # if QXZstatus_New.objects.filter(equip_id=e_id).exists():
  1180. # print("------create default-------")
  1181. # else:
  1182. # QXZstatus_New.objects.create(equip_id_id=e_id,
  1183. # e1=e1,e2=e2,e3=e3,e4=e4,e5=e5,e6=e6,e7=e7,e8=e8,e9=e9,e10=e10,
  1184. # e11=e11,e12=e12,e13=e13,e14=e14,e15=e15,e16=e16,e17=e17,e18=e18,e19=e19,e20=e20,
  1185. # e21=e21,e22=e22,e23=e23,e24=e24,e25=e25,e26=e26,e27=e27,e28=e28,e29=e29,e30=e30,
  1186. # upl_time=upl_time,qxz_picture=qxz_picture)
  1187. # print("------create success-------")
  1188. # e1 = ''
  1189. # e2 = ''
  1190. # e3 = ''
  1191. # e4 = ''
  1192. # e5 = ''
  1193. # e6 = ''
  1194. # e7 = ''
  1195. # e8 = ''
  1196. # e9 = ''
  1197. # e10 = ''
  1198. # e11 = ''
  1199. # e12 = ''
  1200. # e13 = ''
  1201. # e14 = ''
  1202. # e15 = ''
  1203. # e16 = ''
  1204. # e17 = ''
  1205. # e18 = ''
  1206. # e19 = ''
  1207. # e20 = ''
  1208. # e21 = ''
  1209. # e22 = ''
  1210. # e23 = ''
  1211. # e24 = ''
  1212. # e25 = ''
  1213. # e26 = ''
  1214. # e27 = ''
  1215. # e28 = ''
  1216. # e29 = ''
  1217. # e30 = ''
  1218. # if QXZ_Conf.objects.filter(equip_id=e_id).exists():
  1219. # print("------conf create default-------")
  1220. # else:
  1221. # QXZ_Conf.objects.create(equip_id_id=e_id,
  1222. # e1=conf1,e2=conf2,e3=conf3,e4=conf4,e5=conf5,e6=conf6,e7=conf7,e8=conf8,e9=conf9,e10=conf10,
  1223. # e11=conf11,e12=conf12,e13=conf13,e14=conf14,e15=conf15,e16=conf16,e17=conf17,e18=conf18,e19=conf19,e20=conf20,
  1224. # e21=conf21,e22=conf22,e23=conf23,e24=conf24,e25=conf25,e26=conf26,e27=conf27,e28=conf28,e29=conf29,e30=conf30)
  1225. # QXZ_Default_Conf.objects.create(equip_id_id=e_id,
  1226. # e1=conf1,e2=conf2,e3=conf3,e4=conf4,e5=conf5,e6=conf6,e7=conf7,e8=conf8,e9=conf9,e10=conf10,
  1227. # e11=conf11,e12=conf12,e13=conf13,e14=conf14,e15=conf15,e16=conf16,e17=conf17,e18=conf18,e19=conf19,e20=conf20,
  1228. # e21=conf21,e22=conf22,e23=conf23,e24=conf24,e25=conf25,e26=conf26,e27=conf27,e28=conf28,e29=conf29,e30=conf30)
  1229. # print("------conf create success-------")
  1230. # conf1 = ''
  1231. # conf2 = ''
  1232. # conf3 = ''
  1233. # conf4 = ''
  1234. # conf5 = ''
  1235. # conf6 = ''
  1236. # conf7 = ''
  1237. # conf8 = ''
  1238. # conf9 = ''
  1239. # conf10 = ''
  1240. # conf11 = ''
  1241. # conf12 = ''
  1242. # conf13 = ''
  1243. # conf14 = ''
  1244. # conf15 = ''
  1245. # conf16 = ''
  1246. # conf17 = ''
  1247. # conf18 = ''
  1248. # conf19 = ''
  1249. # conf20 = ''
  1250. # conf21 = ''
  1251. # conf22 = ''
  1252. # conf23 = ''
  1253. # conf24 = ''
  1254. # conf25 = ''
  1255. # conf26 = ''
  1256. # conf27 = ''
  1257. # conf28 = ''
  1258. # conf29 = ''
  1259. # conf30 = ''
  1260. # -------------------------------------------------------MQTT TEST-------------------------------------
  1261. # import threading
  1262. # def cbdthread(e_id):
  1263. # i = 0
  1264. # TASK_TOPIC = '/yfkj/cbd/pub/%s'%e_id # 客户端发布消息主题
  1265. # client_id = time.strftime('%Y%m%d%H%M%S', time.localtime(time.time()))
  1266. # client = mqtt.Client(client_id, transport='tcp')
  1267. # client.connect("39.104.94.153", 1883, 60) # 此处端口默认为1883,通信端口期keepalive默认60
  1268. # client.loop_start()
  1269. # # print("子线程名称输出",threading.currentThread().name)
  1270. # """
  1271. # 客户端发布消息
  1272. # :param message: 消息主体
  1273. # :return:
  1274. # """
  1275. # payload = {"cmd": "status", "ext": {"lux": 0, "lng": "113.61237910001185", "ts": 1, "upds": 0, "lps": 0, "csq": 31, "dver": "5.2HK", "hs": 0, "ws": 0, "rps": 1, "tps": 0, "proj": "DCCBD-2_HK", "stamp": "20200107151511", "vs": 201, "dtype": 3, "imei": "%s"%e_id, "lamp": 0, "lat": "34.80817089999999", "dnds": 0, "gs": 0, "iccid": "898602B62518C0046484"}}
  1276. # # publish(主题:Topic; 消息内容)
  1277. # while True:
  1278. # client.publish(TASK_TOPIC, json.dumps(payload, ensure_ascii=False))
  1279. # print("Successful send message!",e_id)
  1280. # time.sleep(1)
  1281. # print("=============",i)
  1282. # i = i + 1
  1283. # e_id = 10000
  1284. # for i in range(10):
  1285. # t = threading.Thread(target=cbdthread,args=(e_id,))
  1286. # #打印出当前线程的名称和id
  1287. # # print(threading.currentThread().name)
  1288. # # t.setDaemon(True)
  1289. # t.start()
  1290. # e_id = e_id + 1
  1291. # if e_id == 10009:
  1292. # while True:
  1293. # print("主线程名称输出",threading.currentThread().name)
  1294. # thread_num = len(threading.enumerate())
  1295. # print("线程数量是%d" % thread_num)
  1296. # time.sleep(1)
  1297. # -------------------------------------------------------MQTT TEST-------------------------------------
  1298. # print(type(os.path.getsize('F:\\1111.jpg')))
  1299. # msg_conf_list = Msg_Conf.objects.all()
  1300. # for i in msg_conf_list:
  1301. # cbd_obj = Equip.objects.get(equip_id=i.equip_id)
  1302. # equip_name = ""
  1303. # if cbd_obj.equip_name == "" or cbd_obj.equip_name == None:
  1304. # equip_name = cbd_obj.equip_id
  1305. # else:
  1306. # equip_name = cbd_obj.equip_name
  1307. # msgconf = eval(i.conf)
  1308. # # 需要发送短信的手机号码
  1309. # phone_numbers = msgconf["phone"]
  1310. # # 短信模板ID,需要在短信控制台中申请
  1311. # template_id = 431378 # NOTE: 这里的模板 ID`7839`只是示例,真实的模板 ID 需要在短信控制台中申请
  1312. # # 签名
  1313. # sms_sign = "云飞科技" # NOTE: 签名参数使用的是`签名内容`,而不是`签名ID`。这里的签名"腾讯云"只是示例,真实的签名需要在短信控制台中申请
  1314. # ssender = SmsSingleSender(appid, appkey)
  1315. # params = ["","","由于入冬无虫子,暂时停止短信发送服务,将于明年三月份开启"] # 当模板没有参数时,`params = []`
  1316. # try:
  1317. # result = ssender.send_with_param(86, phone_numbers,
  1318. # template_id, params, sign=sms_sign, extend="", ext="") # 签名参数未提供或者为空时,会使用默认签名发送短信
  1319. # except HTTPError as e:
  1320. # print(e)
  1321. # except Exception as e:
  1322. # print(e)
  1323. # print(result)
  1324. # Msg_Send.objects.create(mobile=msgconf["phone"],equip_id=i.equip_id,send_dec=params,result_desc=result)
  1325. # pest_name = []
  1326. # print("----发送成功",phone_numbers)
  1327. # 账号有效期设置
  1328. # user_obj = MyUser.objects.all()
  1329. # for i in user_obj:
  1330. # if i.date_joined.year == 2019 and i.date_joined.month >= 10:
  1331. # print(i.date_joined)
  1332. # print(i.username)
  1333. # i.expire_date = i.date_joined + datetime.timedelta(days=730)
  1334. # i.save()
  1335. # print("操作成功")
  1336. # # 查看最近有虫子的测报灯
  1337. # one_month = datetime.timedelta(days=30)
  1338. # now_time = datetime.datetime.now()
  1339. # photo_list = CBDphoto.objects.all()
  1340. # for i in photo_list:
  1341. # if now_time - i.upl_time <= one_month and i.indentify_result:
  1342. # print(i.equip_id_id)
  1343. # book=xlrd.open_workbook('F:\\12.2河南云飞恢复续费.xlsx')
  1344. # sheet=book.sheet_by_index(0) #根据sheet编号来
  1345. # # sheet=book.sheet_by_name('sheet1') #根据 sheet名称来
  1346. # # print(sheet.nrows) #excel里面有多少行
  1347. # # print(sheet.ncols) #excel里面有多少列
  1348. # # print(sheet.cell(0,0).value) #获取第0行第0列的值
  1349. # # print(sheet.row_values(0)) #获取到整行的内容
  1350. # # print(sheet.col_values(1)) #获取到整列的内容
  1351. # iccid_list = sheet.col_values(1)
  1352. # for i in range(len(iccid_list)):
  1353. # if i == 0:
  1354. # continue
  1355. # print(iccid_list[i])
  1356. # # print(iccid_list[i])
  1357. # # for i in range(sheet.nrows): #循环获取每行的内容
  1358. # # print(sheet.row_values(i))
  1359. # equip_list = Equip.objects.all()
  1360. # for i in equip_list:
  1361. # print(type(i.equip_type_id))
  1362. # datalist = RecentCBDdata.objects.all()
  1363. # for i in datalist:
  1364. # if i.discern == False:
  1365. # i.disc = 1
  1366. # i.save()
  1367. # elif i.discern == True:
  1368. # i.disc = 0
  1369. # i.save()
  1370. # print("数据导入完毕")
  1371. # 判断测报灯流量卡充值停用账号
  1372. # simlist = Equip_SimInfo.objects.all()
  1373. # for i in simlist:
  1374. # dateTime_p = datetime.datetime.strptime(i.expiry_date,'%Y-%m-%d %H:%M:%S')
  1375. # # 判断sim卡是否30天到期
  1376. # if dateTime_p - datetime.datetime.now() > datetime.timedelta(days=30):
  1377. # pass
  1378. # elif datetime.timedelta(days=0) > dateTime_p - datetime.datetime.now() > datetime.timedelta(days=0):
  1379. # print("发送短信通知")
  1380. # elif dateTime_p - datetime.datetime.now() < datetime.timedelta(days=0):
  1381. # if i.equip_id.equip_type_id == 2:
  1382. # print("杀虫灯")
  1383. # # 判断杀虫灯状态30天内是否有数据
  1384. # if datetime.datetime.now() - SCDstatus.objects.get(equip_id=i.equip_id).upl_time > datetime.timedelta(days=30):
  1385. # pass
  1386. # else:
  1387. # print("停用账号")
  1388. # elif i.equip_id.equip_type_id == 3:
  1389. # print("测报灯")
  1390. # # 判断测报灯状态30天内是否有数据
  1391. # if datetime.datetime.now() - CBDstatus.objects.get(equip_id=i.equip_id).upl_time > datetime.timedelta(days=30):
  1392. # pass
  1393. # else:
  1394. # print("停用账号")
  1395. # end_date = datetime.datetime.now()
  1396. # one_day = datetime.timedelta(days=1)
  1397. # one_day_later = datetime.datetime.now() - one_day
  1398. # print(one_day_later)
  1399. # new_time = "%s-%s-%s %s:%s:%s" %(one_day_later.year,one_day_later.month,one_day_later.day,"19","00","00")
  1400. # start_date = datetime.datetime.strptime(new_time,"%Y-%m-%d %H:%M:%S")
  1401. # cbd_obj = Equip.objects.get(equip_id='86123456789')
  1402. # equip_name = ""
  1403. # if cbd_obj.equip_name == "" or cbd_obj.equip_name == None:
  1404. # equip_name = cbd_obj.equip_id
  1405. # else:
  1406. # equip_name = cbd_obj.equip_name
  1407. # msg_conf_list = Msg_Conf.objects.get(equip_id=cbd_obj)
  1408. # msgconf = eval(msg_conf_list.conf)
  1409. # if msgconf["appointPest"] == "on":
  1410. # pest_num = 0
  1411. # pest_name = []
  1412. # pest_nums = []
  1413. # pest_dict = {}
  1414. # pest_dict_new = {}
  1415. # cbd_list = CBDphoto.objects.filter(equip_id=cbd_obj)
  1416. # for x in cbd_list:
  1417. # if x.indentify_result == None or x.indentify_result == "":
  1418. # pass
  1419. # else:
  1420. # for a in x.indentify_result.split("#"):
  1421. # pest_num = pest_num + int(a.split(",")[1])
  1422. # pest_name.append(int(a.split(",")[0]))
  1423. # pest_nums.append(int(a.split(",")[1]))
  1424. # for xx in range(len(pest_name)):
  1425. # c = {pest_name[xx]:pest_nums[xx]}
  1426. # for d in c:
  1427. # if d in pest_dict:
  1428. # pest_dict[d] = pest_dict[d] + c[d]
  1429. # else:
  1430. # pest_dict.update(c)
  1431. # print(pest_dict)
  1432. # send_dict = {}
  1433. # print(msgconf["appointPestName"].split("#"))
  1434. # print(msgconf["appointPestNum"].split("#"))
  1435. # msg_name = msgconf["appointPestName"].split("#")
  1436. # msg_num = msgconf["appointPestNum"].split("#")
  1437. # for i in range(len(msg_name)):
  1438. # if pest_dict[int(msg_name[i])] > int(msg_num[i]):
  1439. # aaa = {insect_dict_new[msg_name[i]]:"%s头"%int(msg_num[i])}
  1440. # send_dict.update(aaa)
  1441. # print(send_dict)
  1442. # if pest_dict[int(msgconf["appointPestName"])] >= int(msgconf["appointPestNum"]):
  1443. # pass
  1444. # pest_num = 0
  1445. # pest_name = []
  1446. # pest_nums = []
  1447. # pest_dict = {}
  1448. # pest_dict_new = {}
  1449. # equip_obj = Equip.objects.get(equip_id="868575028850321")
  1450. # file_dir = "pyftp/ftp_file/bzy_photo/%s"%868575028850321
  1451. # print("file_dir",file_dir)
  1452. # sta1 = BZYstatus.objects.all()
  1453. # sta3 = []
  1454. # photo_list = []
  1455. # for i in sta1:
  1456. # sta3.append(i.equip_id.equip_id)
  1457. # for imei in sta3:
  1458. # equip_obj = Equip.objects.get(equip_id=imei)
  1459. # file_dir = "pyftp/ftp_file/bzy_photo/%s"%imei
  1460. # # print("file_dir",file_dir)
  1461. # for root, dirs, files in os.walk(file_dir):
  1462. # # print("当前目录为=========>>",root) #当前目录路径
  1463. # # print("当前子目录为=========>>",dirs) #当前路径下所有子目录
  1464. # if root.endswith(imei):
  1465. # pass
  1466. # else:
  1467. # # print("当前目录------->>",root)
  1468. # for roots, dirss, file in os.walk(root):
  1469. # # print(roots) #当前目录路径
  1470. # # print(dirs) #当前路径下所有子目录
  1471. # # print(file) #当前路径下所有非目录子文件
  1472. # if file != []:
  1473. # for i in file:
  1474. # photo_addr = roots + "/" + i
  1475. # # print(photo_addr)
  1476. # if BZYphoto.objects.filter(addr=photo_addr).exists():
  1477. # # print("照片存在")
  1478. # # print(i[17:29])
  1479. # # print("-----")
  1480. # # sp = datetime.datetime.now().year
  1481. # # sp_str = i.split(str(sp))[1]
  1482. # # # print(sp_str[0:8])
  1483. # # st = str(sp) + sp_str[0:8]
  1484. # # print(st)
  1485. # pass
  1486. # else:
  1487. # print("-----")
  1488. # sp = datetime.datetime.now().year
  1489. # sp_str = i.split(str(sp))[1]
  1490. # # print(sp_str[0:8])
  1491. # st = str(sp) + sp_str[0:8]
  1492. # # st = i[17:29]
  1493. # # print(st)
  1494. # pic_time = datetime.datetime.strptime(st,"%Y%m%d%H%M%S")
  1495. # print(pic_time)
  1496. # BZYphoto.objects.create(equip_id=equip_obj,addr=photo_addr,upl_time=pic_time)
  1497. # sta1 = BZYstatus.objects.all()
  1498. # sta3 = []
  1499. # photo_list = []
  1500. # for i in sta1:
  1501. # sta3.append(i.equip_id.equip_id)
  1502. # for imei in sta3:
  1503. # equip_obj = Equip.objects.get(equip_id=imei)
  1504. # file_dir = "pyftp/ftp_file/bzy_photo/%s"%imei
  1505. # # print("file_dir",file_dir)
  1506. # for root, dirs, files in os.walk(file_dir):
  1507. # # print("当前目录为=========>>",root) #当前目录路径
  1508. # # print("当前子目录为=========>>",dirs) #当前路径下所有子目录
  1509. # if root.endswith(imei):
  1510. # pass
  1511. # else:
  1512. # # print("当前目录------->>",root)
  1513. # for roots, dirss, file in os.walk(root):
  1514. # # print(roots) #当前目录路径
  1515. # # print(dirs) #当前路径下所有子目录
  1516. # # print(file) #当前路径下所有非目录子文件
  1517. # if file != []:
  1518. # for i in file:
  1519. # photo_addr = roots + "/" + i
  1520. # # print(photo_addr)
  1521. # if BZYphoto.objects.filter(addr=photo_addr).exists():
  1522. # print("照片存在")
  1523. # print(i[16:34])
  1524. # else:
  1525. # # os.path.getctime(photo_addr) # 输出文件的创建时间
  1526. # # print("文件创建时间",os.path.getctime(photo_addr))
  1527. # # timeStamp = os.path.getctime(photo_addr)
  1528. # # timeArray = time.localtime(timeStamp)
  1529. # # otherStyleTime = time.strftime("%Y-%m-%d %H:%M:%S", timeArray)
  1530. # # print(otherStyleTime)
  1531. # # BZYphoto.objects.create(equip_id=equip_obj,addr=photo_addr)
  1532. # print("-----")
  1533. # print("=========================")
  1534. # # print(photo_list)
  1535. # print("=========================")
  1536. # sta1 = SCDstatus.objects.all()
  1537. # sta2 = CBDstatus.objects.all()
  1538. # # 获取设备列表中的SIM卡的iccid号码:
  1539. # iccids = []
  1540. # # 获取设备的id:
  1541. # equip_ids = []
  1542. # # 获取设备的名称:
  1543. # equip_names = []
  1544. # # 遍历查询流量信息:
  1545. # siminfos = []
  1546. # for i in sta1:
  1547. # try:
  1548. # iccid = eval(i.scd_status)['iccid']
  1549. # except:
  1550. # iccid = ""
  1551. # iccids.append(iccid)
  1552. # equip_ids.append(str(i.equip_id))
  1553. # equip_names.append(str(i.equip_id.equip_name))
  1554. # for i in sta2:
  1555. # try:
  1556. # iccid = eval(i.cbd_status)['iccid']
  1557. # except:
  1558. # iccid = ""
  1559. # iccids.append(iccid)
  1560. # equip_ids.append(str(i.equip_id))
  1561. # equip_names.append(str(i.equip_id.equip_name))
  1562. # print('all iccids :',iccids)
  1563. # print('all equip_ids :',equip_ids)
  1564. # print('all equip_names :',equip_names)
  1565. # print('iccids :',iccids)
  1566. # print('equip_ids :',equip_ids)
  1567. # print('equip_names :',equip_names)
  1568. # # 调用api查到的iccid号:
  1569. # for i in range(len(iccids)):
  1570. # if iccids[i] != "":
  1571. # # print("------",i)
  1572. # # print('iccids :',iccids[i])
  1573. # # print('equip_ids :',equip_ids[i])
  1574. # # print('equip_names :',equip_names[i])
  1575. # res = get_siminfo(iccids[i])
  1576. # sim_res = res.text.encode('utf-8').decode('unicode_escape')
  1577. # if eval(sim_res)["code"] == 0:
  1578. # timeStamp = eval(sim_res)["data"]["expiry_date"]
  1579. # dateArray = datetime.datetime.utcfromtimestamp(timeStamp)
  1580. # otherStyleTime = dateArray.strftime("%Y-%m-%d %H:%M:%S")
  1581. # timeStamp1 = eval(sim_res)["data"]["active_date"]
  1582. # dateArray1 = datetime.datetime.utcfromtimestamp(timeStamp1)
  1583. # otherStyleTime1 = dateArray1.strftime("%Y-%m-%d %H:%M:%S")
  1584. # if Equip_SimInfo.objects.filter(equip_id=equip_ids[i]).exists():
  1585. # siminfo_obj = Equip_SimInfo.objects.get(equip_id=equip_ids[i])
  1586. # siminfo_obj.equip_name = equip_names[i]
  1587. # siminfo_obj.iccid = eval(sim_res)["data"]["iccid"]
  1588. # siminfo_obj.msisdn = eval(sim_res)["data"]["msisdn"]
  1589. # siminfo_obj.imsi = eval(sim_res)["data"]["imsi"]
  1590. # siminfo_obj.sp_code = eval(sim_res)["data"]["sp_code"]
  1591. # siminfo_obj.carrier = eval(sim_res)["data"]["carrier"]
  1592. # siminfo_obj.data_plan = eval(sim_res)["data"]["data_plan"]
  1593. # siminfo_obj.data_usage = eval(sim_res)["data"]["data_usage"]
  1594. # siminfo_obj.account_status = eval(sim_res)["data"]["account_status"]
  1595. # siminfo_obj.expiry_date = otherStyleTime
  1596. # siminfo_obj.active = eval(sim_res)["data"]["active"]
  1597. # siminfo_obj.test_valid_date = eval(sim_res)["data"]["test_valid_date"]
  1598. # siminfo_obj.silent_valid_date = eval(sim_res)["data"]["silent_valid_date"]
  1599. # siminfo_obj.test_used_data_usage = eval(sim_res)["data"]["test_used_data_usage"]
  1600. # siminfo_obj.active_date = otherStyleTime1
  1601. # siminfo_obj.data_balance = eval(sim_res)["data"]["data_balance"]
  1602. # siminfo_obj.outbound_date = eval(sim_res)["data"]["outbound_date"]
  1603. # siminfo_obj.support_sms = eval(sim_res)["data"]["support_sms"]
  1604. # siminfo_obj.upl_time = datetime.datetime.now()
  1605. # siminfo_obj.save()
  1606. # else:
  1607. # Equip_SimInfo.objects.create(
  1608. # equip_id = Equip.objects.get(equip_id=equip_ids[i]),
  1609. # equip_name = equip_names[i],
  1610. # iccid = eval(sim_res)["data"]["iccid"],
  1611. # msisdn = eval(sim_res)["data"]["msisdn"],
  1612. # imsi = eval(sim_res)["data"]["imsi"],
  1613. # sp_code = eval(sim_res)["data"]["sp_code"],
  1614. # carrier = eval(sim_res)["data"]["carrier"],
  1615. # data_plan = eval(sim_res)["data"]["data_plan"],
  1616. # data_usage = eval(sim_res)["data"]["data_usage"],
  1617. # account_status = eval(sim_res)["data"]["account_status"],
  1618. # expiry_date = otherStyleTime,
  1619. # active = eval(sim_res)["data"]["active"],
  1620. # test_valid_date = eval(sim_res)["data"]["test_valid_date"],
  1621. # silent_valid_date = eval(sim_res)["data"]["silent_valid_date"],
  1622. # test_used_data_usage = eval(sim_res)["data"]["test_used_data_usage"],
  1623. # active_date = otherStyleTime1,
  1624. # data_balance = eval(sim_res)["data"]["data_balance"],
  1625. # outbound_date = eval(sim_res)["data"]["outbound_date"],
  1626. # support_sms = eval(sim_res)["data"]["support_sms"]
  1627. # )
  1628. # print("-----sim卡信息更新成功------")
  1629. # 保存调用查询流量的api返回的数据;
  1630. # dat = []
  1631. # for j in list(range(0,siminfo_dict['data']['count'])):
  1632. # equip_iccids.append(siminfo_dict['data']['card_list'][j]['iccid'])
  1633. # # print('equip_iccids:',equip_iccids)
  1634. # for j in list(range(0,len(iccids))):
  1635. # siminfo_dict=eval(siminfo_str)
  1636. # if (iccids[j] in equip_iccids) == True:
  1637. # dat.append(siminfo_dict['data']['card_list'][equip_iccids.index(iccids[j])])
  1638. # else:
  1639. # dat.append({})
  1640. # dat[j]['equip_id']=equip_ids[j]
  1641. # dat[j]['equip_name']=equip_names[j]
  1642. # # print("dat[%d]=%s" %(j,dat[j]))
  1643. # iccids[j] = ""# 每次判断玩将该值清空,防止多个设备用一个SIM卡测试时显示异常;
  1644. # # print('----- iccids :',iccids)
  1645. # print("------------------------",dat)
  1646. # print("dat:",dat)
  1647. # ----------------------------------测报灯图片存在与否判断-----------------------------------
  1648. # sta1 = CBDstatus.objects.all()
  1649. # sta3 = []
  1650. # photo_list = []
  1651. # for i in sta1:
  1652. # sta3.append(i.equip_id.equip_id)
  1653. # for imei in sta3:
  1654. # file_dir = "pyftp/ftp_file/ykm_cbd/%s"%imei
  1655. # # print("file_dir",file_dir)
  1656. # for root, dirs, files in os.walk(file_dir):
  1657. # # print("当前目录为=========>>",root) #当前目录路径
  1658. # # print("当前子目录为=========>>",dirs) #当前路径下所有子目录
  1659. # if root.endswith(imei):
  1660. # pass
  1661. # else:
  1662. # # print("当前目录------->>",root)
  1663. # for roots, dirss, file in os.walk(root):
  1664. # # print(roots) #当前目录路径
  1665. # # print(dirs) #当前路径下所有子目录
  1666. # # print(file) #当前路径下所有非目录子文件
  1667. # if file != []:
  1668. # for i in file:
  1669. # photo_addr = roots + "/" + i
  1670. # # print(photo_addr)
  1671. # if CBDphoto.objects.filter(addr=photo_addr).exists():
  1672. # print("照片存在")
  1673. # else:
  1674. # photo_list.append(photo_addr)
  1675. # print("=========================")
  1676. # print(photo_list)
  1677. # print("=========================")
  1678. # -----------------------------------------------------------------------------------------------
  1679. # sta1 = BZYstatus.objects.all()
  1680. # sta3 = []
  1681. # photo_list = []
  1682. # for i in sta1:
  1683. # sta3.append(i.equip_id.equip_id)
  1684. # for imei in sta3:
  1685. # file_dir = "pyftp/ftp_file/ykm_cbd/%s"%imei
  1686. # # print("file_dir",file_dir)
  1687. # for root, dirs, files in os.walk(file_dir):
  1688. # # print("当前目录为=========>>",root) #当前目录路径
  1689. # # print("当前子目录为=========>>",dirs) #当前路径下所有子目录
  1690. # if root.endswith(imei):
  1691. # pass
  1692. # else:
  1693. # # print("当前目录------->>",root)
  1694. # for roots, dirss, file in os.walk(root):
  1695. # # print(roots) #当前目录路径
  1696. # # print(dirs) #当前路径下所有子目录
  1697. # # print(file) #当前路径下所有非目录子文件
  1698. # if file != []:
  1699. # for i in file:
  1700. # photo_addr = roots + "/" + i
  1701. # # print(photo_addr)
  1702. # if CBDphoto.objects.filter(addr=photo_addr).exists():
  1703. # print("照片存在")
  1704. # else:
  1705. # photo_list.append(photo_addr)
  1706. # print("=========================")
  1707. # print(photo_list)
  1708. # print("=========================")
  1709. # try:
  1710. # path = "pyftp/ftp_file/ykm_cbd/%s"%imei
  1711. # lsdir = os.listdir(path)
  1712. # dirs = [i for i in lsdir if os.path.isdir(os.path.join(path, i))]
  1713. # if dirs:
  1714. # for i in dirs:
  1715. # print_files(os.path.join(path, i))
  1716. # files = [i for i in lsdir if os.path.isfile(os.path.join(path,i))]
  1717. # for f in files:
  1718. # print(os.path.join(path, f))
  1719. # except Exception as e:
  1720. # print("=================>>",e)
  1721. # print("文件夹不存在")
  1722. # file_dir = "pyftp/ftp_file/ykm_cbd/%s"%imei
  1723. # print("file_dir",file_dir)
  1724. # for root, dirs, files in os.walk(file_dir):
  1725. # print(root) #当前目录路径
  1726. # print(dirs) #当前路径下所有子目录
  1727. # print(files) #当前路径下所有非目录子文件
  1728. # for i in files:
  1729. # file = file_dir + "/" + i
  1730. # jpg_time = time.ctime(os.path.getctime(file))
  1731. # print("jpg_time",jpg_time)
  1732. # st = s_time+jpg_time[11:19]
  1733. # print("-------------------",i.split(".")[0])
  1734. # pic_time_1 = s_time+i.split(".")[0]
  1735. # pic_time_1 = datetime.datetime.strptime(pic_time_1,"%Y%m%d%H-%M-%S")
  1736. # print("-------------------->",pic_time_1)
  1737. # print("-------------------->",type(pic_time_1))
  1738. # pic_time = datetime.datetime.strptime(st,"%Y%m%d%H:%M:%S")
  1739. # print("类型查看",type(pic_time))
  1740. # print("把字符串转成datetime: ", datetime.datetime.strptime(st,"%Y%m%d%H:%M:%S"))
  1741. # if CBDphoto.objects.filter(addr=file).exists():
  1742. # photoobj = CBDphoto.objects.get(addr=file)
  1743. # photoobj.upl_time = pic_time_1
  1744. # photoobj.save()
  1745. # print("照片存在")
  1746. # else:
  1747. # print("照片不存在")
  1748. # try:
  1749. # imei_obj = Equip.objects.get(equip_id=imei)
  1750. # CBDphoto.objects.create(equip_id=imei_obj,addr=file,upl_time=pic_time)
  1751. # except Exception as e:
  1752. # print("错误信息为",e)
  1753. # a = 0
  1754. # qxz_obj = QXZdata.objects.filter(equip_id="16062023")
  1755. # for i in qxz_obj:
  1756. # a = a + 1
  1757. # i.delete()
  1758. # print("----删除成功%s"%a)
  1759. # =========================================================================================================
  1760. # equip_list = Equip.objects.all()
  1761. # bbb = 0
  1762. # for i in equip_list:
  1763. # photo_list = CBDphoto.objects.filter(equip_id=i.equip_id)
  1764. # status_list = CBDdata.objects.filter(equip_id=i.equip_id)
  1765. # for x in photo_list:
  1766. # for a in status_list:
  1767. # if x.at == None:
  1768. # if a.upl_time.year == x.upl_time.year and a.upl_time.month == x.upl_time.month and a.upl_time.day == x.upl_time.day and a.upl_time.hour == x.upl_time.hour:
  1769. # # print("数据时间==================>",a.upl_time)
  1770. # # print("设备温度==================>",eval(a.cbd_data)["at"])
  1771. # # print("设备湿度==================>",eval(a.cbd_data)["ah"])
  1772. # # print("照片时间==================>",x.upl_time)
  1773. # x.at = eval(a.cbd_data)["at"]
  1774. # x.ah = eval(a.cbd_data)["ah"]
  1775. # x.save()
  1776. # bbb = bbb + 1
  1777. # print(bbb)
  1778. # print("========操作成功=======")
  1779. # =========================================================================================================
  1780. # file_dir="pyftp/ftp_file/bzy_photo/865650042816310/201909"
  1781. # # print("file_dir",file_dir)
  1782. # # bzy_obj = Equip.objects.get(equip_id=imei)
  1783. # for root, dirs, files in os.walk(file_dir):
  1784. # print("当前目录为=========>>",root) #当前目录路径
  1785. # print("当前子目录为=========>>",dirs) #当前路径下所有子目录
  1786. # print("当前目录文件为=========>>",files) #当前路径下所有非目录子文件
  1787. # for i in files:
  1788. # photo_addr = file_dir + "/" + i
  1789. # print("文件夹图片路径===========》》",photo_addr)
  1790. # if BZYphoto.objects.filter(addr=photo_addr).exists():
  1791. # print("照片存在")
  1792. # else:
  1793. # print("照片不存在")
  1794. # BZYphoto.objects.create(equip_id=bzy_obj,addr=photo_addr)
  1795. # if root.endswith(imei):
  1796. # pass
  1797. # else:
  1798. # # print("当前目录------->>",root)
  1799. # for roots, dirss, file in os.walk(root):
  1800. # # print(roots) #当前目录路径
  1801. # # print(dirs) #当前路径下所有子目录
  1802. # # print(file) #当前路径下所有非目录子文件
  1803. # if file != []:
  1804. # for i in file:
  1805. # photo_addr = roots + "/" + i
  1806. # # print(photo_addr)
  1807. # if BZYphoto.objects.filter(addr=photo_addr).exists():
  1808. # print("照片存在")
  1809. # else:
  1810. # BZYphoto.objects.create(equip_id=bzy_obj,addr=photo_addr)
  1811. # ---------------------------丁艳青定制设备----------------------------------------------------------
  1812. # one_day = datetime.timedelta(days=1)
  1813. # minut = datetime.timedelta(minutes=random.choice(range(20,34)))
  1814. # start_time = '2019-07-29 19:00:08'
  1815. # start_time = datetime.datetime.strptime(start_time,'%Y-%m-%d %H:%M:%S')
  1816. # a = 1
  1817. # b = 1
  1818. # photo_list = CBDphoto.objects.filter(equip_id="865650040895753")
  1819. # for i in photo_list:
  1820. # i.upl_time = start_time + datetime.timedelta(days=b) + datetime.timedelta(minutes=random.choice(range(20,34))) * a
  1821. # i.save()
  1822. # a = a + 1
  1823. # print("修改次数",a)
  1824. # if a == 5:
  1825. # print("---跨天")
  1826. # b = b + 1
  1827. # i.upl_time = start_time + datetime.timedelta(days=b) + datetime.timedelta(minutes=random.choice(range(20,34)))
  1828. # i.save()
  1829. # a = 0
  1830. # data_obj = RecentCBDdata.objects.get(equip_id="865650042837894")
  1831. # print(eval(data_obj.cbd_data)['at'])
  1832. # scd_list = RecentSCDdata.objects.all().values()
  1833. # for i in scd_list:
  1834. # try:
  1835. # if eval(i['scd_data'])['lng'] == 0:
  1836. # print(i['equip_id_id'])
  1837. # except:
  1838. # print("---报错设备号为:",i['equip_id_id'])
  1839. # print("-----lng-------",eval(i['scd_data'])['lng'])