qx_default_conf.py 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. import os
  2. import sys
  3. import time
  4. import django
  5. local_path = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
  6. print(local_path)
  7. if local_path not in sys.path:
  8. sys.path.append(local_path)
  9. os.environ.setdefault("DJANGO_SETTINGS_MODULE", "kedong.settings")
  10. django.setup()
  11. from django.conf import settings
  12. from smartfarming.models.device import MongoDevice
  13. from smartfarming.models.weather import QXZdata_New, QXZ_Default_Conf
  14. import json
  15. import requests
  16. import pymongo
  17. from urllib import parse
  18. my_client = pymongo.MongoClient(host="8.136.98.49", port=27017, username="root", password="yfkj@6020")
  19. my_col = my_client['smartfarming']['sa_device']
  20. qx_device = {
  21. "861551055315402",
  22. "861551056086671",
  23. "861551056088693",
  24. "861551056088479",
  25. "861551056088719",
  26. "861551055313365",
  27. "861551056086614",
  28. "861551056093800",
  29. "861551056095367",
  30. "861551056102502",
  31. "861551056096621",
  32. "861551056101785",
  33. "861551056086549",
  34. "861551055354120",
  35. "861551055353536",
  36. "861551056092018",
  37. "861551055319586",
  38. "861551056088875",
  39. "861551055324651",
  40. "861551055313423"
  41. }
  42. def dsj_qxz_conf_info():
  43. user = parse.quote_plus("root")
  44. passwd = parse.quote_plus("yfkj@6020")
  45. # 账号密码方式连接MongoDB | "mongodb://用户名:密码@公网ip:端口/"
  46. myclient = pymongo.MongoClient("mongodb://{0}:{1}@8.136.98.49:57017/".format(user,passwd))
  47. # myclient = pymongo.MongoClient("mongodb://127.0.0.1:12514/")
  48. # 指定数据库
  49. db = myclient.smartfarming
  50. # 指定集合
  51. collection = db.sa_device
  52. collection1 = db.sa_qxz_conf
  53. for k in qx_device:
  54. data = {'device_id': k}
  55. cursor = collection1.find(data,{'_id':0,'id':0})
  56. for i in cursor:
  57. qx_data = QXZ_Default_Conf.objects.create(
  58. device_id = i['device_id'],
  59. uptime = i['uptime'],
  60. e1 = i['e1'],
  61. e2 = i['e2'],
  62. e3 = i['e3'],
  63. e4 = i['e4'],
  64. e5 = i['e5'],
  65. e6 = i['e6'],
  66. e7 = i['e7'],
  67. e8 = i['e8'],
  68. e9 = i['e9'],
  69. e10 = i['e10'],
  70. e11 = i['e11'],
  71. e12 = i['e12'],
  72. e13 = i['e13'],
  73. e14 = i['e14'],
  74. e15 = i['e15'],
  75. e16 = i['e16'],
  76. e17 = i['e17'],
  77. e18 = i['e18'],
  78. e19 = i['e19'],
  79. e20 = i['e20'],
  80. e21 = i['e21'],
  81. e22 = i['e22'],
  82. e23 = i['e23'],
  83. e24 = i['e24'],
  84. e25 = i['e25'],
  85. e26 = i['e26'],
  86. e27 = i['e27'],
  87. e28 = i['e28'],
  88. e29 = i['e29'],
  89. e30 = i['e30']
  90. )
  91. print(f"设备: {k} 数据量 {cursor.count()}")
  92. return True
  93. if __name__ == "__main__":
  94. dsj_qxz_conf_info()