Files
2025-10-20 12:32:18 +08:00

11 KiB

In [2]:
import requests
In [45]:
proxies = {
    "http": f"http://192.168.0.185:7000",
    "https": "http://192.168.0.185:7000"
}

登入

In [3]:
# ip = "http://222.213.23.141:8099"
ip = "http://192.168.0.224:8086"#
# ip = "http://192.168.0.220:8086"
In [4]:
data = requests.post(f"{ip}/oauth/token",params={'username': 'zhongwei',
 'password': '123456a',
 'client_id': 'client',
 'grant_type': 'password',
 'client_secret': '123456'}).json()
token = data["access_token"]
print(data)
{'access_token': '3eb0763a-da4e-4137-bd0f-ef718a939c53', 'token_type': 'bearer', 'expires_in': 45017, 'scope': 'select'}
In [ ]:
import time
In [ ]:
dateTime = int(time.time()*1000)
In [ ]:
requests.get(f"{ip}/rtuinfo/seven_pest",params={'access_token':token,"projectId":1,"dateTime":dateTime}).json()
In [ ]:
requests.get(f"{ip}/rtu/monthlyStatistical?projectId=1",params={'access_token':token}).json()
In [ ]:
requests.get(f"{ip}/rtu/monthlyStatisticalTwo?projectId=1",params={'access_token':token}).json()
In [ ]:
requests.get("http://192.168.0.224:8086/rtuinfo/getFifteenData?access_token=e28ecad3-1403-4f3e-9942-a8d0653ef480&projectId=1").json()
In [ ]:
import datetime
start = datetime.datetime(2024,5,1)
end = datetime.datetime(2024,5,31)
start =int( start.timestamp()*1000)
end = int(end.timestamp()*1000)
In [ ]:
print(start,end)
In [3]:
requests.get(f"{ip}/plot/list ",params={"access_token":token,"start":start,"end":end,"pageNum":1,"pageSize":10}).json()
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
Cell In[3], line 1
----> 1 requests.get(f"{ip}/plot/list ",params={"access_token":token,"start":start,"end":end,"pageNum":1,"pageSize":10}).json()

NameError: name 'token' is not defined
In [23]:
params={"access_token":token,"start":start,"end":end,"pageNum":1,"pageSize":10}
In [24]:
print(params)
{'access_token': 'b2f719e7-380f-4479-b735-cbf380342a3a', 'start': 1714492800000, 'end': 1717084800000, 'pageNum': 1, 'pageSize': 10}
In [ ]:
requests.get(f"{ip}/weather/cityWeatherNow ",params=params).json()
In [55]:
imeis = requests.get(f"{ip}/facility/pageList",params={"projectId": 1,
"page": 1,
"currentPage": 1,
"pageSize": 15,
"access_token": token}).json()
In [56]:
tem = []
for item in imeis["data"]["records"]:
    tem.append(item["imei"])
In [57]:
tem
Out [57]:
['866250067096218',
 '866250067089106',
 '866250067109862',
 '866250067096168',
 '866250067110035',
 '866250067096408',
 '865328068117075',
 '866250067076822',
 '866250067088371',
 '865328068118180',
 '453543534']
In [15]:
cat = requests.get("https://api.thecatapi.com/v1/images/search?size=full").json()
In [16]:
cat[0]["url"]
Out [16]:
'https://cdn2.thecatapi.com/images/G-zFLupdX.jpg'
In [19]:
robot = requests.get("https://api.ownthink.com/bot?spoken=今天天气怎么样").json()
In [21]:
scentence = requests.get("https://api.xygeng.cn/one").json()
In [25]:
scentence["data"]["content"]
Out [25]:
'“我本可以忍受黑暗,如果我不曾见到阳光”'
In [49]:
import random
In [50]:
def animal():
    flag = random.randint(0,100)
    if flag%2 == 0:
        data = requests.get("https://api.thecatapi.com/v1/images/search?size=full").json()
    else:
        data = requests.get("https://api.thedogapi.com/v1/images/search?size=full").json()
    return data[0]["url"]

def scentence():
    data =  requests.get("https://api.xygeng.cn/one").json()
    return data["data"]["content"]
In [58]:
for i in range(0, 15):
    requests.post(
        f"{ip}/maintenance/submit",
        headers={
            "content-type": "application/json",
            "authorization": f"Bearer {token}",
        },
        json={
            "imei": random.sample(tem, 1)[0],
            "image": animal(),
            "projectId": 1,
            "reason": scentence(),
        },
    ).json()
In [48]:
requests.post(
    f"{ip}/maintenance/submit",
    headers={"content-type": "application/json", "authorization": f"Bearer {token}"},
    json={
        "imei": random.sample(tem, 1)[0],
        "image": cat[0]["url"],
        "projectId": 1,
        "reason": scentence["data"]["content"],
    },verify=False,
    proxies=proxies
)
Out [48]:
{'success': True,
 'msg': '操作成功',
 'code': 0,
 'data': {'id': 2,
  'imei': '866250067089106',
  'applyUser': 'zhongwei',
  'reason': '“我本可以忍受黑暗,如果我不曾见到阳光”',
  'status': 1,
  'createTime': '2024-08-27 14:38:51',
  'dealUser': None,
  'updateTime': None,
  'apply': None,
  'projectId': 1,
  'image': 'https://cdn2.thecatapi.com/images/G-zFLupdX.jpg'}}