Files
python----/农场.ipynb
T
2025-10-20 12:32:18 +08:00

434 lines
11 KiB
Plaintext

{
"cells": [
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"import requests"
]
},
{
"cell_type": "code",
"execution_count": 45,
"metadata": {},
"outputs": [],
"source": [
"proxies = {\n",
" \"http\": f\"http://192.168.0.185:7000\",\n",
" \"https\": \"http://192.168.0.185:7000\"\n",
"}"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
" ## 登入"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"# ip = \"http://222.213.23.141:8099\"\n",
"ip = \"http://192.168.0.224:8086\"#\n",
"# ip = \"http://192.168.0.220:8086\""
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"{'access_token': '3eb0763a-da4e-4137-bd0f-ef718a939c53', 'token_type': 'bearer', 'expires_in': 45017, 'scope': 'select'}\n"
]
}
],
"source": [
"data = requests.post(f\"{ip}/oauth/token\",params={'username': 'zhongwei',\n",
" 'password': '123456a',\n",
" 'client_id': 'client',\n",
" 'grant_type': 'password',\n",
" 'client_secret': '123456'}).json()\n",
"token = data[\"access_token\"]\n",
"print(data)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import time"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"dateTime = int(time.time()*1000)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"requests.get(f\"{ip}/rtuinfo/seven_pest\",params={'access_token':token,\"projectId\":1,\"dateTime\":dateTime}).json()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"requests.get(f\"{ip}/rtu/monthlyStatistical?projectId=1\",params={'access_token':token}).json()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"requests.get(f\"{ip}/rtu/monthlyStatisticalTwo?projectId=1\",params={'access_token':token}).json()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"requests.get(\"http://192.168.0.224:8086/rtuinfo/getFifteenData?access_token=e28ecad3-1403-4f3e-9942-a8d0653ef480&projectId=1\").json()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import datetime\n",
"start = datetime.datetime(2024,5,1)\n",
"end = datetime.datetime(2024,5,31)\n",
"start =int( start.timestamp()*1000)\n",
"end = int(end.timestamp()*1000)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"print(start,end)"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"ename": "NameError",
"evalue": "name 'token' is not defined",
"output_type": "error",
"traceback": [
"\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[1;31mNameError\u001b[0m Traceback (most recent call last)",
"Cell \u001b[1;32mIn[3], line 1\u001b[0m\n\u001b[1;32m----> 1\u001b[0m requests\u001b[38;5;241m.\u001b[39mget(\u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;132;01m{\u001b[39;00mip\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m/plot/list \u001b[39m\u001b[38;5;124m\"\u001b[39m,params\u001b[38;5;241m=\u001b[39m{\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124maccess_token\u001b[39m\u001b[38;5;124m\"\u001b[39m:token,\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mstart\u001b[39m\u001b[38;5;124m\"\u001b[39m:start,\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mend\u001b[39m\u001b[38;5;124m\"\u001b[39m:end,\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mpageNum\u001b[39m\u001b[38;5;124m\"\u001b[39m:\u001b[38;5;241m1\u001b[39m,\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mpageSize\u001b[39m\u001b[38;5;124m\"\u001b[39m:\u001b[38;5;241m10\u001b[39m})\u001b[38;5;241m.\u001b[39mjson()\n",
"\u001b[1;31mNameError\u001b[0m: name 'token' is not defined"
]
}
],
"source": [
"requests.get(f\"{ip}/plot/list \",params={\"access_token\":token,\"start\":start,\"end\":end,\"pageNum\":1,\"pageSize\":10}).json()"
]
},
{
"cell_type": "code",
"execution_count": 23,
"metadata": {},
"outputs": [],
"source": [
"params={\"access_token\":token,\"start\":start,\"end\":end,\"pageNum\":1,\"pageSize\":10}"
]
},
{
"cell_type": "code",
"execution_count": 24,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"{'access_token': 'b2f719e7-380f-4479-b735-cbf380342a3a', 'start': 1714492800000, 'end': 1717084800000, 'pageNum': 1, 'pageSize': 10}\n"
]
}
],
"source": [
"print(params)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"requests.get(f\"{ip}/weather/cityWeatherNow \",params=params).json()"
]
},
{
"cell_type": "code",
"execution_count": 55,
"metadata": {},
"outputs": [],
"source": [
"imeis = requests.get(f\"{ip}/facility/pageList\",params={\"projectId\": 1,\n",
"\"page\": 1,\n",
"\"currentPage\": 1,\n",
"\"pageSize\": 15,\n",
"\"access_token\": token}).json()"
]
},
{
"cell_type": "code",
"execution_count": 56,
"metadata": {},
"outputs": [],
"source": [
"tem = []\n",
"for item in imeis[\"data\"][\"records\"]:\n",
" tem.append(item[\"imei\"])"
]
},
{
"cell_type": "code",
"execution_count": 57,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"['866250067096218',\n",
" '866250067089106',\n",
" '866250067109862',\n",
" '866250067096168',\n",
" '866250067110035',\n",
" '866250067096408',\n",
" '865328068117075',\n",
" '866250067076822',\n",
" '866250067088371',\n",
" '865328068118180',\n",
" '453543534']"
]
},
"execution_count": 57,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"tem"
]
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {},
"outputs": [],
"source": [
"cat = requests.get(\"https://api.thecatapi.com/v1/images/search?size=full\").json()"
]
},
{
"cell_type": "code",
"execution_count": 16,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'https://cdn2.thecatapi.com/images/G-zFLupdX.jpg'"
]
},
"execution_count": 16,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"cat[0][\"url\"]"
]
},
{
"cell_type": "code",
"execution_count": 19,
"metadata": {},
"outputs": [],
"source": [
"robot = requests.get(\"https://api.ownthink.com/bot?spoken=今天天气怎么样\").json()"
]
},
{
"cell_type": "code",
"execution_count": 21,
"metadata": {},
"outputs": [],
"source": [
"scentence = requests.get(\"https://api.xygeng.cn/one\").json()"
]
},
{
"cell_type": "code",
"execution_count": 25,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'“我本可以忍受黑暗,如果我不曾见到阳光”'"
]
},
"execution_count": 25,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"scentence[\"data\"][\"content\"]"
]
},
{
"cell_type": "code",
"execution_count": 49,
"metadata": {},
"outputs": [],
"source": [
"import random"
]
},
{
"cell_type": "code",
"execution_count": 50,
"metadata": {},
"outputs": [],
"source": [
"def animal():\n",
" flag = random.randint(0,100)\n",
" if flag%2 == 0:\n",
" data = requests.get(\"https://api.thecatapi.com/v1/images/search?size=full\").json()\n",
" else:\n",
" data = requests.get(\"https://api.thedogapi.com/v1/images/search?size=full\").json()\n",
" return data[0][\"url\"]\n",
"\n",
"def scentence():\n",
" data = requests.get(\"https://api.xygeng.cn/one\").json()\n",
" return data[\"data\"][\"content\"]\n"
]
},
{
"cell_type": "code",
"execution_count": 58,
"metadata": {},
"outputs": [],
"source": [
"for i in range(0, 15):\n",
" requests.post(\n",
" f\"{ip}/maintenance/submit\",\n",
" headers={\n",
" \"content-type\": \"application/json\",\n",
" \"authorization\": f\"Bearer {token}\",\n",
" },\n",
" json={\n",
" \"imei\": random.sample(tem, 1)[0],\n",
" \"image\": animal(),\n",
" \"projectId\": 1,\n",
" \"reason\": scentence(),\n",
" },\n",
" ).json()"
]
},
{
"cell_type": "code",
"execution_count": 48,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{'success': True,\n",
" 'msg': '操作成功',\n",
" 'code': 0,\n",
" 'data': {'id': 2,\n",
" 'imei': '866250067089106',\n",
" 'applyUser': 'zhongwei',\n",
" 'reason': '“我本可以忍受黑暗,如果我不曾见到阳光”',\n",
" 'status': 1,\n",
" 'createTime': '2024-08-27 14:38:51',\n",
" 'dealUser': None,\n",
" 'updateTime': None,\n",
" 'apply': None,\n",
" 'projectId': 1,\n",
" 'image': 'https://cdn2.thecatapi.com/images/G-zFLupdX.jpg'}}"
]
},
"execution_count": 48,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"requests.post(\n",
" f\"{ip}/maintenance/submit\",\n",
" headers={\"content-type\": \"application/json\", \"authorization\": f\"Bearer {token}\"},\n",
" json={\n",
" \"imei\": random.sample(tem, 1)[0],\n",
" \"image\": cat[0][\"url\"],\n",
" \"projectId\": 1,\n",
" \"reason\": scentence[\"data\"][\"content\"],\n",
" },verify=False,\n",
" proxies=proxies\n",
")"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "base",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.4"
}
},
"nbformat": 4,
"nbformat_minor": 2
}