from qcloudsms_py import SmsSingleSender from qcloudsms_py.httpclient import HTTPError from qcloudsms_py import SmsMultiSender import os import django import sys BASE_DIR = os.path.dirname(os.path.abspath(__file__)) # 定位到你的django根目录 sys.path.append(os.path.abspath(os.path.join(BASE_DIR, os.pardir))) os.environ.setdefault("DJANGO_SETTINGS_MODULE", "yfwlw_pro.settings") # project_name 项目名称 django.setup() import json import time import requests import datetime from apps.ReportManage.all_dict import mobile_list, insect_dict_new, qxz_dict from apps.AppInfoManage.models import Equip, Equip_type, CBDphoto, Msg_Send, Msg_Conf, Equip_SimInfo, SCDstatus, CBDstatus, RecentCBDdata, MyUser,JKphoto, BZYdata, QXZstatus,QXZdata,\ QXZstatus_New, QXZ_Conf, QXZ_Default_Conf, JKphoto, Alarm_record, SCDdata, SCDstatus_all, QXZdata_New, CBDphoto_desc,BZYphoto, JKdata, User_Log, CBDstatus_all,\ SCDstatus_all, YBQstatus from apps.SimInfo.views import get_siminfo import paho.mqtt.client as mqtt # 短信应用 SDK AppID appid = 1400227496 # SDK AppID 以1400开头 # 短信应用 SDK AppKey appkey = "c9aba961bd30072f1e1b9272077abaea" from requests.auth import HTTPBasicAuth from imutils import paths import cv2 import shutil import random from django.db import transaction # print(random.randint(10,30)) # 测试1 import xlrd import xlwt import socket import re import random from PIL import Image from io import BytesIO #8.12号生成测报灯识别图片 equip_list = [ "865650044618979", "865650044542088", "867814040035020", "867814040006732", "867814040033694", "865650044455844", "865650044519359", "865650044463053", "865650044591457", "865650044585053", "865650044591630", "865650044620793", "865650044451181", "865650044451058", "865650044557524", "865650044560056", ] url = 'http://60.166.14.184:9143/upload' for i in equip_list: cbd_list = CBDphoto.objects.filter(equip_id=i) lng = CBDstatus.objects.get(equip_id=i).lng lat = CBDstatus.objects.get(equip_id=i).lat for x in cbd_list: print("原图",x.addr) print("识别后的图片",x.indentify_photo) if x.indentify_photo: tes = x.indentify_photo.split("/") try: # print("/home/web/yfwlw/" + x.addr) print("/data/yfwlw/" + x.addr) # 测试服务器路径 # imageFile = {'imageFile':('pic.jpg',open("/home/web/yfwlw/" + x.addr,'rb'),'image/jpeg')} imageFile = {'imageFile':('pic.jpg',open("/data/yfwlw/" + x.addr,'rb'),'image/jpeg')} data = {'longitude':lng,'latitude':lat} print('data:',data) res = requests.post(url,data=data,files=imageFile,timeout=10) print("res:",res.text) resp = json.loads(res.text) print("resp------------",resp) img_src = resp["returnResult"]["returnImageUrl"] response = requests.get(img_src) print("img_src-------------",img_src) print(response) code = 1 except Exception as e: print(e) code = 0 if code == 1: try: if resp["returnResult"]["returnStatus"] == "0": print("识别结果为空,不进行保存") else: # 将识别结果中的链接中的图片存入本地 测试服务器 # pic_dir_1 = "/home/web/yfwlw/result_pyftp/ftp_file/ykm_cbd/" + i + "/" #正式服务器 pic_dir_1 = "/data/yfwlw/result_pyftp/ftp_file/ykm_cbd/" + i + "/" print("pic_dir_1:",pic_dir_1) if os.path.exists(pic_dir_1) == False: os.makedirs(pic_dir_1) response = requests.get(img_src) image = Image.open(BytesIO(response.content)) insect_image_addr = pic_dir_1 + tes[-1] print("insect_image_addr:",insect_image_addr) image.save(insect_image_addr) print("------------------图片保存成功") except Exception as e: print(e) # equip_obj = Equip.objects.get(equip_id="867814040037125") # cbd_photo_list = CBDphoto.objects.filter(equip_id="869300039253749") # for i in cbd_photo_list: # addr = i.addr.replace("869300039253749","867814040037125") # i.equip_id = equip_obj # i.addr = addr # i.save() # _list = YBQstatus.objects.all() # for i in _list: # # print(eval(i.ybq_status)['iccid']) # iccid = eval(i.ybq_status)['iccid'] # if len(iccid) == 20: # print(iccid) # sta1 = RecentCBDdata.objects.all().values() # for x in sta1: # print("lng",eval(x['cbd_data'])['lng']) # print("lat",eval(x['cbd_data'])['lat']) # try: # sta2.append({ # "equip_id": x['equip_id_id'], # "equip_type": 3, # "equip_name": x['equip_name'], # "gps": eval(x['cbd_data'])['gps'], # "lng": eval(x['cbd_data'])['lng'], # "lat": eval(x['cbd_data'])['lat'] # }) # except: # sta2.append({ # "equip_id": x['equip_id_id'], # "equip_type": 3, # "equip_name": x['equip_name'], # "gps": 2, # "lng": eval(x['cbd_data'])['lng'], # "lat": eval(x['cbd_data'])['lat'] # }) # dver = "5.9.9-03(1)HK" # _list = "5.9.9-03HK" # a = re.sub('\\(.*?\\)','',_list) # print(a) #7.3号 分配账号脚本 # equip_list = Equip.objects.filter(equip_id=i) # if equip_list: # for x in equip_list: # if x.equip_user: # datt.append(x.equip_id) # else: # x.equip_user = username # x.save() # else: # dat.append(i) # print("设备已绑定用户=====",datt) # print("未找到设备号=====",dat) # start_time = '2020-01-01' # end_time = '2020-05-30' # start_time = datetime.datetime.strptime(start_time,'%Y-%m-%d') # end_time = datetime.datetime.strptime(end_time,'%Y-%m-%d') # print(start_time) # _list = [] # equip_list = Equip.objects.filter(equip_type=3,equip_add_time__range=(start_time,end_time)) # for i in equip_list: # if CBDphoto.objects.filter(equip_id=i,upl_time__range=(start_time,end_time)).exists(): # print("有照片") # _list.append(i.equip_id) # print("====>>",i.equip_id) # print(_list) # start_time = '2020-04-20' # end_time = '2020-05-30' # start_time = datetime.datetime.strptime(start_time,'%Y-%m-%d') # end_time = datetime.datetime.strptime(end_time,'%Y-%m-%d') # Equip.objects.get(equip_id=866714042686849).delete() # print("操作成功") # 物联网自动虫情信息采集设备(4.0)  对应的版本是5版本带HK的,如5.9.9HK # 物联网自动虫情信息采集设备(3.0)  对应的版本是4版本带re,hk的,如4.2.37re,4.1HK # 物联网自动虫情信息采集设备(2.0)  对应版本是1,2,3版本,如1.0.0;2.2.14;3.2.0 # 自动虫情测报灯(1.0)             对应有4版本,5版本带ZP # 高空测报灯(1.0)                 对应4版本带GK,5版本的高空和转盘使用同一版本号,无法区分. # 糖醋测报                          对应1版本带TC, # 简易高空                          对应5版本带gk(区分大小写) # 定制版本                          其他版本 # _list = CBDstatus.objects.all() # for i in _list: # print("equip_id",i.equip_id) # try: # cbddataobj = RecentCBDdata.objects.get(equip_id=i.equip_id) # except: # continue # # print(eval(i.cbd_status)['dver']) # dver = eval(i.cbd_status)['dver'] # if dver.startswith("5") and dver.endswith("HK"): # i.etype = "4.0测报灯" # i.save() # cbddataobj.etype = "4.0测报灯" # cbddataobj.save() # print("4.0测报灯",dver) # elif dver.startswith("4") and dver.endswith("HK"): # i.etype = "3.0测报灯" # i.save() # cbddataobj.etype = "3.0测报灯" # cbddataobj.save() # print("3.0测报灯",dver) # elif dver.startswith("4") and dver.endswith("re"): # i.etype = "3.0测报灯" # i.save() # cbddataobj.etype = "3.0测报灯" # cbddataobj.save() # print("3.0测报灯",dver) # elif dver.startswith("1") or dver.startswith("2") or dver.startswith("3"): # i.etype = "2.0测报灯" # i.save() # cbddataobj.etype = "2.0测报灯" # cbddataobj.save() # print("2.0测报灯",dver) # elif dver.endswith("ZP"): # i.etype = "1.0测报灯" # i.save() # cbddataobj.etype = "1.0测报灯" # cbddataobj.save() # print("1.0测报灯",dver) # elif dver.startswith("4") and dver.endswith("GK"): # i.etype = "高空测报灯" # i.save() # cbddataobj.etype = "高空测报灯" # cbddataobj.save() # print("高空测报灯",dver) # elif dver.endswith("TC"): # i.etype = "糖醋测报灯" # i.save() # cbddataobj.etype = "糖醋测报灯" # cbddataobj.save() # print("糖醋测报灯",dver) # elif dver.startswith("5") and dver.endswith("gk"): # i.etype = "简易高空测报灯" # i.save() # cbddataobj.etype = "简易高空测报灯" # cbddataobj.save() # print("简易高空测报灯",dver) # def on_connect(client, userdata, flags, rc): # print("Connected with result code "+str(rc)) # client.subscribe("api/v1/iot/dragon/868956044807455") # 订阅消息 # def on_message(client, userdata, msg): # print("主题:"+msg.topic+" 消息:"+str(msg.payload.decode('utf-8'))) # def on_subscribe(client, userdata, mid, granted_qos): # print("On Subscribed: qos = %d" % granted_qos) # def on_disconnect(client, userdata, rc): # if rc != 0: # print("Unexpected disconnection %s" % rc) # # HOST = "aftrnmynhcbc5elv-master-nlb-FI.jvessel-open-hb.jdcloud.com" # # HOST = "120.27.222.26" # HOST = "39.104.94.153" # PORT = 1883 # # client_id = "1083421xxxxx" # 没有就不写,此处部分内容用xxx代替原内容,下同 # client_id = time.strftime('%Y%m%d%H%M%S', time.localtime(time.time())) # data = { # "devId": "868956044807455", # "ossPath": "http:\/\/120.27.222.26\/pyftp\/ftp_file\/ykm_cbd\/868956044807455\/192.168.1.100_01_20200612104405264_ALARM_INPUT.jpg", # "collectDT": "2020-06-12 10:43:05", # "manuCode": "10014", # "result": "", # "resultImage": "" # } # param = json.dumps(data) # client = mqtt.Client(client_id) # client.username_pw_set("868956044807455", "") # client.on_connect = on_connect # client.on_message = on_message # client.on_subscribe = on_subscribe # client.on_disconnect = on_disconnect # aa = client.connect(HOST, PORT, 60) # print("---------->>",aa) # client.publish("api/v1/iot/dragon/868956044807455", payload=param, qos=0) # 发送消息 # client.loop_start() # print("执行完毕") # data = { # "devId": "868956044807455", # "ossPath": "http:\/\/120.27.222.26\/pyftp\/ftp_file\/ykm_cbd\/868956044807455\/192.168.1.100_01_20200612104405263_ALARM_INPUT.jpg", # "collectDT": "2020-06-12 10:43:05", # "manuCode": "10014", # "result": "", # "resultImage": "" # } # TASK_TOPIC = 'api/v1/iot/dragon/868956044807455' # 客户端发布消息主题 # """ # 客户端发布消息 # :param message: 消息主体 # :return: # """ # payload = data # # publish(主题:Topic; 消息内容) # client_id = time.strftime('%Y%m%d%H%M%S', time.localtime(time.time())) # client = mqtt.Client(client_id, transport='tcp') # client.username_pw_set("868956044807455", "868956044807455") # # client.connect("aftrnmynhcbc5elv-master-nlb-FI.jvessel-open-hb.jdcloud.com", 1883, 60) # 此处端口默认为1883,通信端口期keepalive默认60 # client.connect("120.27.222.26", 1883, 60) # 此处端口默认为1883,通信端口期keepalive默认60 # aa = client.publish(TASK_TOPIC, json.dumps(payload, ensure_ascii=False, qos=0)) # bb = client.loop_start() # print(bb) # print(aa) # print("京东信息发送成功",data) # print(datetime.datetime.now()) # data = [] # data1 = [] # simlist = Equip_SimInfo.objects.filter(data_plan="10",account_status="3") # for i in simlist: # print("------->>",i.iccid) # 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}) # title = ["设备id","设备类型","iccid","已用","剩余"] # book = xlwt.Workbook() # 创建一个excel对象 # sheet = book.add_sheet('Sheet1',cell_overwrite_ok=True) # 添加一个sheet页 # for i in range(len(title)): # 遍历列 # # sheet.write(0,i,title[i],style) # 将title数组中的字段写入到0行i列中 # sheet.write(0,i,title[i]) # 将title数组中的字段写入到0行i列中 # # print(sta2) # for xx in range(len(data1)): # 遍历列表 # if data1[xx]['equip_type'] == "3": # _type = "测报灯" # # off_time = datetime.datetime.strftime(data1[xx]['off_time'],'%Y-%m-%d') # else: # _type = "杀虫灯" # # off_time = "" # # creat_time = datetime.datetime.strftime(data1[xx]['creat_time'],'%Y-%m-%d') # sheet.write(xx+1,0,data1[xx]['equip_id']) # 将equip_id写入到第x+1行,第0列中 # sheet.write(xx+1,1,_type) # sheet.write(xx+1,2,data1[xx]['iccid']) # sheet.write(xx+1,3,data1[xx]['data_usage']) # sheet.write(xx+1,4,data1[xx]['data_balance']) # book.save("654321.xlsx") # one_month = datetime.timedelta(days=30) # nowtime = datetime.datetime.now() # end_time = nowtime # start_time = nowtime - one_month # print(start_time) # aabbcc = Alarm_record.objects.all().exclude(alarm_time__range=(start_time,end_time)).delete() # for i in aabbcc: # i.delete() # print(i.alarm_time) # print(CBDstatus.objects.get(equip_id_id="865650044552954").rtuinfo) # def mkdir(path): # # 去除首位空格 # path=path.strip() # # 去除尾部 \ 符号 # path=path.rstrip("\\") # # 判断路径是否存在 # # 存在 True # # 不存在 False # isExists=os.path.exists(path) # # 判断结果 # if not isExists: # # 如果不存在则创建目录 # # 创建目录操作函数 # os.makedirs(path) # print(path+' 创建成功') # return True # else: # # 如果目录存在则不创建,并提示目录已存在 # print(path+' 目录已存在') # return False # def variance_of_laplacian(image): # # 拉普拉斯的方差 # return cv2.Laplacian(image, cv2.CV_64F).var() # imei = "865650043208251" # print('=================================================') # print("<-----imei:\n" + imei + ';\n') # print("Message:\n" + "http:bzyphoto" + "----->\n") # print("%s"%datetime.datetime.now()) # print('=================================================') # pic_name = datetime.datetime.now().strftime('%Y%m') # try: # pic_name = datetime.datetime.now().strftime('%Y%m') # args = "pyftp/ftp_file/bzy_test/" + imei # cv_num_list = [] # file_list1 = list(paths.list_images(args)) # print("\n===========================") # print("file_list1:",file_list1) # print("type file_list1:",type(file_list1)) # cv_num_list1 = [] # for imagePath1 in file_list1[::]: # # fm = get_value(imagePath) # # 孢子仪图片过小删除 # if os.path.getsize(imagePath1) <= 10: # file_list1.remove(imagePath1) # img1 = cv2.imread(imagePath1) # img1 = cv2.resize(img1, (800, 600)) # gray = cv2.cvtColor(img1, cv2.COLOR_BGR2GRAY) # # 创建SIFT对象 # sift = cv2.xfeatures2d.SIFT_create() # keypoints, descriptor = sift.detectAndCompute(gray, None) # img1 = cv2.drawKeypoints(image=img1, outImage=img1, keypoints=keypoints,flags=cv2.DRAW_MATCHES_FLAGS_DEFAULT, color=(0, 0, 255)) # fm1 = len(keypoints) # cv_num_list1.append(fm1) # # 打印清晰度值: # print("fm1",fm1) # # 打印文件路径 # print("imagePath1",imagePath1) # file_cv_tuple1 = tuple(zip(cv_num_list1,file_list1)) # print("file_cv_tuple1:\n",file_cv_tuple1) # print("=========================================/n") # file_cv_tuple_list1 = list(file_cv_tuple1) # print("file_cv_tuple_list1:\n",file_cv_tuple_list1) # print("*****************************************/n") # # 按照清晰度排序:, reverse=True降序 # result1 = sorted(file_cv_tuple_list1, key=lambda s: s[0],reverse=True) # print("result1:\n",result1) # # 切片取清晰度最高的前五张图片: # result1_5 = result1[0:3] # # result5 = result[0:1] # print("result1_5:\n",result1_5) # pic_name = datetime.datetime.now().strftime('%Y%m') # # 定义要创建的目录: # mkpath="./pyftp/ftp_file/bzy_photo/" + imei + "/" + pic_name # # 调用函数,创建目录: # mkdir(mkpath) # for i in result1_5: # # for i in result5: # #i值:(137.06453470539032, 'images\\192.168.2.64_01_20190802095315882_ALARM_INPUT.jpg') # print("file path:",i[1]) # #复制文件: # shutil.copy(i[1],mkpath) # # os.system("rm ./pyftp/ftp_file/bzy_test/%s/*.jpg -rf"%imei) # 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"))) # print("-----------------image move success----------------------") # equip = Equip.objects.get(equip_id=imei) # file_dir="pyftp/ftp_file/bzy_photo/" + imei + "/" + pic_name # for root, dirs, files in os.walk(file_dir): # print("当前目录为=========>>",root) #当前目录路径 # print("当前子目录为=========>>",dirs) #当前路径下所有子目录 # print("当前目录文件为=========>>",files) #当前路径下所有非目录子文件 # for i in files: # photo_addr = file_dir + "/" + i # print("文件夹图片路径===========》》",photo_addr) # if BZYphoto.objects.filter(addr=photo_addr).exists(): # print("照片存在") # else: # BZYphoto.objects.create(equip_id=equip, addr=photo_addr) # print("照片不存在") # except Exception as a: # print('=================================================') # print("<-----imei:\n" + imei + ';\n') # print("Message:\n" + "http:bzyphoto" + "----->\n") # print("%s"%datetime.datetime.now()) # print("==========%s========"%a) # print("-----------------image move default----------------------") # lat = "37.56" # lng = "115.28" # data = [] # data1 = [] # # res = requests.post("http://api.map.baidu.com/geocoder?location=%s,%s&coord_type=gcj02&output=json"%(lat,lng)) # # location = (eval(res.text))["result"]["addressComponent"]["province"]+eval(res.text)["result"]["addressComponent"]["district"] # # print(location) # # 大新县农业农村局 # # user_obj = MyUser.objects.get(username="大新县农业农村局") # for i in CBDstatus.objects.all().values(): # try: # lng = i["lng"] # lat = i["lat"] # except: # lng = "" # lat = "" # print("设备版本号",eval(i["cbd_status"])["dver"].split(".")[0]) # print("照片是否存在",CBDphoto.objects.filter(equip_id=i["equip_id_id"]).exists()) # if eval(i["cbd_status"])["dver"].split(".")[0] == "5" and CBDphoto.objects.filter(equip_id=i["equip_id_id"]).exists(): # 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}) # # print(data) # for x in data: # if x["lat"]: # res = requests.post("http://api.map.baidu.com/geocoder?location=%s,%s&coord_type=gcj02&output=json"%(x["lat"],x["lng"])) # try: # print(eval(res.text)) # print((eval(res.text))["result"]["addressComponent"]["province"]) # # print((eval(res.text))["result"]["formatted_address"]) # except: # continue # # if (eval(res.text))["result"]["addressComponent"]["province"] == "河南省": # location = (eval(res.text))["result"]["addressComponent"]["province"] + (eval(res.text))["result"]["addressComponent"]["city"] + (eval(res.text))["result"]["addressComponent"]["district"] # # location = (eval(res.text))["result"]["formatted_address"] # data1.append({"equip_id":x["equip_id"],"location":location,"is_online":x["is_online"],"off_time":x["off_time"],"creat_time":x["creat_time"]}) # # print(data1) # title = ["设备id","设备位置","是否在线","离线时间","设备创建时间"] # book = xlwt.Workbook() # 创建一个excel对象 # sheet = book.add_sheet('Sheet1',cell_overwrite_ok=True) # 添加一个sheet页 # for i in range(len(title)): # 遍历列 # # sheet.write(0,i,title[i],style) # 将title数组中的字段写入到0行i列中 # sheet.write(0,i,title[i]) # 将title数组中的字段写入到0行i列中 # # print(sta2) # for xx in range(len(data1)): # 遍历列表 # if data1[xx]['is_online'] == "0": # is_online = "离线" # off_time = datetime.datetime.strftime(data1[xx]['off_time'],'%Y-%m-%d') # else: # is_online = "在线" # off_time = "" # creat_time = datetime.datetime.strftime(data1[xx]['creat_time'],'%Y-%m-%d') # sheet.write(xx+1,0,data1[xx]['equip_id']) # 将equip_id写入到第x+1行,第0列中 # sheet.write(xx+1,1,data1[xx]['location']) # sheet.write(xx+1,2,is_online) # sheet.write(xx+1,3,off_time) # sheet.write(xx+1,4,creat_time) # book.save("654321.xlsx") # 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': '河北省承德县'}] # print(len(sta)) # imei = "D75675201" # file_dir = "../pyftp/ftp_file/jk_photo1/%s"%imei # print("file_dir",file_dir) # for root, dirs, files in os.walk(file_dir): # for i in files: # file = root + "/" + i # # st = root.split("/")[-1] + i.split(".")[0] # file = file[3:] # st = i.split(".")[3].split("_")[2][0:14] # print("st",st) # print("file====>>",file) # try: # pic_time = datetime.datetime.strptime(st,"%Y%m%d%H%M%S") # except Exception as eeex: # print("错误信息为",eeex) # continue # if JKphoto.objects.filter(addr=file).exists(): # photoobj = JKphoto.objects.get(addr=file) # photoobj.upl_time = pic_time # photoobj.save() # print("照片存在") # else: # print("照片不存在") # try: # imei_obj = Equip.objects.get(equip_id=imei) # JKphoto.objects.create(equip_id=imei_obj,addr=file,upl_time=pic_time) # except Exception as e: # print("错误信息为",e) # equip_obj = Equip.objects.get(equip_id=160648091112227) # equip_obj2 = QXZstatus_New.objects.get(equip_id=16064809) # conf_obj = QXZ_Conf.objects.get(equip_id=16064809) # conf_obj2 = QXZ_Default_Conf.objects.get(equip_id=16064809) # 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) # 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) # 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) # 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) # print("操作完毕") # print(QXZstatus_New.objects.get(equip_id_id=16064808).upl_time) # workbook = xlrd.open_workbook('物联网杀虫灯发货统计(2).xlsx') # print(workbook.sheet_names()) # sheet11 = workbook.sheet_by_name('11 月发货统计') # nro = sheet11.nrows # print(nro) # list_e = [] # user_obj = MyUser.objects.get(username="大新县农业农村局") # cell_a = sheet11.cell(0,2).value # 括号内第一位数字为行,第二位为列 # for i in range(146): # cell_a = sheet11.cell(i,2).value # # print(cell_a) # try: # equip_obj = Equip.objects.get(equip_id=cell_a) # equip_obj.equip_user = user_obj # equip_obj.save() # print("分配成功") # except: # print("设备不存在") # print(cell_a) # list_e.append(cell_a) # print(list_e) # list_e = [] # for i in CBDstatus.objects.all(): # is_hk = eval(i.cbd_status)["dver"] # # print(is_hk) # if "HK" in is_hk: # print(is_hk) # list_e.append(i) # # else: # # print("不是hk") # # print(list_e) # list_n = [] # for x in list_e: # # print(x.simid) # if x.simid: # print("===>>",x.equip_id_id) # equip_obj2 = RecentCBDdata.objects.get(equip_id_id=x.equip_id_id) # equip_obj = CBDstatus.objects.filter(equip_id_id=x.equip_id_id).update(upl_time=equip_obj2.upl_time) # print("操作成功") # else: # # print("为空的设备",x.equip_id_id) # # list_n.append(x.equip_id_id) # # x.simid = '12345678901234567890' # # x.save() # equip_obj2 = RecentCBDdata.objects.get(equip_id_id=x.equip_id_id) # equip_obj = CBDstatus.objects.filter(equip_id_id=x.equip_id_id).update(upl_time=equip_obj2.upl_time) # print("操作成功") # print(list_n) # equip_obj2 = RecentCBDdata.objects.get(equip_id_id=i) # equip_obj = CBDstatus.objects.filter(equip_id_id=i).update(upl_time=equip_obj2.upl_time) # e1 = '' # e2 = '' # e3 = '' # e4 = '' # e5 = '' # e6 = '' # e7 = '' # e8 = '' # e9 = '' # e10 = '' # e11 = '' # e12 = '' # e13 = '' # e14 = '' # e15 = '' # e16 = '' # e17 = '' # e18 = '' # e19 = '' # e20 = '' # e21 = '' # e22 = '' # e23 = '' # e24 = '' # e25 = '' # e26 = '' # e27 = '' # e28 = '' # e29 = '' # e30 = '' # conf1 = '' # conf2 = '' # conf3 = '' # conf4 = '' # conf5 = '' # conf6 = '' # conf7 = '' # conf8 = '' # conf9 = '' # conf10 = '' # conf11 = '' # conf12 = '' # conf13 = '' # conf14 = '' # conf15 = '' # conf16 = '' # conf17 = '' # conf18 = '' # conf19 = '' # conf20 = '' # conf21 = '' # conf22 = '' # conf23 = '' # conf24 = '' # conf25 = '' # conf26 = '' # conf27 = '' # conf28 = '' # conf29 = '' # conf30 = '' # for x in QXZstatus.objects.all(): # e_id = x.equip_id_id # upl_time = QXZstatus.objects.get(equip_id=e_id).upl_time # qxz_picture = QXZstatus.objects.get(equip_id=e_id).qxz_picture # qxzstatus = eval(QXZstatus.objects.get(equip_id=e_id).qxz_status)['data'] # for i in qxzstatus: # if i['eKey'] == 'e1': # e1 = i['eValue'] + '#' + i['eNum'] + '#' + i['eKey'] # conf1 = qxz_dict[i['eNum']][1] + '#' + qxz_dict[i['eNum']][2] # elif i['eKey'] == 'e2': # e2 = i['eValue'] + '#' + i['eNum'] + '#' + i['eKey'] # conf2 = qxz_dict[i['eNum']][1] + '#' + qxz_dict[i['eNum']][2] # elif i['eKey'] == 'e3': # e3 = i['eValue'] + '#' + i['eNum'] + '#' + i['eKey'] # conf3 = qxz_dict[i['eNum']][1] + '#' + qxz_dict[i['eNum']][2] # elif i['eKey'] == 'e4': # e4 = i['eValue'] + '#' + i['eNum'] + '#' + i['eKey'] # conf4 = qxz_dict[i['eNum']][1] + '#' + qxz_dict[i['eNum']][2] # elif i['eKey'] == 'e5': # e5 = i['eValue'] + '#' + i['eNum'] + '#' + i['eKey'] # conf5 = qxz_dict[i['eNum']][1] + '#' + qxz_dict[i['eNum']][2] # elif i['eKey'] == 'e6': # e6 = i['eValue'] + '#' + i['eNum'] + '#' + i['eKey'] # conf6 = qxz_dict[i['eNum']][1] + '#' + qxz_dict[i['eNum']][2] # elif i['eKey'] == 'e7': # e7 = i['eValue'] + '#' + i['eNum'] + '#' + i['eKey'] # conf7 = qxz_dict[i['eNum']][1] + '#' + qxz_dict[i['eNum']][2] # elif i['eKey'] == 'e8': # e8 = i['eValue'] + '#' + i['eNum'] + '#' + i['eKey'] # conf8 = qxz_dict[i['eNum']][1] + '#' + qxz_dict[i['eNum']][2] # elif i['eKey'] == 'e9': # e9 = i['eValue'] + '#' + i['eNum'] + '#' + i['eKey'] # conf9 = qxz_dict[i['eNum']][1] + '#' + qxz_dict[i['eNum']][2] # elif i['eKey'] == 'e10': # e10 = i['eValue'] + '#' + i['eNum'] + '#' + i['eKey'] # conf10 = qxz_dict[i['eNum']][1] + '#' + qxz_dict[i['eNum']][2] # elif i['eKey'] == 'e11': # e11 = i['eValue'] + '#' + i['eNum'] + '#' + i['eKey'] # conf11 = qxz_dict[i['eNum']][1] + '#' + qxz_dict[i['eNum']][2] # elif i['eKey'] == 'e12': # e12 = i['eValue'] + '#' + i['eNum'] + '#' + i['eKey'] # conf12 = qxz_dict[i['eNum']][1] + '#' + qxz_dict[i['eNum']][2] # elif i['eKey'] == 'e13': # e13 = i['eValue'] + '#' + i['eNum'] + '#' + i['eKey'] # conf13 = qxz_dict[i['eNum']][1] + '#' + qxz_dict[i['eNum']][2] # elif i['eKey'] == 'e14': # e14 = i['eValue'] + '#' + i['eNum'] + '#' + i['eKey'] # conf14 = qxz_dict[i['eNum']][1] + '#' + qxz_dict[i['eNum']][2] # elif i['eKey'] == 'e15': # e15 = i['eValue'] + '#' + i['eNum'] + '#' + i['eKey'] # conf15 = qxz_dict[i['eNum']][1] + '#' + qxz_dict[i['eNum']][2] # elif i['eKey'] == 'e16': # e16 = i['eValue'] + '#' + i['eNum'] + '#' + i['eKey'] # conf16 = qxz_dict[i['eNum']][1] + '#' + qxz_dict[i['eNum']][2] # elif i['eKey'] == 'e17': # e17 = i['eValue'] + '#' + i['eNum'] + '#' + i['eKey'] # conf17 = qxz_dict[i['eNum']][1] + '#' + qxz_dict[i['eNum']][2] # elif i['eKey'] == 'e18': # e18 = i['eValue'] + '#' + i['eNum'] + '#' + i['eKey'] # conf18 = qxz_dict[i['eNum']][1] + '#' + qxz_dict[i['eNum']][2] # elif i['eKey'] == 'e19': # e19 = i['eValue'] + '#' + i['eNum'] + '#' + i['eKey'] # conf19 = qxz_dict[i['eNum']][1] + '#' + qxz_dict[i['eNum']][2] # elif i['eKey'] == 'e20': # e20 = i['eValue'] + '#' + i['eNum'] + '#' + i['eKey'] # conf20 = qxz_dict[i['eNum']][1] + '#' + qxz_dict[i['eNum']][2] # elif i['eKey'] == 'e21': # e21 = i['eValue'] + '#' + i['eNum'] + '#' + i['eKey'] # conf21 = qxz_dict[i['eNum']][1] + '#' + qxz_dict[i['eNum']][2] # elif i['eKey'] == 'e22': # e22 = i['eValue'] + '#' + i['eNum'] + '#' + i['eKey'] # conf22 = qxz_dict[i['eNum']][1] + '#' + qxz_dict[i['eNum']][2] # elif i['eKey'] == 'e23': # e23 = i['eValue'] + '#' + i['eNum'] + '#' + i['eKey'] # conf23 = qxz_dict[i['eNum']][1] + '#' + qxz_dict[i['eNum']][2] # elif i['eKey'] == 'e24': # e24 = i['eValue'] + '#' + i['eNum'] + '#' + i['eKey'] # conf24 = qxz_dict[i['eNum']][1] + '#' + qxz_dict[i['eNum']][2] # elif i['eKey'] == 'e25': # e25 = i['eValue'] + '#' + i['eNum'] + '#' + i['eKey'] # conf25 = qxz_dict[i['eNum']][1] + '#' + qxz_dict[i['eNum']][2] # elif i['eKey'] == 'e26': # e26 = i['eValue'] + '#' + i['eNum'] + '#' + i['eKey'] # conf26 = qxz_dict[i['eNum']][1] + '#' + qxz_dict[i['eNum']][2] # elif i['eKey'] == 'e27': # e27 = i['eValue'] + '#' + i['eNum'] + '#' + i['eKey'] # conf27 = qxz_dict[i['eNum']][1] + '#' + qxz_dict[i['eNum']][2] # elif i['eKey'] == 'e28': # e28 = i['eValue'] + '#' + i['eNum'] + '#' + i['eKey'] # conf28 = qxz_dict[i['eNum']][1] + '#' + qxz_dict[i['eNum']][2] # elif i['eKey'] == 'e29': # e29 = i['eValue'] + '#' + i['eNum'] + '#' + i['eKey'] # conf29 = qxz_dict[i['eNum']][1] + '#' + qxz_dict[i['eNum']][2] # elif i['eKey'] == 'e30': # e30 = i['eValue'] + '#' + i['eNum'] + '#' + i['eKey'] # conf30 = qxz_dict[i['eNum']][1] + '#' + qxz_dict[i['eNum']][2] # if QXZstatus_New.objects.filter(equip_id=e_id).exists(): # print("------create default-------") # else: # QXZstatus_New.objects.create(equip_id_id=e_id, # e1=e1,e2=e2,e3=e3,e4=e4,e5=e5,e6=e6,e7=e7,e8=e8,e9=e9,e10=e10, # e11=e11,e12=e12,e13=e13,e14=e14,e15=e15,e16=e16,e17=e17,e18=e18,e19=e19,e20=e20, # e21=e21,e22=e22,e23=e23,e24=e24,e25=e25,e26=e26,e27=e27,e28=e28,e29=e29,e30=e30, # upl_time=upl_time,qxz_picture=qxz_picture) # print("------create success-------") # e1 = '' # e2 = '' # e3 = '' # e4 = '' # e5 = '' # e6 = '' # e7 = '' # e8 = '' # e9 = '' # e10 = '' # e11 = '' # e12 = '' # e13 = '' # e14 = '' # e15 = '' # e16 = '' # e17 = '' # e18 = '' # e19 = '' # e20 = '' # e21 = '' # e22 = '' # e23 = '' # e24 = '' # e25 = '' # e26 = '' # e27 = '' # e28 = '' # e29 = '' # e30 = '' # if QXZ_Conf.objects.filter(equip_id=e_id).exists(): # print("------conf create default-------") # else: # QXZ_Conf.objects.create(equip_id_id=e_id, # e1=conf1,e2=conf2,e3=conf3,e4=conf4,e5=conf5,e6=conf6,e7=conf7,e8=conf8,e9=conf9,e10=conf10, # e11=conf11,e12=conf12,e13=conf13,e14=conf14,e15=conf15,e16=conf16,e17=conf17,e18=conf18,e19=conf19,e20=conf20, # e21=conf21,e22=conf22,e23=conf23,e24=conf24,e25=conf25,e26=conf26,e27=conf27,e28=conf28,e29=conf29,e30=conf30) # QXZ_Default_Conf.objects.create(equip_id_id=e_id, # e1=conf1,e2=conf2,e3=conf3,e4=conf4,e5=conf5,e6=conf6,e7=conf7,e8=conf8,e9=conf9,e10=conf10, # e11=conf11,e12=conf12,e13=conf13,e14=conf14,e15=conf15,e16=conf16,e17=conf17,e18=conf18,e19=conf19,e20=conf20, # e21=conf21,e22=conf22,e23=conf23,e24=conf24,e25=conf25,e26=conf26,e27=conf27,e28=conf28,e29=conf29,e30=conf30) # print("------conf create success-------") # conf1 = '' # conf2 = '' # conf3 = '' # conf4 = '' # conf5 = '' # conf6 = '' # conf7 = '' # conf8 = '' # conf9 = '' # conf10 = '' # conf11 = '' # conf12 = '' # conf13 = '' # conf14 = '' # conf15 = '' # conf16 = '' # conf17 = '' # conf18 = '' # conf19 = '' # conf20 = '' # conf21 = '' # conf22 = '' # conf23 = '' # conf24 = '' # conf25 = '' # conf26 = '' # conf27 = '' # conf28 = '' # conf29 = '' # conf30 = '' # -------------------------------------------------------MQTT TEST------------------------------------- # import threading # def cbdthread(e_id): # i = 0 # TASK_TOPIC = '/yfkj/cbd/pub/%s'%e_id # 客户端发布消息主题 # client_id = time.strftime('%Y%m%d%H%M%S', time.localtime(time.time())) # client = mqtt.Client(client_id, transport='tcp') # client.connect("39.104.94.153", 1883, 60) # 此处端口默认为1883,通信端口期keepalive默认60 # client.loop_start() # # print("子线程名称输出",threading.currentThread().name) # """ # 客户端发布消息 # :param message: 消息主体 # :return: # """ # 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"}} # # publish(主题:Topic; 消息内容) # while True: # client.publish(TASK_TOPIC, json.dumps(payload, ensure_ascii=False)) # print("Successful send message!",e_id) # time.sleep(1) # print("=============",i) # i = i + 1 # e_id = 10000 # for i in range(10): # t = threading.Thread(target=cbdthread,args=(e_id,)) # #打印出当前线程的名称和id # # print(threading.currentThread().name) # # t.setDaemon(True) # t.start() # e_id = e_id + 1 # if e_id == 10009: # while True: # print("主线程名称输出",threading.currentThread().name) # thread_num = len(threading.enumerate()) # print("线程数量是%d" % thread_num) # time.sleep(1) # -------------------------------------------------------MQTT TEST------------------------------------- # print(type(os.path.getsize('F:\\1111.jpg'))) # msg_conf_list = Msg_Conf.objects.all() # for i in msg_conf_list: # cbd_obj = Equip.objects.get(equip_id=i.equip_id) # equip_name = "" # if cbd_obj.equip_name == "" or cbd_obj.equip_name == None: # equip_name = cbd_obj.equip_id # else: # equip_name = cbd_obj.equip_name # msgconf = eval(i.conf) # # 需要发送短信的手机号码 # phone_numbers = msgconf["phone"] # # 短信模板ID,需要在短信控制台中申请 # template_id = 431378 # NOTE: 这里的模板 ID`7839`只是示例,真实的模板 ID 需要在短信控制台中申请 # # 签名 # sms_sign = "云飞科技" # NOTE: 签名参数使用的是`签名内容`,而不是`签名ID`。这里的签名"腾讯云"只是示例,真实的签名需要在短信控制台中申请 # ssender = SmsSingleSender(appid, appkey) # params = ["","","由于入冬无虫子,暂时停止短信发送服务,将于明年三月份开启"] # 当模板没有参数时,`params = []` # try: # result = ssender.send_with_param(86, phone_numbers, # template_id, params, sign=sms_sign, extend="", ext="") # 签名参数未提供或者为空时,会使用默认签名发送短信 # except HTTPError as e: # print(e) # except Exception as e: # print(e) # print(result) # Msg_Send.objects.create(mobile=msgconf["phone"],equip_id=i.equip_id,send_dec=params,result_desc=result) # pest_name = [] # print("----发送成功",phone_numbers) # 账号有效期设置 # user_obj = MyUser.objects.all() # for i in user_obj: # if i.date_joined.year == 2019 and i.date_joined.month >= 10: # print(i.date_joined) # print(i.username) # i.expire_date = i.date_joined + datetime.timedelta(days=730) # i.save() # print("操作成功") # # 查看最近有虫子的测报灯 # one_month = datetime.timedelta(days=30) # now_time = datetime.datetime.now() # photo_list = CBDphoto.objects.all() # for i in photo_list: # if now_time - i.upl_time <= one_month and i.indentify_result: # print(i.equip_id_id) # book=xlrd.open_workbook('F:\\12.2河南云飞恢复续费.xlsx') # sheet=book.sheet_by_index(0) #根据sheet编号来 # # sheet=book.sheet_by_name('sheet1') #根据 sheet名称来 # # print(sheet.nrows) #excel里面有多少行 # # print(sheet.ncols) #excel里面有多少列 # # print(sheet.cell(0,0).value) #获取第0行第0列的值 # # print(sheet.row_values(0)) #获取到整行的内容 # # print(sheet.col_values(1)) #获取到整列的内容 # iccid_list = sheet.col_values(1) # for i in range(len(iccid_list)): # if i == 0: # continue # print(iccid_list[i]) # # print(iccid_list[i]) # # for i in range(sheet.nrows): #循环获取每行的内容 # # print(sheet.row_values(i)) # equip_list = Equip.objects.all() # for i in equip_list: # print(type(i.equip_type_id)) # datalist = RecentCBDdata.objects.all() # for i in datalist: # if i.discern == False: # i.disc = 1 # i.save() # elif i.discern == True: # i.disc = 0 # i.save() # print("数据导入完毕") # 判断测报灯流量卡充值停用账号 # simlist = Equip_SimInfo.objects.all() # for i in simlist: # dateTime_p = datetime.datetime.strptime(i.expiry_date,'%Y-%m-%d %H:%M:%S') # # 判断sim卡是否30天到期 # if dateTime_p - datetime.datetime.now() > datetime.timedelta(days=30): # pass # elif datetime.timedelta(days=0) > dateTime_p - datetime.datetime.now() > datetime.timedelta(days=0): # print("发送短信通知") # elif dateTime_p - datetime.datetime.now() < datetime.timedelta(days=0): # if i.equip_id.equip_type_id == 2: # print("杀虫灯") # # 判断杀虫灯状态30天内是否有数据 # if datetime.datetime.now() - SCDstatus.objects.get(equip_id=i.equip_id).upl_time > datetime.timedelta(days=30): # pass # else: # print("停用账号") # elif i.equip_id.equip_type_id == 3: # print("测报灯") # # 判断测报灯状态30天内是否有数据 # if datetime.datetime.now() - CBDstatus.objects.get(equip_id=i.equip_id).upl_time > datetime.timedelta(days=30): # pass # else: # print("停用账号") # end_date = datetime.datetime.now() # one_day = datetime.timedelta(days=1) # one_day_later = datetime.datetime.now() - one_day # print(one_day_later) # new_time = "%s-%s-%s %s:%s:%s" %(one_day_later.year,one_day_later.month,one_day_later.day,"19","00","00") # start_date = datetime.datetime.strptime(new_time,"%Y-%m-%d %H:%M:%S") # cbd_obj = Equip.objects.get(equip_id='86123456789') # equip_name = "" # if cbd_obj.equip_name == "" or cbd_obj.equip_name == None: # equip_name = cbd_obj.equip_id # else: # equip_name = cbd_obj.equip_name # msg_conf_list = Msg_Conf.objects.get(equip_id=cbd_obj) # msgconf = eval(msg_conf_list.conf) # if msgconf["appointPest"] == "on": # pest_num = 0 # pest_name = [] # pest_nums = [] # pest_dict = {} # pest_dict_new = {} # cbd_list = CBDphoto.objects.filter(equip_id=cbd_obj) # for x in cbd_list: # if x.indentify_result == None or x.indentify_result == "": # pass # else: # for a in x.indentify_result.split("#"): # pest_num = pest_num + int(a.split(",")[1]) # pest_name.append(int(a.split(",")[0])) # pest_nums.append(int(a.split(",")[1])) # for xx in range(len(pest_name)): # c = {pest_name[xx]:pest_nums[xx]} # for d in c: # if d in pest_dict: # pest_dict[d] = pest_dict[d] + c[d] # else: # pest_dict.update(c) # print(pest_dict) # send_dict = {} # print(msgconf["appointPestName"].split("#")) # print(msgconf["appointPestNum"].split("#")) # msg_name = msgconf["appointPestName"].split("#") # msg_num = msgconf["appointPestNum"].split("#") # for i in range(len(msg_name)): # if pest_dict[int(msg_name[i])] > int(msg_num[i]): # aaa = {insect_dict_new[msg_name[i]]:"%s头"%int(msg_num[i])} # send_dict.update(aaa) # print(send_dict) # if pest_dict[int(msgconf["appointPestName"])] >= int(msgconf["appointPestNum"]): # pass # pest_num = 0 # pest_name = [] # pest_nums = [] # pest_dict = {} # pest_dict_new = {} # equip_obj = Equip.objects.get(equip_id="868575028850321") # file_dir = "pyftp/ftp_file/bzy_photo/%s"%868575028850321 # print("file_dir",file_dir) # sta1 = BZYstatus.objects.all() # sta3 = [] # photo_list = [] # for i in sta1: # sta3.append(i.equip_id.equip_id) # for imei in sta3: # equip_obj = Equip.objects.get(equip_id=imei) # file_dir = "pyftp/ftp_file/bzy_photo/%s"%imei # # print("file_dir",file_dir) # for root, dirs, files in os.walk(file_dir): # # print("当前目录为=========>>",root) #当前目录路径 # # print("当前子目录为=========>>",dirs) #当前路径下所有子目录 # if root.endswith(imei): # pass # else: # # print("当前目录------->>",root) # for roots, dirss, file in os.walk(root): # # print(roots) #当前目录路径 # # print(dirs) #当前路径下所有子目录 # # print(file) #当前路径下所有非目录子文件 # if file != []: # for i in file: # photo_addr = roots + "/" + i # # print(photo_addr) # if BZYphoto.objects.filter(addr=photo_addr).exists(): # # print("照片存在") # # print(i[17:29]) # # print("-----") # # sp = datetime.datetime.now().year # # sp_str = i.split(str(sp))[1] # # # print(sp_str[0:8]) # # st = str(sp) + sp_str[0:8] # # print(st) # pass # else: # print("-----") # sp = datetime.datetime.now().year # sp_str = i.split(str(sp))[1] # # print(sp_str[0:8]) # st = str(sp) + sp_str[0:8] # # st = i[17:29] # # print(st) # pic_time = datetime.datetime.strptime(st,"%Y%m%d%H%M%S") # print(pic_time) # BZYphoto.objects.create(equip_id=equip_obj,addr=photo_addr,upl_time=pic_time) # sta1 = BZYstatus.objects.all() # sta3 = [] # photo_list = [] # for i in sta1: # sta3.append(i.equip_id.equip_id) # for imei in sta3: # equip_obj = Equip.objects.get(equip_id=imei) # file_dir = "pyftp/ftp_file/bzy_photo/%s"%imei # # print("file_dir",file_dir) # for root, dirs, files in os.walk(file_dir): # # print("当前目录为=========>>",root) #当前目录路径 # # print("当前子目录为=========>>",dirs) #当前路径下所有子目录 # if root.endswith(imei): # pass # else: # # print("当前目录------->>",root) # for roots, dirss, file in os.walk(root): # # print(roots) #当前目录路径 # # print(dirs) #当前路径下所有子目录 # # print(file) #当前路径下所有非目录子文件 # if file != []: # for i in file: # photo_addr = roots + "/" + i # # print(photo_addr) # if BZYphoto.objects.filter(addr=photo_addr).exists(): # print("照片存在") # print(i[16:34]) # else: # # os.path.getctime(photo_addr) # 输出文件的创建时间 # # print("文件创建时间",os.path.getctime(photo_addr)) # # timeStamp = os.path.getctime(photo_addr) # # timeArray = time.localtime(timeStamp) # # otherStyleTime = time.strftime("%Y-%m-%d %H:%M:%S", timeArray) # # print(otherStyleTime) # # BZYphoto.objects.create(equip_id=equip_obj,addr=photo_addr) # print("-----") # print("=========================") # # print(photo_list) # print("=========================") # sta1 = SCDstatus.objects.all() # sta2 = CBDstatus.objects.all() # # 获取设备列表中的SIM卡的iccid号码: # iccids = [] # # 获取设备的id: # equip_ids = [] # # 获取设备的名称: # equip_names = [] # # 遍历查询流量信息: # siminfos = [] # for i in sta1: # try: # iccid = eval(i.scd_status)['iccid'] # except: # iccid = "" # iccids.append(iccid) # equip_ids.append(str(i.equip_id)) # equip_names.append(str(i.equip_id.equip_name)) # for i in sta2: # try: # iccid = eval(i.cbd_status)['iccid'] # except: # iccid = "" # iccids.append(iccid) # equip_ids.append(str(i.equip_id)) # equip_names.append(str(i.equip_id.equip_name)) # print('all iccids :',iccids) # print('all equip_ids :',equip_ids) # print('all equip_names :',equip_names) # print('iccids :',iccids) # print('equip_ids :',equip_ids) # print('equip_names :',equip_names) # # 调用api查到的iccid号: # for i in range(len(iccids)): # if iccids[i] != "": # # print("------",i) # # print('iccids :',iccids[i]) # # print('equip_ids :',equip_ids[i]) # # print('equip_names :',equip_names[i]) # res = get_siminfo(iccids[i]) # sim_res = res.text.encode('utf-8').decode('unicode_escape') # if eval(sim_res)["code"] == 0: # timeStamp = eval(sim_res)["data"]["expiry_date"] # dateArray = datetime.datetime.utcfromtimestamp(timeStamp) # otherStyleTime = dateArray.strftime("%Y-%m-%d %H:%M:%S") # timeStamp1 = eval(sim_res)["data"]["active_date"] # dateArray1 = datetime.datetime.utcfromtimestamp(timeStamp1) # otherStyleTime1 = dateArray1.strftime("%Y-%m-%d %H:%M:%S") # if Equip_SimInfo.objects.filter(equip_id=equip_ids[i]).exists(): # siminfo_obj = Equip_SimInfo.objects.get(equip_id=equip_ids[i]) # siminfo_obj.equip_name = equip_names[i] # siminfo_obj.iccid = eval(sim_res)["data"]["iccid"] # siminfo_obj.msisdn = eval(sim_res)["data"]["msisdn"] # siminfo_obj.imsi = eval(sim_res)["data"]["imsi"] # siminfo_obj.sp_code = eval(sim_res)["data"]["sp_code"] # siminfo_obj.carrier = eval(sim_res)["data"]["carrier"] # siminfo_obj.data_plan = eval(sim_res)["data"]["data_plan"] # siminfo_obj.data_usage = eval(sim_res)["data"]["data_usage"] # siminfo_obj.account_status = eval(sim_res)["data"]["account_status"] # siminfo_obj.expiry_date = otherStyleTime # siminfo_obj.active = eval(sim_res)["data"]["active"] # siminfo_obj.test_valid_date = eval(sim_res)["data"]["test_valid_date"] # siminfo_obj.silent_valid_date = eval(sim_res)["data"]["silent_valid_date"] # siminfo_obj.test_used_data_usage = eval(sim_res)["data"]["test_used_data_usage"] # siminfo_obj.active_date = otherStyleTime1 # siminfo_obj.data_balance = eval(sim_res)["data"]["data_balance"] # siminfo_obj.outbound_date = eval(sim_res)["data"]["outbound_date"] # siminfo_obj.support_sms = eval(sim_res)["data"]["support_sms"] # siminfo_obj.upl_time = datetime.datetime.now() # siminfo_obj.save() # else: # Equip_SimInfo.objects.create( # equip_id = Equip.objects.get(equip_id=equip_ids[i]), # equip_name = equip_names[i], # iccid = eval(sim_res)["data"]["iccid"], # msisdn = eval(sim_res)["data"]["msisdn"], # imsi = eval(sim_res)["data"]["imsi"], # sp_code = eval(sim_res)["data"]["sp_code"], # carrier = eval(sim_res)["data"]["carrier"], # data_plan = eval(sim_res)["data"]["data_plan"], # data_usage = eval(sim_res)["data"]["data_usage"], # account_status = eval(sim_res)["data"]["account_status"], # expiry_date = otherStyleTime, # active = eval(sim_res)["data"]["active"], # test_valid_date = eval(sim_res)["data"]["test_valid_date"], # silent_valid_date = eval(sim_res)["data"]["silent_valid_date"], # test_used_data_usage = eval(sim_res)["data"]["test_used_data_usage"], # active_date = otherStyleTime1, # data_balance = eval(sim_res)["data"]["data_balance"], # outbound_date = eval(sim_res)["data"]["outbound_date"], # support_sms = eval(sim_res)["data"]["support_sms"] # ) # print("-----sim卡信息更新成功------") # 保存调用查询流量的api返回的数据; # dat = [] # for j in list(range(0,siminfo_dict['data']['count'])): # equip_iccids.append(siminfo_dict['data']['card_list'][j]['iccid']) # # print('equip_iccids:',equip_iccids) # for j in list(range(0,len(iccids))): # siminfo_dict=eval(siminfo_str) # if (iccids[j] in equip_iccids) == True: # dat.append(siminfo_dict['data']['card_list'][equip_iccids.index(iccids[j])]) # else: # dat.append({}) # dat[j]['equip_id']=equip_ids[j] # dat[j]['equip_name']=equip_names[j] # # print("dat[%d]=%s" %(j,dat[j])) # iccids[j] = ""# 每次判断玩将该值清空,防止多个设备用一个SIM卡测试时显示异常; # # print('----- iccids :',iccids) # print("------------------------",dat) # print("dat:",dat) # ----------------------------------测报灯图片存在与否判断----------------------------------- # sta1 = CBDstatus.objects.all() # sta3 = [] # photo_list = [] # for i in sta1: # sta3.append(i.equip_id.equip_id) # for imei in sta3: # file_dir = "pyftp/ftp_file/ykm_cbd/%s"%imei # # print("file_dir",file_dir) # for root, dirs, files in os.walk(file_dir): # # print("当前目录为=========>>",root) #当前目录路径 # # print("当前子目录为=========>>",dirs) #当前路径下所有子目录 # if root.endswith(imei): # pass # else: # # print("当前目录------->>",root) # for roots, dirss, file in os.walk(root): # # print(roots) #当前目录路径 # # print(dirs) #当前路径下所有子目录 # # print(file) #当前路径下所有非目录子文件 # if file != []: # for i in file: # photo_addr = roots + "/" + i # # print(photo_addr) # if CBDphoto.objects.filter(addr=photo_addr).exists(): # print("照片存在") # else: # photo_list.append(photo_addr) # print("=========================") # print(photo_list) # print("=========================") # ----------------------------------------------------------------------------------------------- # sta1 = BZYstatus.objects.all() # sta3 = [] # photo_list = [] # for i in sta1: # sta3.append(i.equip_id.equip_id) # for imei in sta3: # file_dir = "pyftp/ftp_file/ykm_cbd/%s"%imei # # print("file_dir",file_dir) # for root, dirs, files in os.walk(file_dir): # # print("当前目录为=========>>",root) #当前目录路径 # # print("当前子目录为=========>>",dirs) #当前路径下所有子目录 # if root.endswith(imei): # pass # else: # # print("当前目录------->>",root) # for roots, dirss, file in os.walk(root): # # print(roots) #当前目录路径 # # print(dirs) #当前路径下所有子目录 # # print(file) #当前路径下所有非目录子文件 # if file != []: # for i in file: # photo_addr = roots + "/" + i # # print(photo_addr) # if CBDphoto.objects.filter(addr=photo_addr).exists(): # print("照片存在") # else: # photo_list.append(photo_addr) # print("=========================") # print(photo_list) # print("=========================") # try: # path = "pyftp/ftp_file/ykm_cbd/%s"%imei # lsdir = os.listdir(path) # dirs = [i for i in lsdir if os.path.isdir(os.path.join(path, i))] # if dirs: # for i in dirs: # print_files(os.path.join(path, i)) # files = [i for i in lsdir if os.path.isfile(os.path.join(path,i))] # for f in files: # print(os.path.join(path, f)) # except Exception as e: # print("=================>>",e) # print("文件夹不存在") # file_dir = "pyftp/ftp_file/ykm_cbd/%s"%imei # print("file_dir",file_dir) # for root, dirs, files in os.walk(file_dir): # print(root) #当前目录路径 # print(dirs) #当前路径下所有子目录 # print(files) #当前路径下所有非目录子文件 # for i in files: # file = file_dir + "/" + i # jpg_time = time.ctime(os.path.getctime(file)) # print("jpg_time",jpg_time) # st = s_time+jpg_time[11:19] # print("-------------------",i.split(".")[0]) # pic_time_1 = s_time+i.split(".")[0] # pic_time_1 = datetime.datetime.strptime(pic_time_1,"%Y%m%d%H-%M-%S") # print("-------------------->",pic_time_1) # print("-------------------->",type(pic_time_1)) # pic_time = datetime.datetime.strptime(st,"%Y%m%d%H:%M:%S") # print("类型查看",type(pic_time)) # print("把字符串转成datetime: ", datetime.datetime.strptime(st,"%Y%m%d%H:%M:%S")) # if CBDphoto.objects.filter(addr=file).exists(): # photoobj = CBDphoto.objects.get(addr=file) # photoobj.upl_time = pic_time_1 # photoobj.save() # print("照片存在") # else: # print("照片不存在") # try: # imei_obj = Equip.objects.get(equip_id=imei) # CBDphoto.objects.create(equip_id=imei_obj,addr=file,upl_time=pic_time) # except Exception as e: # print("错误信息为",e) # a = 0 # qxz_obj = QXZdata.objects.filter(equip_id="16062023") # for i in qxz_obj: # a = a + 1 # i.delete() # print("----删除成功%s"%a) # ========================================================================================================= # equip_list = Equip.objects.all() # bbb = 0 # for i in equip_list: # photo_list = CBDphoto.objects.filter(equip_id=i.equip_id) # status_list = CBDdata.objects.filter(equip_id=i.equip_id) # for x in photo_list: # for a in status_list: # if x.at == None: # 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: # # print("数据时间==================>",a.upl_time) # # print("设备温度==================>",eval(a.cbd_data)["at"]) # # print("设备湿度==================>",eval(a.cbd_data)["ah"]) # # print("照片时间==================>",x.upl_time) # x.at = eval(a.cbd_data)["at"] # x.ah = eval(a.cbd_data)["ah"] # x.save() # bbb = bbb + 1 # print(bbb) # print("========操作成功=======") # ========================================================================================================= # file_dir="pyftp/ftp_file/bzy_photo/865650042816310/201909" # # print("file_dir",file_dir) # # bzy_obj = Equip.objects.get(equip_id=imei) # for root, dirs, files in os.walk(file_dir): # print("当前目录为=========>>",root) #当前目录路径 # print("当前子目录为=========>>",dirs) #当前路径下所有子目录 # print("当前目录文件为=========>>",files) #当前路径下所有非目录子文件 # for i in files: # photo_addr = file_dir + "/" + i # print("文件夹图片路径===========》》",photo_addr) # if BZYphoto.objects.filter(addr=photo_addr).exists(): # print("照片存在") # else: # print("照片不存在") # BZYphoto.objects.create(equip_id=bzy_obj,addr=photo_addr) # if root.endswith(imei): # pass # else: # # print("当前目录------->>",root) # for roots, dirss, file in os.walk(root): # # print(roots) #当前目录路径 # # print(dirs) #当前路径下所有子目录 # # print(file) #当前路径下所有非目录子文件 # if file != []: # for i in file: # photo_addr = roots + "/" + i # # print(photo_addr) # if BZYphoto.objects.filter(addr=photo_addr).exists(): # print("照片存在") # else: # BZYphoto.objects.create(equip_id=bzy_obj,addr=photo_addr) # ---------------------------丁艳青定制设备---------------------------------------------------------- # one_day = datetime.timedelta(days=1) # minut = datetime.timedelta(minutes=random.choice(range(20,34))) # start_time = '2019-07-29 19:00:08' # start_time = datetime.datetime.strptime(start_time,'%Y-%m-%d %H:%M:%S') # a = 1 # b = 1 # photo_list = CBDphoto.objects.filter(equip_id="865650040895753") # for i in photo_list: # i.upl_time = start_time + datetime.timedelta(days=b) + datetime.timedelta(minutes=random.choice(range(20,34))) * a # i.save() # a = a + 1 # print("修改次数",a) # if a == 5: # print("---跨天") # b = b + 1 # i.upl_time = start_time + datetime.timedelta(days=b) + datetime.timedelta(minutes=random.choice(range(20,34))) # i.save() # a = 0 # data_obj = RecentCBDdata.objects.get(equip_id="865650042837894") # print(eval(data_obj.cbd_data)['at']) # scd_list = RecentSCDdata.objects.all().values() # for i in scd_list: # try: # if eval(i['scd_data'])['lng'] == 0: # print(i['equip_id_id']) # except: # print("---报错设备号为:",i['equip_id_id']) # print("-----lng-------",eval(i['scd_data'])['lng'])