
import json
import requests
import pymongo
from urllib import parse


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))
db = myclient.smartfarming
device_id = "864865060481331"
device_config = db.sa_qxz_conf.find_one({"device_id": device_id}, {'_id':0,'id':0})
device_data = db.sa_qxz_data.find({"device_id": device_id, "uptime": {"$gte": 1689993000, "$lte": 1690008300}})
idevice_key = ""
device_config = dict(device_config)
for iname, ivalue in device_config.items():
    if ivalue and isinstance(ivalue, str):
        if "日照时数" in ivalue:
            idevice_key = iname
idevice_data = []
for d in device_data:
    idevice_data.append(float((d.get(idevice_key)).split("#")[0]))
print(idevice_data)