| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- import os
- import sys
- import time
- import django
- local_path = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
- print(local_path)
- if local_path not in sys.path:
- sys.path.append(local_path)
- os.environ.setdefault("DJANGO_SETTINGS_MODULE", "kedong.settings")
- django.setup()
- from django.conf import settings
- from smartfarming.models.device import MongoDevice
- from smartfarming.models.weather import QXZdata_New, MongoQXZ_Base_Info
- import json
- import requests
- import pymongo
- from urllib import parse
- my_client = pymongo.MongoClient(host="8.136.98.49", port=27017, username="root", password="yfkj@6020")
- my_col = my_client['smartfarming']['sa_device']
- qx_device = {
- "861551055315402",
- "861551056086671",
- "861551056088693",
- "861551056088479",
- "861551056088719",
- "861551055313365",
- "861551056086614",
- "861551056093800",
- "861551056095367",
- "861551056102502",
- "861551056096621",
- "861551056101785",
- "861551056086549",
- "861551055354120",
- "861551055353536",
- "861551056092018",
- "861551055319586",
- "861551056088875",
- "861551055324651",
- "861551055313423"
- }
- def dsj_qxz_conf_info():
- user = parse.quote_plus("root")
- passwd = parse.quote_plus("yfkj@6020")
- # 账号密码方式连接MongoDB | "mongodb://用户名:密码@公网ip:端口/"
- myclient = pymongo.MongoClient("mongodb://{0}:{1}@8.136.98.49:57017/".format(user,passwd))
- # myclient = pymongo.MongoClient("mongodb://127.0.0.1:12514/")
- # 指定数据库
- db = myclient.smartfarming
- # 指定集合
- collection = db.sa_device
- collection1 = db.sa_qxz_base_info
- for k in qx_device:
- data = {'device_id': k}
- cursor = collection1.find(data,{'_id':0,'id':0})
- for i in cursor:
- qx_data, is_created = MongoQXZ_Base_Info.objects.get_or_create(
- device_id = i.get("device_id"),
- defaults={
- "volt": i.get("volt"),
- "rssi": i.get("rssi"),
- "iccid": i.get("iccid"),
- "lng": i.get("lng"),
- "lat": i.get("lat"),
- "led": i.get("led"),
- "ledinfo": i.get("ledinfo"),
- "dver": i.get("dver"),
- "uptime": i.get("uptime")
- }
- )
- print(f"设备: {k} 数据量 {cursor.count()} {qx_data.id, is_created} ")
- return True
- if __name__ == "__main__":
- dsj_qxz_conf_info()
|