diff --git a/aisenzhecode/沥青/定性模型数据项12-11.xlsx b/aisenzhecode/沥青/定性模型数据项12-11.xlsx index a60327d..05e1d28 100644 Binary files a/aisenzhecode/沥青/定性模型数据项12-11.xlsx and b/aisenzhecode/沥青/定性模型数据项12-11.xlsx differ diff --git a/aisenzhecode/沥青/日度价格预测_最佳模型.pkl b/aisenzhecode/沥青/日度价格预测_最佳模型.pkl index c672501..8fb5923 100644 Binary files a/aisenzhecode/沥青/日度价格预测_最佳模型.pkl and b/aisenzhecode/沥青/日度价格预测_最佳模型.pkl differ diff --git a/aisenzhecode/沥青/沥青定性模型每日推送-ytj.ipynb b/aisenzhecode/沥青/沥青定性模型每日推送-ytj.ipynb index 3bd5591..e331ed1 100644 --- a/aisenzhecode/沥青/沥青定性模型每日推送-ytj.ipynb +++ b/aisenzhecode/沥青/沥青定性模型每日推送-ytj.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "code", - "execution_count": 25, + "execution_count": 5, "metadata": {}, "outputs": [], "source": [ @@ -1073,7 +1073,7 @@ }, { "cell_type": "code", - "execution_count": 26, + "execution_count": 6, "metadata": {}, "outputs": [], "source": [ @@ -1113,7 +1113,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 7, "metadata": {}, "outputs": [], "source": [ @@ -1159,7 +1159,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 8, "metadata": {}, "outputs": [ { @@ -1173,9 +1173,9 @@ "name": "stderr", "output_type": "stream", "text": [ - "C:\\Users\\EDY\\AppData\\Local\\Temp\\ipykernel_6640\\43143909.py:66: FutureWarning: DataFrame.applymap has been deprecated. Use DataFrame.map instead.\n", + "C:\\Users\\EDY\\AppData\\Local\\Temp\\ipykernel_1412\\43143909.py:66: FutureWarning: DataFrame.applymap has been deprecated. Use DataFrame.map instead.\n", " df = df.applymap(lambda x: float(x) if isinstance(x, (int, float)) else x)\n", - "C:\\Users\\EDY\\AppData\\Local\\Temp\\ipykernel_6640\\43143909.py:70: FutureWarning: DataFrame.fillna with 'method' is deprecated and will raise in a future version. Use obj.ffill() or obj.bfill() instead.\n", + "C:\\Users\\EDY\\AppData\\Local\\Temp\\ipykernel_1412\\43143909.py:70: FutureWarning: DataFrame.fillna with 'method' is deprecated and will raise in a future version. Use obj.ffill() or obj.bfill() instead.\n", " df = df.fillna(method='ffill')\n" ] }, @@ -1185,7 +1185,7 @@ "text": [ " 日期 京博指导价 70号沥青开工率 资金因素 昨日计划提货偏差 生产情况 基质沥青库存 \\\n", "1399 2025-04-06 3600.0 37.3095 1.0 -1051.74 6000.0 107382.182661 \n", - "1400 2025-04-07 3500.0 36.784 1.0 478.28 6000.0 107382.182661 \n", + "1400 2025-04-07 3500.0 36.784 1.0 478.28 6000.0 107945.963078 \n", "\n", " 下游客户价格预期 即期成本 订单结构 计划产量 京博产量 \n", "1399 3630.0 3136.0033 1.0 4982.8366 5715.5175 \n", @@ -1194,7 +1194,7 @@ "现在的 2972.5098 \n", " index 日期 京博指导价 70号沥青开工率 资金因素 昨日计划提货偏差 生产情况 基质沥青库存 \\\n", "0 1399 2025-04-06 3600 37.3095 1 -1051.74 6000 107382.182661 \n", - "1 1400 2025-04-07 3500 36.784 1 478.28 6000 107382.182661 \n", + "1 1400 2025-04-07 3500 36.784 1 478.28 6000 107945.963078 \n", "\n", " 下游客户价格预期 即期成本 订单结构 计划产量 京博产量 \n", "0 3630 3136.0033 1 4982.8366 5715.5175 \n", @@ -1231,7 +1231,7 @@ }, { "cell_type": "code", - "execution_count": 29, + "execution_count": 9, "metadata": {}, "outputs": [], "source": [ @@ -1244,7 +1244,7 @@ }, { "cell_type": "code", - "execution_count": 30, + "execution_count": 10, "metadata": {}, "outputs": [], "source": [ diff --git a/aisenzhecode/沥青/沥青定量价格预测每日推送-ytj.ipynb b/aisenzhecode/沥青/沥青定量价格预测每日推送-ytj.ipynb index e0138f1..9b79cf5 100644 --- a/aisenzhecode/沥青/沥青定量价格预测每日推送-ytj.ipynb +++ b/aisenzhecode/沥青/沥青定量价格预测每日推送-ytj.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "code", - "execution_count": 11, + "execution_count": null, "metadata": {}, "outputs": [ { @@ -35,7 +35,7 @@ "import json\n", "import xlrd\n", "import xlwt\n", - "import datetime\n", + "from datetime import datetime, timedelta\n", "import time\n", "import pandas as pd\n", "\n", @@ -69,7 +69,7 @@ " \"funcOperation\": \"获取token\"\n", "}\n", "\n", - "read_file_path_name = \"沥青数据项.xls\"\n", + "read_file_path_name = \"沥青数据项.xlsx\"\n", "one_cols = []\n", "two_cols = []\n", "\n", @@ -98,7 +98,6 @@ "from sklearn.linear_model import Lasso\n", "from xgboost import XGBRegressor\n", "\n", - "import datetime\n", "import statsmodels.api as sm\n", "# from keras.preprocessing.sequence import TimeseriesGenerator\n", "from tensorflow.keras.preprocessing.sequence import TimeseriesGenerator\n", @@ -236,29 +235,11 @@ " ]\n", " }\n", " headers = {\"Authorization\": token_push}\n", - " # res = requests.post(url=upload_url, headers=headers, json=data, timeout=(3, 5))\n", - " # print(res.text)\n", - "\n", - " \n", - "# def upload_data_to_system(token):\n", - "# data = {\n", - "# \"funcModule\": \"数据表信息列表\",\n", - "# \"funcOperation\": \"新增\",\n", - "# \"data\": [\n", - "# {\"dataItemNo\": \"C01100036|Forecast_ Price|ACN\",\n", - "# \"dataDate\": '20230706',\n", - "# \"dataStatus\": \"add\",\n", - "# \"dataValue\": 3780.0\n", - "# }\n", - "\n", - "# ]\n", - "# }\n", - "# headers = {\"Authorization\": token}\n", - "# res = requests.post(url=upload_url, headers=headers, json=data, timeout=(3, 5))\n", - "# print(res.text)\n", + " res = requests.post(url=upload_url, headers=headers, json=data, timeout=(3, 5))\n", + " print(res.text)\n", "\n", "def forecast_price():\n", - " df_test = pd.read_excel('沥青数据项.xls',sheet_name='数据项历史数据')\n", + " df_test = pd.read_excel('沥青数据项.xlsx',sheet_name='数据项历史数据')\n", " df_test.drop([0],inplace=True)\n", " df_test[['汽油执行价','柴油执行价','齐鲁石化销量','齐鲁石化产量','齐鲁石化成交价','齐鲁石化库存','科力达销量',\n", " '科力达产量','科力达成交价','科力达库存','弘润销量','弘润产量','弘润成交价','弘润库存','市场成交价','京博指导价',\n", @@ -318,7 +299,7 @@ "\n", " pd.set_option('display.max_rows',40) \n", " pd.set_option('display.max_columns',40) \n", - " df_test = pd.read_excel('沥青数据项.xls',sheet_name='数据项历史数据')\n", + " df_test = pd.read_excel('沥青数据项.xlsx',sheet_name='数据项历史数据')\n", " df_test.drop([0],inplace=True)\n", " df_test[['汽油执行价','柴油执行价','齐鲁石化销量','齐鲁石化产量','齐鲁石化成交价','齐鲁石化库存','科力达销量',\n", " '科力达产量','科力达成交价','科力达库存','弘润销量','弘润产量','弘润成交价','弘润库存','市场成交价','京博指导价',\n", @@ -362,7 +343,6 @@ " from sklearn.linear_model import Lasso\n", " from xgboost import XGBRegressor\n", "\n", - " from datetime import datetime\n", " import statsmodels.api as sm\n", " # from keras.preprocessing.sequence import TimeseriesGenerator\n", " from tensorflow.keras.preprocessing.sequence import TimeseriesGenerator\n", @@ -586,7 +566,6 @@ " save_xls(append_rows)\n", "\n", " # 获取当月的数据写入到指定文件\n", - " queryDataListItemNos(token)\n", " # optimize_Model()\n", " # upload_data_to_system(token_push,date)\n", " # data_list.append(three_cols)\n", @@ -596,6 +575,7 @@ "\n", "def start_1():\n", " '''更新数据'''\n", + " print(\"更新当天数据\")\n", " read_xls_data()\n", "\n", " token = get_head_auth()\n", @@ -622,6 +602,7 @@ " append_rows.append(dataItemNo_dataValue[value])\n", " else:\n", " append_rows.append(\"\")\n", + " print(\"当天数据为:\",append_rows)\n", " save_xls_1(append_rows)\n", "\n", " \n", @@ -667,7 +648,7 @@ "def save_xls_1(append_rows):\n", "\n", " # 打开xls文件\n", - " workbook = xlrd.open_workbook('沥青数据项.xls')\n", + " workbook = xlrd.open_workbook('沥青数据项.xlsx')\n", "\n", " # 获取所有sheet的个数\n", " sheet_count = len(workbook.sheet_names())\n", @@ -705,7 +686,7 @@ " new_sheet.write(row_count, col, append_rows[col])\n", "\n", " # 保存新的xls文件\n", - " new_workbook.save(\"沥青数据项.xls\") \n", + " new_workbook.save(\"沥青数据项.xlsx\") \n", "\n", " \n", " \n", @@ -761,7 +742,7 @@ " new_sheet.write(row_count, col, append_rows[col])\n", "\n", " # 保存新的xls文件\n", - " new_workbook.save(\"沥青数据项.xls\")\n", + " new_workbook.save(\"沥青数据项.xlsx\")\n", "\n", "\n", "\n", @@ -854,13 +835,13 @@ "\n", "\n", " # 保存新的xls文件\n", - " new_workbook.save(\"沥青数据项.xls\")\n", + " new_workbook.save(\"沥青数据项.xlsx\")\n", "\n", "\n", "\n", "\n", "def queryDataListItemNos(token=None):\n", - " df = pd.read_excel('沥青数据项.xls')\n", + " df = pd.read_excel('沥青数据项.xlsx')\n", " dataItemNoList = df.iloc[0].tolist()[1:]\n", " \n", " if token is None:\n", @@ -890,41 +871,48 @@ " save_queryDataListItemNos_xls(data_df,dataItemNoList)\n", " print('当月数据更新完成')\n", "\n", + "def main(start_date=None,token=None,token_push=None):\n", + " if start_date is None:\n", + " start_date = datetime.now()\n", + " if token is None:\n", + " token = get_head_auth()\n", + " if token_push is None:\n", + " token_push = get_head_push_auth()\n", + " date = start_date.strftime('%Y%m%d')\n", + " print(date)\n", + " # 更新当月数据\n", + " queryDataListItemNos(token)\n", + " # 更新当日数据\n", + " start_3(start_date,token,token_push)\n", + " # 训练模型\n", + " optimize_Model()\n", + " # 预测&上传预测结果\n", + " upload_data_to_system(token_push,start_date)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ "\n", "if __name__ == \"__main__\":\n", - " pass\n", - " # 需要单独运行放开\n", - "\n", - "# start()\n", - "\n", + " print(\"运行中ing...\")\n", " # 每天定时12点运行\n", - " # while True:\n", - " # # 获取当前时间\n", - " # current_time = time.strftime(\"%H:%M:%S\", time.localtime())\n", - " # current_time_1 = time.strftime(\"%H:%M:%S\", time.localtime())\n", + " while True:\n", + " # 获取当前时间\n", + " current_time = time.strftime(\"%H:%M:%S\", time.localtime())\n", "\n", - "\n", - " \n", - "\n", - " # # 判断当前时间是否为执行任务的时间点\n", - " # if current_time == \"12:00:00\":\n", - " # print(\"执行定时任务\")\n", - "\n", - " # 这个函数,获取当天数据,\n", - " # 预测训练,\n", - " # 预测结果上传\n", - "\n", - " # start()\n", - "\n", - " # # 休眠1秒钟,避免过多占用CPU资源\n", - " # time.sleep(1)\n", - " \n", - " # elif current_time_1 == \"20:00:00\":\n", - " # print(\"更新数据\")\n", - "\n", - " # 这个函数,获取当天数据,保存\n", - " # start_1()\n", - " # time.sleep(1)\n", + " # 判断当前时间是否为执行任务的时间点\n", + " # if current_time == \"12:00:00\":\n", + " if current_time == \"15:36:00\":\n", + " print(\"执行定时任务\")\n", + " main()\n", + " time.sleep(1)\n", + " elif current_time == \"15:40:00\":\n", + " start_1()\n", + " time.sleep(1)\n", "\n", "\n", "# # 检测数据准确性, 需要检测放开\n", @@ -941,40 +929,24 @@ "name": "stdout", "output_type": "stream", "text": [ - "20250401\n" - ] - }, - { - "ename": "PermissionError", - "evalue": "[Errno 13] Permission denied: '沥青数据项.xls'", - "output_type": "error", - "traceback": [ - "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", - "\u001b[1;31mPermissionError\u001b[0m Traceback (most recent call last)", - "Cell \u001b[1;32mIn[12], line 11\u001b[0m\n\u001b[0;32m 9\u001b[0m \u001b[38;5;28;01mwhile\u001b[39;00m start_date \u001b[38;5;241m<\u001b[39m end_date:\n\u001b[0;32m 10\u001b[0m \u001b[38;5;28mprint\u001b[39m(start_date\u001b[38;5;241m.\u001b[39mstrftime(\u001b[38;5;124m'\u001b[39m\u001b[38;5;124m%\u001b[39m\u001b[38;5;124mY\u001b[39m\u001b[38;5;124m%\u001b[39m\u001b[38;5;124mm\u001b[39m\u001b[38;5;132;01m%d\u001b[39;00m\u001b[38;5;124m'\u001b[39m))\n\u001b[1;32m---> 11\u001b[0m start_3(start_date,token,token_push)\n\u001b[0;32m 12\u001b[0m time\u001b[38;5;241m.\u001b[39msleep(\u001b[38;5;241m1\u001b[39m)\n\u001b[0;32m 13\u001b[0m start_2(start_date,token)\n", - "Cell \u001b[1;32mIn[11], line 553\u001b[0m, in \u001b[0;36mstart_3\u001b[1;34m(date, token, token_push)\u001b[0m\n\u001b[0;32m 551\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[0;32m 552\u001b[0m append_rows\u001b[38;5;241m.\u001b[39mappend(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n\u001b[1;32m--> 553\u001b[0m save_xls(append_rows)\n\u001b[0;32m 555\u001b[0m \u001b[38;5;66;03m# 获取当月的数据写入到指定文件\u001b[39;00m\n\u001b[0;32m 556\u001b[0m queryDataListItemNos(token)\n", - "Cell \u001b[1;32mIn[11], line 731\u001b[0m, in \u001b[0;36msave_xls\u001b[1;34m(append_rows)\u001b[0m\n\u001b[0;32m 728\u001b[0m new_sheet\u001b[38;5;241m.\u001b[39mwrite(row_count, col, append_rows[col])\n\u001b[0;32m 730\u001b[0m \u001b[38;5;66;03m# 保存新的xls文件\u001b[39;00m\n\u001b[1;32m--> 731\u001b[0m new_workbook\u001b[38;5;241m.\u001b[39msave(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m沥青数据项.xls\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n", - "File \u001b[1;32m~\\AppData\\Roaming\\Python\\Python311\\site-packages\\xlwt\\Workbook.py:710\u001b[0m, in \u001b[0;36mWorkbook.save\u001b[1;34m(self, filename_or_stream)\u001b[0m\n\u001b[0;32m 707\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01m.\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m CompoundDoc\n\u001b[0;32m 709\u001b[0m doc \u001b[38;5;241m=\u001b[39m CompoundDoc\u001b[38;5;241m.\u001b[39mXlsDoc()\n\u001b[1;32m--> 710\u001b[0m doc\u001b[38;5;241m.\u001b[39msave(filename_or_stream, \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mget_biff_data())\n", - "File \u001b[1;32m~\\AppData\\Roaming\\Python\\Python311\\site-packages\\xlwt\\CompoundDoc.py:262\u001b[0m, in \u001b[0;36mXlsDoc.save\u001b[1;34m(self, file_name_or_filelike_obj, stream)\u001b[0m\n\u001b[0;32m 260\u001b[0m we_own_it \u001b[38;5;241m=\u001b[39m \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;28mhasattr\u001b[39m(f, \u001b[38;5;124m'\u001b[39m\u001b[38;5;124mwrite\u001b[39m\u001b[38;5;124m'\u001b[39m)\n\u001b[0;32m 261\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m we_own_it:\n\u001b[1;32m--> 262\u001b[0m f \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mopen\u001b[39m(file_name_or_filelike_obj, \u001b[38;5;124m'\u001b[39m\u001b[38;5;124mw+b\u001b[39m\u001b[38;5;124m'\u001b[39m)\n\u001b[0;32m 263\u001b[0m f\u001b[38;5;241m.\u001b[39mwrite(\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mheader)\n\u001b[0;32m 264\u001b[0m f\u001b[38;5;241m.\u001b[39mwrite(\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mpacked_MSAT_1st)\n", - "\u001b[1;31mPermissionError\u001b[0m: [Errno 13] Permission denied: '沥青数据项.xls'" + "更新当天数据\n", + "当天数据为: ['2025-04-08', '', '', 0.05, 0.25, 3680.0, 0.7, 0.0, 0.0, 3450.0, 7.9, 0.15, 0.2, 3400.0, 10.27, '', 3450.0, 65.88, 64.36, '', '', '', '', '', '', '', '', '', 3096.5238, '', '', '', '', '']\n" ] } ], "source": [ - "# from datetime import datetime, timedelta\n", - "\n", - "# start_date = datetime(2025, 4, 1)\n", - "# end_date = datetime(2025, 4, 2)\n", + "# start_date = datetime(2025, 4, 8)\n", + "# end_date = datetime(2025, 4, 9)\n", "# token = get_head_auth()\n", "\n", "# token_push = get_head_push_auth()\n", "\n", + "\n", + "\n", + "\n", "# while start_date < end_date:\n", - "# print(start_date.strftime('%Y%m%d'))\n", - "# start_3(start_date,token,token_push)\n", - "# time.sleep(1)\n", - "# start_2(start_date,token)\n", - "# start_date += timedelta(days=1)" + " # main(start_date,token,token_push)\n", + "# start_date += timedelta(days=1)\n" ] } ], diff --git a/aisenzhecode/沥青/沥青数据项 - 副本.xls b/aisenzhecode/沥青/沥青数据项 - 副本.xls new file mode 100644 index 0000000..290b16e Binary files /dev/null and b/aisenzhecode/沥青/沥青数据项 - 副本.xls differ diff --git a/aisenzhecode/沥青/沥青数据项.xlsx b/aisenzhecode/沥青/沥青数据项.xlsx new file mode 100644 index 0000000..818411a Binary files /dev/null and b/aisenzhecode/沥青/沥青数据项.xlsx differ diff --git a/aisenzhecode/液化石油气/液化气价格预测ytj.ipynb b/aisenzhecode/液化石油气/液化气价格预测ytj.ipynb index 46b3a96..fb29845 100644 --- a/aisenzhecode/液化石油气/液化气价格预测ytj.ipynb +++ b/aisenzhecode/液化石油气/液化气价格预测ytj.ipynb @@ -11,30 +11,23 @@ " \n", - " \n", " " ] }, "metadata": {}, "output_type": "display_data" - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "获取的token: eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJhcGlfZGV2IiwidGgiOiI4YTQ1NzdkYmQ5MTk2NzU3NThkNTc5OTlhMWU4OTFmZSIsImx0IjoiYXBpIiwiaXNzIjoiIiwidG0iOiJQQyIsImV4cCI6MTc0MzEwNTAxMCwianRpIjoiN2QwMjE1N2Q0NzIwNDZjMjk3NTE4ODMzNjA3NzY3OTQifQ.F2QXnRxR_YUmQ8w2GIWkvjy0xLMTZg93rJ-wHkuyIzw\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "C:\\Users\\h5218\\AppData\\Local\\Temp\\ipykernel_31728\\3153608672.py:885: DeprecationWarning:\n", - "\n", - "The truth value of an empty array is ambiguous. Returning False, but in future this will result in an error. Use `array.size > 0` to check that an array is not empty.\n", - "\n" - ] } ], "source": [ @@ -555,7 +548,7 @@ " print('更新数据前')\n", " print(df.tail(1))\n", " # 检查日期是否已存在于数据中\n", - " if previous_date not in df['日期'].values:\n", + " if previous_date not in df['Date'].values:\n", " # 将新的数据添加到DataFrame中\n", " new_row = pd.DataFrame([append_rows], columns=df.columns.tolist())\n", " df = pd.concat([df, new_row], ignore_index=True)\n", @@ -563,7 +556,7 @@ " # 更新现有数据\n", " print('日期存在,即将更新')\n", " print('新数据',append_rows[1:])\n", - " df.loc[df['日期'] == previous_date, df.columns.tolist()[1:]] = append_rows[1:]\n", + " df.loc[df['Date'] == previous_date, df.columns.tolist()[1:]] = append_rows[1:]\n", "\n", " print('更新数据后')\n", " print(df.tail(1))\n", @@ -635,6 +628,11 @@ " else:\n", " append_rows.append(\"\")\n", " save_xls(append_rows)\n", + " \n", + " \n", + " # 获取当月的数据写入到指定文件\n", + " # queryDataListItemNos(token=token)\n", + " \n", " # optimize_Model()\n", " # upload_data_to_system(token_push,cur_time)\n", " \n", @@ -795,8 +793,14 @@ "\n", "def save_xls(append_rows):\n", "\n", - " # 打开xls文件\n", - " workbook = xlrd.open_workbook('液化气数据.xls')\n", + " # 修改文件打开方式\n", + " try:\n", + " # 尝试用xlrd打开旧版xls文件\n", + " workbook = xlrd.open_workbook('液化气数据.xls')\n", + " except:\n", + " # 使用openpyxl打开新版xlsx文件\n", + " from openpyxl import load_workbook\n", + " workbook = load_workbook('液化气数据.xls')\n", "\n", " # 获取所有sheet的个数\n", " sheet_count = len(workbook.sheet_names())\n", @@ -922,31 +926,34 @@ " dataItemNo = dataItemNoList[j]\n", "\n", " # for dataItemNo in dataItemNoList:\n", - " if group[group[\"dataItemNo\"] == dataItemNo][\"dataValue\"].values and (not str(group[group[\"dataItemNo\"] == dataItemNo][\"dataValue\"].values[0]) == 'nan'):\n", - " # if group[group[\"dataItemNo\"] == dataItemNo][\"dataValue\"].values:\n", + " if group[group[\"dataItemNo\"] == dataItemNo][\"dataValue\"].values:\n", "\n", " new_sheet.write(row_count + rowFlag - current_year_month_row, j + 1, group[group[\"dataItemNo\"] == dataItemNo][\"dataValue\"].values[0])\n", "\n", " rowFlag += 1\n", "\n", - "\n", " # 保存新的xls文件\n", " new_workbook.save(\"液化气数据.xls\")\n", "\n", "\n", "\n", "\n", - "def queryDataListItemNos():\n", + "def queryDataListItemNos(date=None,token=None):\n", " df = pd.read_excel('液化气数据.xls')\n", " dataItemNoList = df.iloc[0].tolist()[1:]\n", + " \n", + " if token is None:\n", + " token = get_head_auth()\n", "\n", - " token = get_head_auth()\n", - " if not token:\n", - " return\n", + " if not token:\n", + " print('token获取失败')\n", + " return\n", "\n", " # 获取当前日期\n", - " current_date = datetime.now()\n", - "\n", + " if date is None:\n", + " current_date = datetime.now()\n", + " else:\n", + " current_date = date\n", " # 获取当月1日\n", " first_day_of_month = current_date.replace(day=1)\n", "\n", @@ -961,7 +968,10 @@ "\n", " data_df[\"dataDate\"] = pd.to_datetime(data_df[\"dataDate\"])\n", " data_df[\"dataDate\"] = data_df[\"dataDate\"].dt.strftime('%Y-%m-%d')\n", + " print(data_df)\n", " save_queryDataListItemNos_xls(data_df,dataItemNoList)\n", + " print('当月数据更新完成')\n", + "\n", "\n", "\n", "\n", @@ -974,7 +984,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 61, "metadata": { "scrolled": true }, @@ -997,14 +1007,12 @@ "# # print(current_time_1)\n", "\n", "\n", - " # 获取当月的数据写入到指定文件\n", - " # queryDataListItemNos()\n", "\n", "\n", "# # 判断当前时间是否为执行任务的时间点\n", "# if current_time == \"09:15:00\":\n", "# print(\"执行定时任务\")\n", - "# start()\n", + " # start()\n", "\n", "# # 休眠1秒钟,避免过多占用CPU资源\n", "# time.sleep(1)\n", @@ -1025,32 +1033,45 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 62, "metadata": {}, "outputs": [ { - "ename": "NameError", - "evalue": "name 'datetime' is not defined", + "name": "stdout", + "output_type": "stream", + "text": [ + "获取的token: eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJhcGlfZGV2IiwidGgiOiI4YTQ1NzdkYmQ5MTk2NzU3NThkNTc5OTlhMWU4OTFmZSIsImx0IjoiYXBpIiwiaXNzIjoiIiwidG0iOiJQQyIsImV4cCI6MTc0NDEyODI3NywianRpIjoiMjk0MTk4NTU0MWIxNGY2NmJjMTgyY2Y5ZDY1MWVjYzUifQ.2uFevYbViecixxMPgJNCvWO_q2hjzJM35_FavDmEXnI\n" + ] + }, + { + "ename": "ValueError", + "evalue": "Unknown engine: xlwt", "output_type": "error", "traceback": [ "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", - "\u001b[1;31mNameError\u001b[0m Traceback (most recent call last)", - "Cell \u001b[1;32mIn[2], line 1\u001b[0m\n\u001b[1;32m----> 1\u001b[0m start_date \u001b[38;5;241m=\u001b[39m datetime(\u001b[38;5;241m2025\u001b[39m, \u001b[38;5;241m3\u001b[39m, \u001b[38;5;241m1\u001b[39m)\n\u001b[0;32m 2\u001b[0m end_date \u001b[38;5;241m=\u001b[39m datetime(\u001b[38;5;241m2025\u001b[39m, \u001b[38;5;241m3\u001b[39m, \u001b[38;5;241m12\u001b[39m)\n\u001b[0;32m 4\u001b[0m \u001b[38;5;28;01mwhile\u001b[39;00m start_date \u001b[38;5;241m<\u001b[39m end_date:\n", - "\u001b[1;31mNameError\u001b[0m: name 'datetime' is not defined" + "\u001b[1;31mValueError\u001b[0m Traceback (most recent call last)", + "Cell \u001b[1;32mIn[62], line 8\u001b[0m\n\u001b[0;32m 6\u001b[0m date \u001b[38;5;241m=\u001b[39m start_date\u001b[38;5;241m.\u001b[39mstrftime(\u001b[38;5;124m'\u001b[39m\u001b[38;5;124m%\u001b[39m\u001b[38;5;124mY\u001b[39m\u001b[38;5;124m%\u001b[39m\u001b[38;5;124mm\u001b[39m\u001b[38;5;132;01m%d\u001b[39;00m\u001b[38;5;124m'\u001b[39m)\n\u001b[0;32m 7\u001b[0m date2 \u001b[38;5;241m=\u001b[39m start_date\u001b[38;5;241m.\u001b[39mstrftime(\u001b[38;5;124m'\u001b[39m\u001b[38;5;124m%\u001b[39m\u001b[38;5;124mY-\u001b[39m\u001b[38;5;124m%\u001b[39m\u001b[38;5;124mm-\u001b[39m\u001b[38;5;132;01m%d\u001b[39;00m\u001b[38;5;124m'\u001b[39m)\n\u001b[1;32m----> 8\u001b[0m updateYesterdayExcelData(date\u001b[38;5;241m=\u001b[39mdate2,token\u001b[38;5;241m=\u001b[39mtoken)\n\u001b[0;32m 9\u001b[0m \u001b[38;5;66;03m# queryDataListItemNos(date=start_date,token=token)\u001b[39;00m\n\u001b[0;32m 10\u001b[0m start(date)\n", + "Cell \u001b[1;32mIn[60], line 471\u001b[0m, in \u001b[0;36mupdateYesterdayExcelData\u001b[1;34m(date, token)\u001b[0m\n\u001b[0;32m 469\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mupdateYesterdayExcelData\u001b[39m(date\u001b[38;5;241m=\u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124m'\u001b[39m, token\u001b[38;5;241m=\u001b[39m\u001b[38;5;28;01mNone\u001b[39;00m):\n\u001b[0;32m 470\u001b[0m \u001b[38;5;66;03m# 使用pandas读取Excel文件\u001b[39;00m\n\u001b[1;32m--> 471\u001b[0m df \u001b[38;5;241m=\u001b[39m pd\u001b[38;5;241m.\u001b[39mread_excel(read_file_path_name, engine\u001b[38;5;241m=\u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mxlwt\u001b[39m\u001b[38;5;124m'\u001b[39m)\n\u001b[0;32m 473\u001b[0m \u001b[38;5;66;03m# 获取第二行的数据作为列名\u001b[39;00m\n\u001b[0;32m 474\u001b[0m one_cols \u001b[38;5;241m=\u001b[39m df\u001b[38;5;241m.\u001b[39miloc[\u001b[38;5;241m0\u001b[39m,:]\u001b[38;5;241m.\u001b[39mtolist()\n", + "File \u001b[1;32md:\\ProgramData\\anaconda3\\Lib\\site-packages\\pandas\\io\\excel\\_base.py:504\u001b[0m, in \u001b[0;36mread_excel\u001b[1;34m(io, sheet_name, header, names, index_col, usecols, dtype, engine, converters, true_values, false_values, skiprows, nrows, na_values, keep_default_na, na_filter, verbose, parse_dates, date_parser, date_format, thousands, decimal, comment, skipfooter, storage_options, dtype_backend, engine_kwargs)\u001b[0m\n\u001b[0;32m 502\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;28misinstance\u001b[39m(io, ExcelFile):\n\u001b[0;32m 503\u001b[0m should_close \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;01mTrue\u001b[39;00m\n\u001b[1;32m--> 504\u001b[0m io \u001b[38;5;241m=\u001b[39m ExcelFile(\n\u001b[0;32m 505\u001b[0m io,\n\u001b[0;32m 506\u001b[0m storage_options\u001b[38;5;241m=\u001b[39mstorage_options,\n\u001b[0;32m 507\u001b[0m engine\u001b[38;5;241m=\u001b[39mengine,\n\u001b[0;32m 508\u001b[0m engine_kwargs\u001b[38;5;241m=\u001b[39mengine_kwargs,\n\u001b[0;32m 509\u001b[0m )\n\u001b[0;32m 510\u001b[0m \u001b[38;5;28;01melif\u001b[39;00m engine \u001b[38;5;129;01mand\u001b[39;00m engine \u001b[38;5;241m!=\u001b[39m io\u001b[38;5;241m.\u001b[39mengine:\n\u001b[0;32m 511\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mValueError\u001b[39;00m(\n\u001b[0;32m 512\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mEngine should not be specified when passing \u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[0;32m 513\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124man ExcelFile - ExcelFile already has the engine set\u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[0;32m 514\u001b[0m )\n", + "File \u001b[1;32md:\\ProgramData\\anaconda3\\Lib\\site-packages\\pandas\\io\\excel\\_base.py:1531\u001b[0m, in \u001b[0;36mExcelFile.__init__\u001b[1;34m(self, path_or_buffer, engine, storage_options, engine_kwargs)\u001b[0m\n\u001b[0;32m 1528\u001b[0m engine_kwargs \u001b[38;5;241m=\u001b[39m {}\n\u001b[0;32m 1530\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m engine \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m \u001b[38;5;129;01mand\u001b[39;00m engine \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;129;01min\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_engines:\n\u001b[1;32m-> 1531\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mValueError\u001b[39;00m(\u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mUnknown engine: \u001b[39m\u001b[38;5;132;01m{\u001b[39;00mengine\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m\"\u001b[39m)\n\u001b[0;32m 1533\u001b[0m \u001b[38;5;66;03m# First argument can also be bytes, so create a buffer\u001b[39;00m\n\u001b[0;32m 1534\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28misinstance\u001b[39m(path_or_buffer, \u001b[38;5;28mbytes\u001b[39m):\n", + "\u001b[1;31mValueError\u001b[0m: Unknown engine: xlwt" ] } ], "source": [ - "start_date = datetime(2025, 3, 1)\n", - "end_date = datetime(2025, 3, 12)\n", + "start_date = datetime(2025, 4, 2)\n", + "end_date = datetime(2025, 4, 3)\n", + "token = get_head_auth()\n", "\n", "while start_date < end_date:\n", " date = start_date.strftime('%Y%m%d')\n", - " updateYesterdayExcelData(date)\n", - " # start(date)\n", + " date2 = start_date.strftime('%Y-%m-%d')\n", + " updateYesterdayExcelData(date=date2,token=token)\n", + " # queryDataListItemNos(date=start_date,token=token)\n", + " start(date)\n", " # # time.sleep(1)\n", " # start_1(start_date)\n", - " # start_date += timedelta(days=1)\n", + " start_date += timedelta(days=1)\n", " time.sleep(5)\n", "\n", "# print(price_list)" @@ -1066,7 +1087,7 @@ ], "metadata": { "kernelspec": { - "display_name": "Python 3", + "display_name": "base", "language": "python", "name": "python3" }, @@ -1080,7 +1101,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.12.4" + "version": "3.11.7" } }, "nbformat": 4, diff --git a/aisenzhecode/液化石油气/液化气数据.xls b/aisenzhecode/液化石油气/液化气数据.xls index 549d483..2ba8b49 100644 Binary files a/aisenzhecode/液化石油气/液化气数据.xls and b/aisenzhecode/液化石油气/液化气数据.xls differ diff --git a/aisenzhecode/石油苯/纯苯价格预测-自定义日期ytj.ipynb b/aisenzhecode/石油苯/纯苯价格预测-自定义日期ytj.ipynb index 944eb98..8b2538c 100644 --- a/aisenzhecode/石油苯/纯苯价格预测-自定义日期ytj.ipynb +++ b/aisenzhecode/石油苯/纯苯价格预测-自定义日期ytj.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "code", - "execution_count": null, + "execution_count": 20, "metadata": {}, "outputs": [ { @@ -828,7 +828,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 21, "metadata": {}, "outputs": [ {