| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182 |
- 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
- 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 = {
- "861551056086614"
- }
- 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
- # 指定集合
- collection1 = db.sa_qxz_data
- for i in qx_device:
- data = {'device_id': i,'uptime':{'$gt':1697951100}}
- cursor = collection1.find(data,{'_id':0,'id':0})
- print(cursor.count(), "-----------", i)
- for i in cursor:
- qx_data = QXZdata_New.objects.create(
- device_id = i['device_id'],
- uptime = i['uptime'],
- e1 = i['e1'],
- e2 = i['e2'],
- e3 = i['e3'],
- e4 = i['e4'],
- e5 = i['e5'],
- e6 = i['e6'],
- e7 = i['e7'],
- e8 = i['e8'],
- e9 = i['e9'],
- e10 = i['e10'],
- e11 = i['e11'],
- e12 = i['e12'],
- e13 = i['e13'],
- e14 = i['e14'],
- e15 = i['e15'],
- e16 = i['e16'],
- e17 = i['e17'],
- e18 = i['e18'],
- e19 = i['e19'],
- e20 = i['e20'],
- e21 = i['e21'],
- e22 = i['e22'],
- e23 = i['e23'],
- e24 = i['e24'],
- e25 = i['e25'],
- e26 = i['e26'],
- e27 = i['e27'],
- e28 = i['e28'],
- e29 = i['e29'],
- e30 = i['e30']
- )
-
- return True
- if __name__ == "__main__":
- dsj_qxz_conf_info()
|