PriceForecast/测试环境获取市场信息平台数据项.ipynb

303 lines
214 KiB
Plaintext
Raw Normal View History

2024-12-25 16:13:22 +08:00
{
"cells": [
{
"cell_type": "code",
2024-12-27 14:15:20 +08:00
"execution_count": 1,
2024-12-25 16:13:22 +08:00
"id": "31c0e11d-c87a-4e95-92a0-d1d09625e255",
"metadata": {},
2024-12-27 14:15:20 +08:00
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"数据库连接成功 192.168.101.27 jingbo_test root\n"
]
}
],
2024-12-25 16:13:22 +08:00
"source": [
"from config_jingbo import *\n",
"import requests\n",
"import json\n",
"import datetime"
]
},
{
"cell_type": "code",
2024-12-27 14:15:20 +08:00
"execution_count": 2,
2024-12-25 16:13:22 +08:00
"id": "83c81b9e",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'http://192.168.100.53:8080/jingbo-dev/api/server/login'"
]
},
2024-12-27 14:15:20 +08:00
"execution_count": 2,
2024-12-25 16:13:22 +08:00
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"login_pushreport_url\n"
]
},
{
"cell_type": "code",
"execution_count": 12,
2024-12-25 16:13:22 +08:00
"id": "a058f507",
"metadata": {},
"outputs": [],
2024-12-27 14:15:20 +08:00
"source": [
"# login_pushreport_url = \"http://10.200.32.39/jingbo-api/api/server/login\"\n",
"# upload_url = \"http://10.200.32.39/jingbo-api/api/analysis/reportInfo/researchUploadReportSave\"\n",
"# upload_warning_url = \"http://10.200.32.39/jingbo-api/api/basicBuiness/crudeOilWarning/save\"\n",
"# query_data_list_item_nos_url = \"http://10.200.32.39/jingbo-api/api/warehouse/dwDataItem/queryDataListItemNos\"\n",
2024-12-27 14:15:20 +08:00
"\n",
"# login_data = {\n",
"# \"data\": {\n",
"# \"account\": \"api_dev\",\n",
"# \"password\": \"ZTEwYWRjMzk0OWJhNTlhYmJlNTZlMDU3ZjIwZjg4M2U=\",\n",
"# \"tenantHashCode\": \"8a4577dbd919675758d57999a1e891fe\",\n",
"# \"terminal\": \"API\"\n",
"# },\n",
"# \"funcModule\": \"API\",\n",
"# \"funcOperation\": \"获取token\"\n",
"# }"
2024-12-27 14:15:20 +08:00
]
},
{
"cell_type": "code",
"execution_count": 13,
2024-12-27 14:15:20 +08:00
"id": "8af0311d",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'http://10.200.32.39/jingbo-api/api/server/login'"
]
},
"execution_count": 13,
2024-12-27 14:15:20 +08:00
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"login_pushreport_url"
]
2024-12-25 16:13:22 +08:00
},
{
"cell_type": "code",
"execution_count": 14,
2024-12-25 16:13:22 +08:00
"id": "2b330ee3-c006-4ab1-8558-59c51ac8d86f",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
2024-12-27 14:15:20 +08:00
"{'data': {'account': 'api_dev',\n",
2024-12-25 16:13:22 +08:00
" 'password': 'ZTEwYWRjMzk0OWJhNTlhYmJlNTZlMDU3ZjIwZjg4M2U=',\n",
" 'tenantHashCode': '8a4577dbd919675758d57999a1e891fe',\n",
" 'terminal': 'API'},\n",
" 'funcModule': 'API',\n",
" 'funcOperation': '获取token'}"
]
},
"execution_count": 14,
2024-12-25 16:13:22 +08:00
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"login_data"
]
},
{
"cell_type": "code",
"execution_count": 15,
2024-12-25 16:13:22 +08:00
"id": "dcb6100a-ed2b-4077-a1a9-361c6cb565f9",
"metadata": {},
"outputs": [],
"source": [
"\n",
"def get_head_auth_report():\n",
" login_res = requests.post(url=login_pushreport_url, json=login_data, timeout=(3, 5))\n",
" text = json.loads(login_res.text)\n",
" print(text)\n",
" if text[\"status\"]:\n",
" token = text[\"data\"][\"accessToken\"]\n",
" return token\n"
]
},
{
"cell_type": "code",
"execution_count": 16,
2024-12-25 16:13:22 +08:00
"id": "22c0c7c4",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"{'confirmFlg': False, 'data': {'accessToken': 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJhcGlfZGV2IiwidGgiOiI4YTQ1NzdkYmQ5MTk2NzU3NThkNTc5OTlhMWU4OTFmZSIsImx0IjoiYXBpIiwiaXNzIjoiIiwidG0iOiJQQyIsImV4cCI6MTczNTMxNjAyMywianRpIjoiYjRhYTcxMWI2OTQxNDk3MjkzMWY2MDM2MDg1YWQ1NTIifQ.LP01YpDRKIqnc8Xw9Dzhy7rTV8qgcX5J-0MSlGMFGEo', 'md5Token': 'b3d0f00333a7b1e10844dcd84262326c'}, 'status': True}\n"
2024-12-25 16:13:22 +08:00
]
}
],
"source": [
"token = get_head_auth_report()"
]
},
{
"cell_type": "code",
2024-12-27 14:15:20 +08:00
"execution_count": 8,
2024-12-25 16:13:22 +08:00
"id": "12077ead",
"metadata": {},
"outputs": [],
"source": [
"# token = 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJhcGlfdGVzdCIsInRoIjoiOGE0NTc3ZGJkOTE5Njc1NzU4ZDU3OTk5YTFlODkxZmUiLCJsdCI6ImFwaSIsImlzcyI6IiIsInRtIjoiUEMiLCJleHAiOjE3MzE5NTkzNjUsImp0aSI6IjRiMjcwNTgzN2YyZDQxOWM4MzQ3NjI2NDQwZDlhZGQzIn0.PPgnoiJt412dJiceqVW8w7qkJFY4s-VqU9z6ZIkpqho'"
]
},
{
"cell_type": "code",
2024-12-27 14:15:20 +08:00
"execution_count": 9,
2024-12-25 16:13:22 +08:00
"id": "a7ae21d1",
"metadata": {},
"outputs": [],
"source": [
"# def upload_warning_data(warning_data):\n",
"# token = get_head_auth_report()\n",
"# warning_data = warning_data\n",
"# headers = {\"Authorization\": token}\n",
"# logger.info(\"预警上传中...\")\n",
"# logger.info(f\"token:{token}\")\n",
"# logger.info(f\"warning_data:{warning_data}\" )\n",
"# upload_res = requests.post(url=upload_warning_url, headers=headers, json=warning_data, timeout=(3, 15))\n",
"# if upload_res:\n",
"# return upload_res\n",
"# else:\n",
"# logger.info(\"预警上传失败\")\n",
"# return None\n",
"\n",
"\n",
"# logger.info(f'上传预警信息')\n",
"# try:\n",
"# warning_date = datetime.datetime.now().strftime('%Y-%m-%d')\n",
"# content = f'{warning_date}有2887个停更'\n",
"# warning_data['data']['WARNING_DATE'] = warning_date\n",
"# warning_data['data']['WARNING_CONTENT'] = content\n",
"# upload_warning_data(warning_data)\n",
"# logger.info(f'上传预警信息成功')\n",
"# except Exception as e:\n",
"# logger.error(f'上传预警信息失败:{e}')"
]
},
{
"cell_type": "code",
"execution_count": 17,
2024-12-25 16:13:22 +08:00
"id": "54942e1a",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"{\"confirmFlg\":false,\"data\":[{\"dataDate\":\"20240709\",\"dataItemNo\":\"Brentzdj\",\"dataValue\":84.53000000},{\"dataDate\":\"20241224\",\"dataItemNo\":\"Brentzdj\",\"dataValue\":72.46000000},{\"dataDate\":\"20200102\",\"dataItemNo\":\"Brentzdj\",\"dataValue\":65.72000000},{\"dataDate\":\"20200103\",\"dataItemNo\":\"Brentzdj\",\"dataValue\":66.22000000},{\"dataDate\":\"20200106\",\"dataItemNo\":\"Brentzdj\",\"dataValue\":68.21000000},{\"dataDate\":\"20200107\",\"dataItemNo\":\"Brentzdj\",\"dataValue\":67.65000000},{\"dataDate\":\"20200108\",\"dataItemNo\":\"Brentzdj\",\"dataValue\":64.94000000},{\"dataDate\":\"20200109\",\"dataItemNo\":\"Brentzdj\",\"dataValue\":64.56000000},{\"dataDate\":\"20200110\",\"dataItemNo\":\"Brentzdj\",\"dataValue\":64.86000000},{\"dataDate\":\"20200113\",\"dataItemNo\":\"Brentzdj\",\"dataValue\":63.92000000},{\"dataDate\":\"20200114\",\"dataItemNo\":\"Brentzdj\",\"dataValue\":63.92000000},{\"dataDate\":\"20200115\",\"dataItemNo\":\"Brentzdj\",\"dataValue\":63.55000000},{\"dataDate\":\"20200116\",\"dataItemNo\":\"Brentzdj\",\"dataValue\":63.90000000},{\"dataDate\":\"20200117\",\"dataItemNo\":\"Brentzdj\",\"dataValue\":64.48000000},{\"dataDate\":\"20200120\",\"dataItemNo\":\"Brentzdj\",\"dataValue\":64.92000000},{\"dataDate\":\"20200121\",\"dataItemNo\":\"Brentzdj\",\"dataValue\":63.25000000},{\"dataDate\":\"20200122\",\"dataItemNo\":\"Brentzdj\",\"dataValue\":61.86000000},{\"dataDate\":\"20200123\",\"dataItemNo\":\"Brentzdj\",\"dataValue\":60.54000000},{\"dataDate\":\"20200124\",\"dataItemNo\":\"Brentzdj\",\"dataValue\":59.48000000},{\"dataDate\":\"20200127\",\"dataItemNo\":\"Brentzdj\",\"dataValue\":57.74000000},{\"dataDate\":\"20200128\",\"dataItemNo\":\"Brentzdj\",\"dataValue\":57.90000000},{\"dataDate\":\"20200129\",\"dataItemNo\":\"Brentzdj\",\"dataValue\":58.38000000},{\"dataDate\":\"20200130\",\"dataItemNo\":\"Brentzdj\",\"dataValue\":56.74000000},{\"dataDate\":\"20200131\",\"dataItemNo\":\"Brentzdj\",\"dataValue\":55.93000000},{\"dataDate\":\"20200203\",\"dataItemNo\":\"Brentzdj\",\"dataValue\":54.08000000},{\"dataDate\":\"20200204\",\"dataItemNo\":\"Brentzdj\",\"dataValue\":53.69000000},{\"dataDate\":\"20200205\",\"dataItemNo\":\"Brentzdj\",\"dataValue\":54.05000000},{\"dataDate\":\"20200206\",\"dataItemNo\":\"Brentzdj\",\"dataValue\":54.25000000},{\"dataDate\":\"20200207\",\"dataItemNo\":\"Brentzdj\",\"dataValue\":54.21000000},{\"dataDate\":\"20200210\",\"dataItemNo\":\"Brentzdj\",\"dataValue\":53.11000000},{\"dataDate\":\"20200211\",\"dataItemNo\":\"Brentzdj\",\"dataValue\":53.60000000},{\"dataDate\":\"20200212\",\"dataItemNo\":\"Brentzdj\",\"dataValue\":54.39000000},{\"dataDate\":\"20200213\",\"dataItemNo\":\"Brentzdj\",\"dataValue\":54.96000000},{\"dataDate\":\"20200214\",\"dataItemNo\":\"Brentzdj\",\"dataValue\":56.15000000},{\"dataDate\":\"20200217\",\"dataItemNo\":\"Brentzdj\",\"dataValue\":56.74000000},{\"dataDate\":\"20200218\",\"dataItemNo\":\"Brentzdj\",\"dataValue\":56.16000000},{\"dataDate\":\"20200219\",\"dataItemNo\":\"Brentzdj\",\"dataValue\":57.24000000},{\"dataDate\":\"20200220\",\"dataItemNo\":\"Brentzdj\",\"dataValue\":58.47000000},{\"dataDate\":\"20200221\",\"dataItemNo\":\"Brentzdj\",\"dataValue\":57.23000000},{\"dataDate\":\"20200224\",\"dataItemNo\":\"Brentzdj\",\"dataValue\":54.60000000},{\"dataDate\":\"20200225\",\"dataItemNo\":\"Brentzdj\",\"dataValue\":53.94000000},{\"dataDate\":\"20200226\",\"dataItemNo\":\"Brentzdj\",\"dataValue\":52.39000000},{\"dataDate\":\"20200227\",\"dataItemNo\":\"Brentzdj\",\"dataValue\":50.39000000},{\"dataDate\":\"20200228\",\"dataItemNo\":\"Brentzdj\",\"dataValue\":48.94000000},{\"dataDate\":\"20200302\",\"dataItemNo\":\"Brentzdj\",\"dataValue\":48.40000000},{\"dataDate\":\"20200303\",\"dataItemNo\":\"Brentzdj\",\"dataValue\":51.22000000},{\"dataDate\":\"20200304\",\"dataItemNo\":\"Brentzdj\",\"dataValue\":51.04000000},{\"dataDate\":\"20200305\",\"dataItemNo\":\"Brentzdj\",\"dataValue\":49.70000000},{\"dataDate\":\"20200306\",\"dataItemNo\":\"Brentzdj\",\"dataValue\":45.18000000},{\"dataDate\":\"20200309\",\"dataItemN
2024-12-25 16:13:22 +08:00
]
}
],
"source": [
"query_data_list_item_nos_data = {\n",
" \"funcModule\": \"数据项\",\n",
" \"funcOperation\": \"查询\",\n",
" \"data\": {\n",
" \"dateStart\":\"20200101\",\n",
" \"dateEnd\":\"20241231\",\n",
" \"dataItemNoList\":[\"Brentzdj\",\"Brentzgj\"]\n",
" }\n",
2024-12-25 16:13:22 +08:00
"}\n",
"\n",
"headers = {\"Authorization\": token}\n",
"items_res = requests.post(url=query_data_list_item_nos_url, headers=headers, json=query_data_list_item_nos_data, timeout=(3, 35))\n",
"print(items_res.text)"
]
},
{
"cell_type": "code",
"execution_count": 18,
"id": "5272c84b",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" dataDate Brentzdj Brentzgj\n",
"0 20240709 84.53 NaN\n",
"1 20241224 72.46 NaN\n",
"2 20200102 65.72 NaN\n",
"3 20200103 66.22 NaN\n",
"4 20200106 68.21 NaN\n",
"... ... ... ...\n",
"2563 20240814 NaN 81.44\n",
"2564 20240806 NaN 77.85\n",
"2565 20240807 NaN 78.87\n",
"2566 20240808 NaN 79.37\n",
"2567 20240426 NaN 88.64\n",
"\n",
"[2568 rows x 3 columns]\n"
]
}
],
"source": [
"# 遍历items.text 获取data ,整理成 ds itemno value 的形式\n",
"import json\n",
"import pandas as pd\n",
"json_data = json.loads(items_res.text)\n",
"df = pd.DataFrame(json_data['data'])\n",
"# 按照dataItemNo 分组 得到多个dataframe 最后根据dataDate merge 成一个dataframe\n",
"df2 = pd.DataFrame()\n",
"for i in df['dataItemNo'].unique():\n",
" df1 = df[df['dataItemNo'] == i]\n",
" df1 = df1[['dataDate', 'dataValue']]\n",
" df1 = df1.rename(columns={'dataValue': i})\n",
" df2 = pd.concat([df2, df1], axis=0)\n",
"print(df2)\n",
"\n",
"\n",
"\n",
"df2.to_csv('data.csv')"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "2b1de00f",
"metadata": {},
"outputs": [],
"source": []
2024-12-25 16:13:22 +08:00
}
],
"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.11.7"
}
},
"nbformat": 4,
"nbformat_minor": 5
}