{ "cells": [ { "cell_type": "code", "execution_count": 43, "metadata": {}, "outputs": [], "source": [ "import requests\n", "import json\n", "import xlrd\n", "import xlwt\n", "from datetime import datetime, timedelta \n", "import time\n", "import pandas as pd\n", "pd.set_option('display.max_columns', None)\n", "\n", "import numpy as np\n", "# 变量定义\n", "login_url = \"http://10.200.32.39/jingbo-api/api/server/login\"\n", "login_push_url = \"http://10.200.32.39/jingbo-api/api/server/login\"\n", "# query_data_list_item_nos_url\n", "search_url = \"http://10.200.32.39/jingbo-api/api/warehouse/dwDataItem/queryByItemNos\" #jingbo-dev/api/warehouse/dwDataItem/queryDataListItemNos\n", "upload_url = \"http://10.200.32.39/jingbo-api/api/dw/dataValue/pushDataValueList\"\n", "queryDataListItemNos_url = \"http://10.200.32.39/jingbo-api//api/warehouse/dwDataItem/queryDataListItemNos\"\n", "\n", "\n", "query_data_list_item_nos_data = {\n", " \"funcModule\": \"数据项\",\n", " \"funcOperation\": \"查询\",\n", " \"data\": {\n", " \"dateStart\": \"20200101\",\n", " \"dateEnd\": \"20241231\",\n", " \"dataItemNoList\": [\"Brentzdj\", \"Brentzgj\"] # 数据项编码,代表 brent最低价和最高价\n", " }\n", "}\n", "\n", "\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", "}\n", "\n", "login_push_data = {\n", " \"data\": {\n", " \"account\": \"api_dev\",\n", " \"password\": \"ZTEwYWRjMzk0OWJhNTlhYmJlNTZlMDU3ZjIwZjg4M2U=\",\n", " \"tenantHashCode\": \"8a4577dbd919675758d57999a1e891fe\",\n", " \"terminal\": \"API\"\n", " },\n", " \"funcModule\": \"API\",\n", " \"funcOperation\": \"获取token\"\n", "}\n", "\n", "\n", "read_file_path_name = \"定性模型数据项12-11.xlsx\"\n", "one_cols = []\n", "two_cols = []\n", "\n", "def get_head_auth():\n", " login_res = requests.post(url=login_url, json=login_data, timeout=(3, 5))\n", " text = json.loads(login_res.text)\n", " if text[\"status\"]:\n", " token = text[\"data\"][\"accessToken\"]\n", " return token\n", " else:\n", " print(\"获取认证失败\")\n", " return None\n", "\n", "\n", "def get_head_push_auth():\n", " login_res = requests.post(url=login_push_url, json=login_push_data, timeout=(3, 5))\n", " text = json.loads(login_res.text)\n", " if text[\"status\"]:\n", " token = text[\"data\"][\"accessToken\"]\n", " return token\n", " else:\n", " print(\"获取认证失败\")\n", " return None\n", "\n", "\n", "def update_e_value(file_path, column_index, threshold):\n", " \"\"\"\n", " 数据修正需求:2025年1月8日\n", " 如果如果今天的成本即期价跟昨天的成本价差正负1000以上,就按照昨天的成本价计算\n", "\n", " 更新Excel文件中指定列的值,如果新值与前一天的值变化大于阈值,则将新值改为前一天的值。\n", "\n", " :param file_path: Excel文件路径\n", " :param column_index: 需要更新的列索引\n", " :param threshold: 变化阈值\n", " \"\"\"\n", " # 读取Excel文件\n", " # try:\n", " # df = pd.read_excel(file_path, engine='openpyxl')\n", " # except:\n", " # df = pd.read_excel(file_path, engine='xlrd')\n", " \n", " df = pd.read_excel(file_path)\n", " # 所有列列统一数据格式为float\n", " df = df.applymap(lambda x: float(x) if isinstance(x, (int, float)) else x)\n", " \n", " # print(df.tail())\n", " # 填充缺失值\n", " df = df.fillna(method='ffill')\n", "\n", " # 获取昨天,前天数据\n", " df1 = df[-3:-1]\n", " print(df1)\n", " # 获取前一天的指定列值\n", " previous_value = df1.iloc[0, column_index]\n", " print('前一天的',previous_value,type(previous_value))\n", " # 获取当前的指定列值\n", " current_value = df1.iloc[1, column_index]\n", " print('现在的',current_value,type(current_value))\n", " # 判断指定列值的变化是否大于阈值\n", " if abs(current_value - previous_value) > threshold:\n", " # 如果变化大于阈值,将当前的指定列值改为前一天的值\n", " df.iloc[-2, column_index] = previous_value\n", " print('修改了')\n", " # print(df.tail())\n", " # 将修改后的数据写回Excel文件\n", " df.to_excel(file_path, index=False,engine='openpyxl')\n", "\n", "def getLogToken():\n", " login_res = requests.post(url=login_url, json=login_data, timeout=(3, 5))\n", " text = json.loads(login_res.text)\n", " if text[\"status\"]:\n", " token = text[\"data\"][\"accessToken\"]\n", " else:\n", " print(\"获取认证失败\")\n", " token = None\n", " return token\n", "\n", "def updateExcelDatabak(date='',token=None):\n", " workbook = xlrd.open_workbook(read_file_path_name)\n", "\n", " # 选择第一个表格\n", " sheet = workbook.sheet_by_index(0)\n", "\n", " row_data = sheet.row_values(1)\n", " one_cols = row_data\n", "\n", " cur_time,cur_time2 = getNow(date)\n", " search_data = {\n", " \"data\": {\n", " \"date\": cur_time,\n", " \"dataItemNoList\": one_cols[1:]\n", " },\n", " \"funcModule\": \"数据项\",\n", " \"funcOperation\": \"查询\"\n", " }\n", " headers = {\"Authorization\": token}\n", " search_res = requests.post(url=search_url, headers=headers, json=search_data, timeout=(3, 5))\n", " search_value = json.loads(search_res.text)[\"data\"]\n", "# datas = search_value\n", " if search_value:\n", " datas = search_value\n", " else :\n", " datas = None\n", " \n", "\n", " append_rows = [cur_time2]\n", " dataItemNo_dataValue = {}\n", "# for data_value in datas:\n", "# dataItemNo_dataValue[data_value[\"dataItemNo\"]] = data_value[\"dataValue\"]\n", " for data_value in datas:\n", " if \"dataValue\" not in data_value:\n", " print(data_value)\n", " dataItemNo_dataValue[data_value[\"dataItemNo\"]] = \"\"\n", " else:\n", " dataItemNo_dataValue[data_value[\"dataItemNo\"]] = data_value[\"dataValue\"]\n", " for value in one_cols[1:]:\n", " if value in dataItemNo_dataValue:\n", " append_rows.append(dataItemNo_dataValue[value])\n", " else:\n", " append_rows.append(\"\")\n", "\n", " workbook = xlrd.open_workbook('定性模型数据项12-11.xlsx')\n", "\n", " # 获取所有sheet的个数\n", " sheet_count = len(workbook.sheet_names())\n", "\n", " # 获取所有sheet的名称\n", " sheet_names = workbook.sheet_names()\n", "\n", " new_workbook = xlwt.Workbook()\n", " for i in range(sheet_count):\n", " # 获取当前sheet\n", " sheet = workbook.sheet_by_index(i)\n", "\n", " # 获取sheet的行数和列数\n", " row_count = sheet.nrows\n", " col_count = sheet.ncols\n", " # 获取原有数据\n", " data = []\n", " for row in range(row_count):\n", " row_data = []\n", " for col in range(col_count):\n", " row_data.append(sheet.cell_value(row, col))\n", " data.append(row_data)\n", " # 创建xlwt的Workbook对象\n", " # 创建sheet\n", " new_sheet = new_workbook.add_sheet(sheet_names[i])\n", "\n", " # 将原有的数据写入新的sheet\n", " for row in range(row_count):\n", " for col in range(col_count):\n", " new_sheet.write(row, col, data[row][col])\n", "\n", " if i == 0:\n", " \n", " # 在新的sheet中添加数据\n", " for col in range(col_count):\n", " new_sheet.write(row_count, col, append_rows[col])\n", "\n", " # 保存新的xls文件\n", " new_workbook.save(\"定性模型数据项12-11.xlsx\")\n", "\n", "def updateYesterdayExcelData(date='', token=None):\n", " # 使用pandas读取Excel文件\n", " df = pd.read_excel(read_file_path_name, engine='openpyxl')\n", "\n", " # 获取第二行的数据作为列名\n", " one_cols = df.iloc[0,:].tolist()\n", "\n", " # 获取当前日期的前一天\n", " if date == '':\n", " previous_date = (datetime.now() - timedelta(days=1)).strftime('%Y-%m-%d')\n", " else:\n", " # 字符串转日期\n", " previous_date = (datetime.strptime(date, \"%Y-%m-%d\")-timedelta(days=1)).strftime('%Y-%m-%d')\n", " \n", "\n", " cur_time, cur_time2 = getNow(previous_date)\n", " search_data = {\n", " \"data\": {\n", " \"date\": cur_time,\n", " \"dataItemNoList\": one_cols[1:]\n", " },\n", " \"funcModule\": \"数据项\",\n", " \"funcOperation\": \"查询\"\n", " }\n", " headers = {\"Authorization\": token}\n", " search_res = requests.post(url=search_url, headers=headers, json=search_data, timeout=(3, 5))\n", " search_value = json.loads(search_res.text)[\"data\"]\n", " if search_value:\n", " datas = search_value\n", " else:\n", " datas = None\n", "\n", " append_rows = [cur_time2]\n", " dataItemNo_dataValue = {}\n", " for data_value in datas:\n", " if \"dataValue\" not in data_value:\n", " print(data_value)\n", " dataItemNo_dataValue[data_value[\"dataItemNo\"]] = \"\"\n", " else:\n", " dataItemNo_dataValue[data_value[\"dataItemNo\"]] = data_value[\"dataValue\"]\n", " for value in one_cols[1:]:\n", " if value in dataItemNo_dataValue:\n", " append_rows.append(dataItemNo_dataValue[value])\n", " else:\n", " append_rows.append(\"\")\n", "\n", " print('更新数据前')\n", " print(df.tail(1))\n", " # 检查日期是否已存在于数据中\n", " if previous_date not in df['日期'].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", " else:\n", " # 更新现有数据\n", " print('日期存在,即将更新')\n", " print('新数据',append_rows[1:])\n", " df.loc[df['日期'] == previous_date, df.columns.tolist()[1:]] = append_rows[1:]\n", "\n", " print('更新数据后')\n", " print(df.tail(1))\n", " # 使用pandas保存Excel文件\n", " df.to_excel(\"定性模型数据项12-11.xlsx\", index=False, engine='openpyxl')\n", "\n", "\n", "def updateExcelData(date='', token=None):\n", " # 使用pandas读取Excel文件\n", " df = pd.read_excel(read_file_path_name, engine='openpyxl')\n", "\n", " # 获取第一行的数据作为列名\n", " # one_cols = df.columns.tolist()\n", " \n", " # 获取第二行的数据作为列名\n", " one_cols = df.iloc[0,:].tolist()\n", "\n", " cur_time, cur_time2 = getNow(date)\n", " search_data = {\n", " \"data\": {\n", " \"date\": cur_time,\n", " \"dataItemNoList\": one_cols[1:]\n", " },\n", " \"funcModule\": \"数据项\",\n", " \"funcOperation\": \"查询\"\n", " }\n", " headers = {\"Authorization\": token}\n", " search_res = requests.post(url=search_url, headers=headers, json=search_data, timeout=(3, 5))\n", " search_value = json.loads(search_res.text)[\"data\"]\n", " if search_value:\n", " datas = search_value\n", " else:\n", " datas = None\n", "\n", " append_rows = [cur_time2]\n", " dataItemNo_dataValue = {}\n", " for data_value in datas:\n", " if \"dataValue\" not in data_value:\n", " print(data_value)\n", " dataItemNo_dataValue[data_value[\"dataItemNo\"]] = \"\"\n", " else:\n", " dataItemNo_dataValue[data_value[\"dataItemNo\"]] = data_value[\"dataValue\"]\n", " for value in one_cols[1:]:\n", " if value in dataItemNo_dataValue:\n", " append_rows.append(dataItemNo_dataValue[value])\n", " else:\n", " append_rows.append(\"\")\n", "\n", " # 将新的数据添加到DataFrame中\n", " new_row = pd.DataFrame([append_rows], columns=df.columns.tolist())\n", " df = pd.concat([df, new_row], ignore_index=True)\n", " # df = df.append(pd.Series(append_rows), ignore_index=True)\n", "\n", " # 使用pandas保存Excel文件\n", " df.to_excel(\"定性模型数据项12-11.xlsx\", index=False, engine='openpyxl')\n", "\n", "\n", "def qualitativeModel():\n", " df = pd.read_excel('定性模型数据项12-11.xlsx')\n", "\n", " df=df.fillna(df.ffill())\n", " df1 = df[-3:-1].reset_index()\n", " print(df1)\n", " '''\n", " # if df1.loc[1,'70号沥青开工率'] > 0.3: \n", " 2025年1月8日 修改:\n", " 复盘分析后发现2024-7月开始,开工率数据从0.28 变为了28 ,改为下面的判断规则\n", " '''\n", " if df1.loc[1,'70号沥青开工率'] / 100 > 0.3:\n", " a = -(df1.loc[1,'70号沥青开工率'] / 100 -0.2)*5/0.1\n", " else :\n", " a = 0\n", " b = df1.loc[1,'资金因素']\n", " \n", " print('昨日计划提货偏差改之前',df1.loc[1,'昨日计划提货偏差'])\n", " # 昨日计划提货偏差 = 京博产量 - 计划产量\n", " df1.loc[1,'昨日计划提货偏差'] = df1.loc[1,'京博产量'] - df1.loc[1,'计划产量']\n", " \n", " print('昨日计划提货偏差改之后',df1.loc[1,'昨日计划提货偏差'])\n", " if df1.loc[1,'昨日计划提货偏差']>0:\n", " c = df1.loc[1,'昨日计划提货偏差']*10/2000\n", " else :\n", " c = df1.loc[1,'昨日计划提货偏差']*10/3000\n", " \n", " # 生产情况 = (京博产量 - 计划产量)/500*5\n", " d = (df1.loc[1,'京博产量'] - df1.loc[1,'计划产量']) / 500 * 5\n", " \n", " if df1.loc[1,'基质沥青库存']/265007 >0.8:\n", " e = (df1.loc[1,'基质沥青库存'] - df1.loc[0,'基质沥青库存'])*10/-5000\n", " else : \n", " e = 0\n", "# f = df1.loc[1,'下游客户价格预期']\n", " f = 1 # 2025年1月23日修改:价格预期都按1计算\n", " if abs(df1.loc[1,'即期成本'] - df1.loc[0,'即期成本'])>=100:\n", " g = (df1.loc[1,'即期成本'] - df1.loc[0,'即期成本'])*50/100\n", " else :\n", " g = 0\n", " h = df1.loc[1,'订单结构']\n", " x = round(0.08*a+0*b+0.15*c+0.08*d +0.03*e +0.08*f +0.4*g+0.18*h+df1.loc[0,'京博指导价'],2)\n", " return x\n", "\n", "\n", "def getNow(date='',offset=0):\n", " if date == '':\n", " now = datetime.now() - timedelta(days=offset)\n", " else:\n", " try:\n", " date = datetime.strptime(date, \"%Y-%m-%d\")\n", " except:\n", " date = datetime.strptime(date, \"%Y%m%d\")\n", " now = date\n", "\n", " year = now.year\n", " month = now.month\n", " day = now.day\n", "\n", " if month < 10:\n", " month = \"0\" + str(month)\n", " if day < 10:\n", " day = \"0\" + str(day)\n", " cur_time = str(year) + str(month) + str(day)\n", " cur_time2 = str(year) + \"-\" + str(month) + \"-\" + str(day)\n", " return cur_time,cur_time2\n", "\n", "def pushData(cur_time,x,token_push):\n", " data1 = {\n", " \"funcModule\": \"数据表信息列表\",\n", " \"funcOperation\": \"新增\",\n", " \"data\": [\n", " {\"dataItemNo\": \"C01100036|Forecast_Price|DX|ACN\",\n", " \"dataDate\": cur_time,\n", " \"dataStatus\": \"add\",\n", " \"dataValue\": x\n", " }\n", " ]\n", " }\n", " headers1 = {\"Authorization\": token_push}\n", " res = requests.post(url=upload_url, headers=headers1, json=data1, timeout=(3, 5))\n", " \n", "def start_2(date='',token=None):\n", " workbook = xlrd.open_workbook(read_file_path_name)\n", "\n", " # 选择第一个表格\n", " sheet = workbook.sheet_by_index(0)\n", "\n", " # 获取行数和列数\n", " num_rows = sheet.nrows\n", " \n", " row_data = sheet.row_values(1)\n", " one_cols = row_data\n", "\n", " cur_time,cur_time2 = getNow(date)\n", " \n", " \n", " \n", " search_data = {\n", " \"data\": {\n", " \"date\": cur_time,\n", " \"dataItemNoList\": one_cols[1:]\n", " },\n", " \"funcModule\": \"数据项\",\n", " \"funcOperation\": \"查询\"\n", " }\n", " headers = {\"Authorization\": token}\n", " search_res = requests.post(url=search_url, headers=headers, json=search_data, timeout=(3, 5))\n", " search_value = json.loads(search_res.text)[\"data\"]\n", "# datas = search_value\n", " if search_value:\n", " datas = search_value\n", " else :\n", " datas = None\n", " \n", "\n", " append_rows = [cur_time2]\n", " dataItemNo_dataValue = {}\n", "# for data_value in datas:\n", "# dataItemNo_dataValue[data_value[\"dataItemNo\"]] = data_value[\"dataValue\"]\n", " for data_value in datas:\n", " if \"dataValue\" not in data_value:\n", " print(data_value)\n", " dataItemNo_dataValue[data_value[\"dataItemNo\"]] = \"\"\n", " else:\n", " dataItemNo_dataValue[data_value[\"dataItemNo\"]] = data_value[\"dataValue\"]\n", " for value in one_cols[1:]:\n", " if value in dataItemNo_dataValue:\n", " append_rows.append(dataItemNo_dataValue[value])\n", " else:\n", " append_rows.append(\"\")\n", "\n", " workbook = xlrd.open_workbook('定性模型数据项12-11.xlsx')\n", "\n", " # 获取所有sheet的个数\n", " sheet_count = len(workbook.sheet_names())\n", "\n", " # 获取所有sheet的名称\n", " sheet_names = workbook.sheet_names()\n", "\n", " new_workbook = xlwt.Workbook()\n", " for i in range(sheet_count):\n", " # 获取当前sheet\n", " sheet = workbook.sheet_by_index(i)\n", "\n", " # 获取sheet的行数和列数\n", " row_count = sheet.nrows\n", " col_count = sheet.ncols\n", " # 获取原有数据\n", " data = []\n", " for row in range(row_count):\n", " row_data = []\n", " for col in range(col_count):\n", " row_data.append(sheet.cell_value(row, col))\n", " data.append(row_data)\n", " # 创建xlwt的Workbook对象\n", " # 创建sheet\n", " new_sheet = new_workbook.add_sheet(sheet_names[i])\n", "\n", " # 将原有的数据写入新的sheet\n", " for row in range(row_count):\n", " for col in range(col_count):\n", " new_sheet.write(row, col, data[row][col])\n", "\n", " if i == 0:\n", " \n", " # 在新的sheet中添加数据\n", " for col in range(col_count):\n", " new_sheet.write(row_count, col, append_rows[col])\n", "\n", " # 保存新的xls文件\n", " new_workbook.save(\"定性模型数据项12-11.xlsx\")\n", "\n", " update_e_value('定性模型数据项12-11.xlsx', 8, 1000)\n", "\n", " df = pd.read_excel('定性模型数据项12-11.xlsx')\n", "\n", " df=df.fillna(df.ffill())\n", " df1 = df[-2:].reset_index()\n", " '''\n", " # if df1.loc[1,'70号沥青开工率'] > 0.3: \n", " 2025年1月8日 修改:\n", " 复盘分析后发现2024-7月开始,开工率数据从0.28 变为了28 ,改为下面的判断规则\n", " '''\n", " if df1.loc[1,'70号沥青开工率'] > 30:\n", " a = (df1.loc[1,'70号沥青开工率']-0.2)*5/0.1\n", " else :\n", " a = 0\n", " b = df1.loc[1,'资金因素']\n", " if df1.loc[1,'昨日计划提货偏差']>0:\n", " c = df1.loc[1,'昨日计划提货偏差']*10/2000\n", " else :\n", " c = df1.loc[1,'昨日计划提货偏差']*10/3000\n", " d = df1.loc[1,'生产情况']\n", " if df1.loc[1,'基质沥青库存']/265007 >0.8:\n", " e = (df1.loc[1,'基质沥青库存'] - df1.loc[0,'基质沥青库存'])*10/-5000\n", " else : \n", " e = 0\n", "# f = df1.loc[1,'下游客户价格预期']\n", " f = 1 # 2025年1月23日修改:价格预期都按1计算\n", " if abs(df1.loc[1,'即期成本'] - df1.loc[0,'即期成本'])>=100:\n", " g = (df1.loc[1,'即期成本'] - df1.loc[0,'即期成本'])*50/100\n", " else :\n", " g = 0\n", " h = df1.loc[1,'订单结构']\n", " x = round(0.08*a+0*b+0.15*c+0.08*d +0.03*e +0.08*f +0.4*g+0.18*h+df1.loc[0,'京博指导价'],2)\n", "\n", " login_res1 = requests.post(url=login_push_url, json=login_push_data, timeout=(3, 5))\n", " text1 = json.loads(login_res1.text)\n", " token_push = text1[\"data\"][\"accessToken\"]\n", "\n", "\n", " data1 = {\n", " \"funcModule\": \"数据表信息列表\",\n", " \"funcOperation\": \"新增\",\n", " \"data\": [\n", " {\"dataItemNo\": \"C01100036|Forecast_Price|DX|ACN\",\n", " \"dataDate\": cur_time,\n", " \"dataStatus\": \"add\",\n", " \"dataValue\": x\n", " }\n", "\n", " ]\n", " }\n", " headers1 = {\"Authorization\": token_push}\n", " # res = requests.post(url=upload_url, headers=headers1, json=data1, timeout=(3, 5))\n", " \n", "\n", "def start(now=None):\n", " workbook = xlrd.open_workbook(read_file_path_name)\n", "\n", "\n", "\n", " # 选择第一个表格\n", " sheet = workbook.sheet_by_index(0)\n", "\n", " # 获取行数和列数\n", " num_rows = sheet.nrows\n", "\n", "\n", "\n", " row_data = sheet.row_values(1)\n", " one_cols = row_data\n", "\n", "\n", " login_res = requests.post(url=login_url, json=login_data, timeout=(3, 5))\n", " text = json.loads(login_res.text)\n", " if text[\"status\"]:\n", " token = text[\"data\"][\"accessToken\"]\n", " else:\n", " print(\"获取认证失败\")\n", " token = None\n", "\n", " if now is None:\n", " now = datetime.now()\n", " year = now.year\n", " month = now.month\n", " day = now.day\n", "\n", " if month < 10:\n", " month = \"0\" + str(month)\n", " if day < 10:\n", " day = \"0\" + str(day)\n", " cur_time = str(year) + str(month) + str(day)\n", " cur_time2 = str(year) + \"-\" + str(month) + \"-\" + str(day)\n", " search_data = {\n", " \"data\": {\n", " \"date\": cur_time,\n", " \"dataItemNoList\": one_cols[1:]\n", " },\n", " \"funcModule\": \"数据项\",\n", " \"funcOperation\": \"查询\"\n", " }\n", " headers = {\"Authorization\": token}\n", " search_res = requests.post(url=search_url, headers=headers, json=search_data, timeout=(3, 5))\n", " search_value = json.loads(search_res.text)[\"data\"]\n", "# datas = search_value\n", " if search_value:\n", " datas = search_value\n", " else :\n", " datas = None\n", " \n", "\n", " append_rows = [cur_time2]\n", " dataItemNo_dataValue = {}\n", "# for data_value in datas:\n", "# dataItemNo_dataValue[data_value[\"dataItemNo\"]] = data_value[\"dataValue\"]\n", " for data_value in datas:\n", " if \"dataValue\" not in data_value:\n", " print(data_value)\n", " dataItemNo_dataValue[data_value[\"dataItemNo\"]] = \"\"\n", " else:\n", " dataItemNo_dataValue[data_value[\"dataItemNo\"]] = data_value[\"dataValue\"]\n", " for value in one_cols[1:]:\n", " if value in dataItemNo_dataValue:\n", " append_rows.append(dataItemNo_dataValue[value])\n", " else:\n", " append_rows.append(\"\")\n", "\n", " workbook = xlrd.open_workbook('定性模型数据项12-11.xlsx')\n", "\n", " # 获取所有sheet的个数\n", " sheet_count = len(workbook.sheet_names())\n", "\n", " # 获取所有sheet的名称\n", " sheet_names = workbook.sheet_names()\n", "\n", " new_workbook = xlwt.Workbook()\n", " for i in range(sheet_count):\n", " # 获取当前sheet\n", " sheet = workbook.sheet_by_index(i)\n", "\n", " # 获取sheet的行数和列数\n", " row_count = sheet.nrows\n", " col_count = sheet.ncols\n", " # 获取原有数据\n", " data = []\n", " for row in range(row_count):\n", " row_data = []\n", " for col in range(col_count):\n", " row_data.append(sheet.cell_value(row, col))\n", " data.append(row_data)\n", " # 创建xlwt的Workbook对象\n", " # 创建sheet\n", " new_sheet = new_workbook.add_sheet(sheet_names[i])\n", "\n", " # 将原有的数据写入新的sheet\n", " for row in range(row_count):\n", " for col in range(col_count):\n", " new_sheet.write(row, col, data[row][col])\n", "\n", " if i == 0:\n", " # 在新的sheet中添加数据\n", " for col in range(col_count):\n", " new_sheet.write(row_count, col, append_rows[col])\n", "\n", " # 保存新的xls文件\n", " new_workbook.save(\"定性模型数据项12-11.xlsx\")\n", " \n", " \n", " update_e_value('定性模型数据项12-11.xlsx', 8, 1000)\n", "\n", " df = pd.read_excel('定性模型数据项12-11.xlsx')\n", " df=df.fillna(df.ffill())\n", " df1 = df[-2:].reset_index()\n", " print(df1)\n", " # if df1.loc[1,'70号沥青开工率'] > 0.3: -- 2025年1月9日 发版更改\n", " if df1.loc[1,'70号沥青开工率'] / 100 > 0.3:\n", " a = (df1.loc[1,'70号沥青开工率'] / 100 -0.2)*5/0.1\n", " else :\n", " a = 0\n", " b = df1.loc[1,'资金因素']\n", " if df1.loc[1,'昨日计划提货偏差']>0:\n", " c = df1.loc[1,'昨日计划提货偏差']*10/2000\n", " else :\n", " c = df1.loc[1,'昨日计划提货偏差']*10/3000\n", " d = df1.loc[1,'生产情况']\n", " if df1.loc[1,'基质沥青库存']/265007 >0.8:\n", " e = (df1.loc[1,'基质沥青库存'] - df1.loc[0,'基质沥青库存'])*10/-5000\n", " else : \n", " e = 0\n", "# f = df1.loc[1,'下游客户价格预期']\n", " f = 1 # 2025年1月23日修改:价格预期都按1计算\n", " if abs(df1.loc[1,'即期成本'] - df1.loc[0,'即期成本'])>=100:\n", " g = (df1.loc[1,'即期成本'] - df1.loc[0,'即期成本'])*50/100\n", " else :\n", " g = 0\n", " h = df1.loc[1,'订单结构']\n", " x = round(0.08*a+0*b+0.15*c+0.08*d +0.03*e +0.08*f +0.4*g+0.18*h+df1.loc[0,'京博指导价'],2)\n", " \n", "\n", " # login_res1 = requests.post(url=login_url, json=login_data, timeout=(3, 30))\n", " # text1 = json.loads(login_res1.text)\n", " # token_push = text1[\"data\"][\"accessToken\"]\n", "\n", "\n", " # data1 = {\n", " # \"funcModule\": \"数据表信息列表\",\n", " # \"funcOperation\": \"新增\",\n", " # \"data\": [\n", " # {\"dataItemNo\": \"C01100036|Forecast_Price|DX|ACN\",\n", " # \"dataDate\": cur_time,\n", " # \"dataStatus\": \"add\",\n", " # \"dataValue\": x\n", " # }\n", "\n", " # ]\n", " # }\n", " # headers1 = {\"Authorization\": token_push}\n", " # res = requests.post(url=upload_url, headers=headers1, json=data1, timeout=(3, 5))\n", " \n", "\n", "\n", "def start_test():\n", " workbook = xlrd.open_workbook(read_file_path_name)\n", "\n", "\n", "\n", " # 选择第一个表格\n", " sheet = workbook.sheet_by_index(0)\n", "\n", " # 获取行数和列数\n", " num_rows = sheet.nrows\n", "\n", "\n", "\n", " row_data = sheet.row_values(1)\n", " one_cols = row_data\n", "\n", "\n", " login_res = requests.post(url=login_url, json=login_data, timeout=(3, 5))\n", " text = json.loads(login_res.text)\n", " if text[\"status\"]:\n", " token = text[\"data\"][\"accessToken\"]\n", " else:\n", " print(\"获取认证失败\")\n", " token = None\n", "\n", "\n", " now = datetime.now()\n", " year = now.year\n", " month = now.month\n", " day = now.day\n", "\n", " if month < 10:\n", " month = \"0\" + str(month)\n", " if day < 10:\n", " day = \"0\" + str(day)\n", " cur_time = str(year) + str(month) + str(day)\n", " cur_time2 = str(year) + \"-\" + str(month) + \"-\" + str(day)\n", " search_data = {\n", " \"data\": {\n", " \"date\": cur_time,\n", " \"dataItemNoList\": one_cols[1:]\n", " },\n", " \"funcModule\": \"数据项\",\n", " \"funcOperation\": \"查询\"\n", " }\n", " headers = {\"Authorization\": token}\n", " search_res = requests.post(url=search_url, headers=headers, json=search_data, timeout=(3, 5))\n", " search_value = json.loads(search_res.text)[\"data\"]\n", "# datas = search_value\n", " if search_value:\n", " datas = search_value\n", " else :\n", " datas = None\n", " \n", "\n", " append_rows = [cur_time2]\n", " dataItemNo_dataValue = {}\n", "# for data_value in datas:\n", "# dataItemNo_dataValue[data_value[\"dataItemNo\"]] = data_value[\"dataValue\"]\n", " for data_value in datas:\n", " if \"dataValue\" not in data_value:\n", " print(data_value)\n", " dataItemNo_dataValue[data_value[\"dataItemNo\"]] = \"\"\n", " else:\n", " dataItemNo_dataValue[data_value[\"dataItemNo\"]] = data_value[\"dataValue\"]\n", " for value in one_cols[1:]:\n", " if value in dataItemNo_dataValue:\n", " append_rows.append(dataItemNo_dataValue[value])\n", " else:\n", " append_rows.append(\"\")\n", "\n", " workbook = xlrd.open_workbook('定性模型数据项12-11.xlsx')\n", "\n", " # 获取所有sheet的个数\n", " sheet_count = len(workbook.sheet_names())\n", "\n", " # 获取所有sheet的名称\n", " sheet_names = workbook.sheet_names()\n", "\n", " new_workbook = xlwt.Workbook()\n", " for i in range(sheet_count):\n", " # 获取当前sheet\n", " sheet = workbook.sheet_by_index(i)\n", "\n", " # 获取sheet的行数和列数\n", " row_count = sheet.nrows\n", " col_count = sheet.ncols\n", " # 获取原有数据\n", " data = []\n", " for row in range(row_count):\n", " row_data = []\n", " for col in range(col_count):\n", " row_data.append(sheet.cell_value(row, col))\n", " data.append(row_data)\n", " # 创建xlwt的Workbook对象\n", " # 创建sheet\n", " new_sheet = new_workbook.add_sheet(sheet_names[i])\n", "\n", " # 将原有的数据写入新的sheet\n", " for row in range(row_count):\n", " for col in range(col_count):\n", " new_sheet.write(row, col, data[row][col])\n", "\n", " if i == 0:\n", " # 在新的sheet中添加数据\n", " for col in range(col_count):\n", " new_sheet.write(row_count, col, append_rows[col])\n", "\n", " # 保存新的xls文件\n", " new_workbook.save(\"定性模型数据项12-11.xlsx\")\n", " \n", " update_e_value('定性模型数据项12-11.xlsx', 8, 1000)\n", "\n", " df = pd.read_excel('定性模型数据项12-11.xlsx')\n", " df=df.fillna(df.ffill())\n", " df1 = df[-2:].reset_index()\n", " # if df1.loc[1,'70号沥青开工率'] > 0.3: -- 2025年1月9日 发版更改\n", " if df1.loc[1,'70号沥青开工率'] / 100 > 0.3:\n", " a = (df1.loc[1,'70号沥青开工率'] / 100 -0.2)*5/0.1\n", " else :\n", " a = 0\n", " b = df1.loc[1,'资金因素']\n", " if df1.loc[1,'昨日计划提货偏差']>0:\n", " c = df1.loc[1,'昨日计划提货偏差']*10/2000\n", " else :\n", " c = df1.loc[1,'昨日计划提货偏差']*10/3000\n", " d = df1.loc[1,'生产情况']\n", " if df1.loc[1,'基质沥青库存']/265007 >0.8:\n", " e = (df1.loc[1,'基质沥青库存'] - df1.loc[0,'基质沥青库存'])*10/-5000\n", " else : \n", " e = 0\n", "# f = df1.loc[1,'下游客户价格预期']\n", " f = 1 # 2025年1月23日修改:价格预期都按1计算\n", " if abs(df1.loc[1,'即期成本'] - df1.loc[0,'即期成本'])>=100:\n", " g = (df1.loc[1,'即期成本'] - df1.loc[0,'即期成本'])*50/100\n", " else :\n", " g = 0\n", " h = df1.loc[1,'订单结构']\n", " x = round(0.08*a+0*b+0.15*c+0.08*d +0.03*e +0.08*f +0.4*g+0.18*h+df1.loc[0,'京博指导价'],2)\n", " \n", "\n", " # login_res1 = requests.post(url=login_url, json=login_data, timeout=(3, 30))\n", " # text1 = json.loads(login_res1.text)\n", " # token_push = text1[\"data\"][\"accessToken\"]\n", "\n", "\n", " # data1 = {\n", " # \"funcModule\": \"数据表信息列表\",\n", " # \"funcOperation\": \"新增\",\n", " # \"data\": [\n", " # {\"dataItemNo\": \"C01100036|Forecast_Price|DX|ACN\",\n", " # \"dataDate\": cur_time,\n", " # \"dataStatus\": \"add\",\n", " # \"dataValue\": x\n", " # }\n", "\n", " # ]\n", " # }\n", " # headers1 = {\"Authorization\": token_push}\n", " # res = requests.post(url=upload_url, headers=headers1, json=data1, timeout=(3, 5))\n", " \n", "\n", "\n", "\n", "\n", "def start_1():\n", " workbook = xlrd.open_workbook(read_file_path_name)\n", "\n", "\n", "\n", " # 选择第一个表格\n", " sheet = workbook.sheet_by_index(0)\n", "\n", " # 获取行数和列数\n", " num_rows = sheet.nrows\n", "\n", "\n", "\n", " row_data = sheet.row_values(1)\n", " one_cols = row_data\n", "\n", "\n", " login_res = requests.post(url=login_url, json=login_data, timeout=(3, 5))\n", " text = json.loads(login_res.text)\n", " if text[\"status\"]:\n", " token = text[\"data\"][\"accessToken\"]\n", " else:\n", " print(\"获取认证失败\")\n", " token = None\n", "\n", "\n", " now = datetime.now() - timedelta(days=1) \n", " year = now.year\n", " month = now.month\n", " day = now.day\n", "\n", " if month < 10:\n", " month = \"0\" + str(month)\n", " if day < 10:\n", " day = \"0\" + str(day)\n", " cur_time = str(year) + str(month) + str(day)\n", " cur_time2 = str(year) + \"-\" + str(month) + \"-\" + str(day)\n", " search_data = {\n", " \"data\": {\n", " \"date\": cur_time,\n", " \"dataItemNoList\": one_cols[1:]\n", " },\n", " \"funcModule\": \"数据项\",\n", " \"funcOperation\": \"查询\"\n", " }\n", " headers = {\"Authorization\": token}\n", " search_res = requests.post(url=search_url, headers=headers, json=search_data, timeout=(3, 5))\n", " search_value = json.loads(search_res.text)[\"data\"]\n", "# datas = search_value\n", " if search_value:\n", " datas = search_value\n", " else :\n", " datas = None\n", " \n", " \n", "\n", " append_rows = [cur_time2]\n", " dataItemNo_dataValue = {}\n", "# for data_value in datas:\n", "# dataItemNo_dataValue[data_value[\"dataItemNo\"]] = data_value[\"dataValue\"]\n", " for data_value in datas:\n", " if \"dataValue\" not in data_value:\n", " print(data_value)\n", " dataItemNo_dataValue[data_value[\"dataItemNo\"]] = \"\"\n", " else:\n", " dataItemNo_dataValue[data_value[\"dataItemNo\"]] = data_value[\"dataValue\"]\n", " for value in one_cols[1:]:\n", " if value in dataItemNo_dataValue:\n", " append_rows.append(dataItemNo_dataValue[value])\n", " else:\n", " append_rows.append(\"\")\n", "\n", " workbook = xlrd.open_workbook('定性模型数据项12-11.xlsx')\n", "\n", " # 获取所有sheet的个数\n", " sheet_count = len(workbook.sheet_names())\n", "\n", " # 获取所有sheet的名称\n", " sheet_names = workbook.sheet_names()\n", "\n", " new_workbook = xlwt.Workbook()\n", " for i in range(sheet_count):\n", " # 获取当前sheet\n", " sheet = workbook.sheet_by_index(i)\n", "\n", " # 获取sheet的行数和列数\n", " row_count = sheet.nrows - 1\n", " col_count = sheet.ncols\n", " # 获取原有数据\n", " data = []\n", " for row in range(row_count):\n", " row_data = []\n", " for col in range(col_count):\n", " row_data.append(sheet.cell_value(row, col))\n", " data.append(row_data)\n", " # 创建xlwt的Workbook对象\n", " # 创建sheet\n", " new_sheet = new_workbook.add_sheet(sheet_names[i])\n", "\n", " # 将原有的数据写入新的sheet\n", " for row in range(row_count):\n", " for col in range(col_count):\n", " new_sheet.write(row, col, data[row][col])\n", "\n", " if i == 0:\n", " # 在新的sheet中添加数据\n", " for col in range(col_count):\n", " new_sheet.write(row_count, col, append_rows[col])\n", "\n", " # 保存新的xls文件\n", " new_workbook.save(\"定性模型数据项12-11.xlsx\")\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "def get_queryDataListItemNos_value(token, url, dataItemNoList, dateStart, dateEnd):\n", "\n", " search_data = {\n", " \"funcModule\": \"数据项\",\n", " \"funcOperation\": \"查询\",\n", " \"data\": {\n", " \"dateStart\": dateStart,\n", " \"dateEnd\": dateEnd,\n", " \"dataItemNoList\": dataItemNoList # 数据项编码,代表 brent最低价和最高价\n", " }\n", " }\n", "\n", " headers = {\"Authorization\": token}\n", " search_res = requests.post(url=url, headers=headers, json=search_data, timeout=(3, 5))\n", " search_value = json.loads(search_res.text)[\"data\"]\n", " if search_value:\n", " return search_value\n", " else:\n", " return None\n", "\n", "\n", "\n", "def save_queryDataListItemNos_xls(data_df,dataItemNoList):\n", "\n", " current_year_month = datetime.now().strftime('%Y-%m')\n", " grouped = data_df.groupby(\"dataDate\")\n", "\n", "\n", " df_old = pd.read_excel('定性模型数据项12-11.xlsx')\n", " df_old0 = df_old[:1]\n", " result_dict = {df_old0.iloc[0][col] : col for col in df_old0.columns}\n", " df_old1 = df_old[1:].copy()\n", "\n", " df_old1[\"日期\"] = pd.to_datetime(df_old1[\"日期\"])\n", " # 删除日期列为本月的数据\n", " df_old1 = df_old1[~df_old1[\"日期\"].dt.strftime('%Y-%m').eq(current_year_month)]\n", " df_old1[\"日期\"] = df_old1[\"日期\"].dt.strftime('%Y-%m-%d')\n", "\n", "\n", " list_data = []\n", " for date, group in grouped:\n", " dict_data = {\"日期\": date}\n", " for index, row in group.iterrows():\n", " dict_data[result_dict[row['dataItemNo']]] = row['dataValue']\n", " list_data.append(dict_data)\n", "\n", " df_current_year_month = pd.DataFrame(list_data)\n", " df_current_year_month\n", "\n", " df_merged = pd.concat([df_old0, df_old1, df_current_year_month], ignore_index=True)\n", "\n", " df_merged.to_excel('定性模型数据项12-11.xlsx', index=False)\n", "\n", "\n", "\n", "def queryDataListItemNos(date=None,token=None):\n", " df = pd.read_excel('定性模型数据项12-11.xlsx')\n", " dataItemNoList = df.iloc[0].tolist()[1:]\n", "\n", " if token is None:\n", " token = getLogToken()\n", " if token is None:\n", " print(\"获取token失败\")\n", " return\n", "\n", " # 获取当前日期\n", " if date is None:\n", " date = datetime.now()\n", " current_date = date\n", "\n", " # 获取当月1日\n", " first_day_of_month = current_date.replace(day=1)\n", "\n", " # 格式化为 YYYYMMDD 格式\n", " dateEnd = current_date.strftime('%Y%m%d')\n", " dateStart = first_day_of_month.strftime('%Y%m%d')\n", "\n", " search_value = get_queryDataListItemNos_value(token, queryDataListItemNos_url, dataItemNoList, dateStart, dateEnd)\n", " # print(\"search_value\",search_value)\n", "\n", "\n", " data_df = pd.DataFrame(search_value)\n", "\n", " data_df[\"dataDate\"] = pd.to_datetime(data_df[\"dataDate\"])\n", " data_df[\"dataDate\"] = data_df[\"dataDate\"].dt.strftime('%Y-%m-%d')\n", " save_queryDataListItemNos_xls(data_df,dataItemNoList)\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", " updateExcelData(date,token)\n", " queryDataListItemNos(token=token)\n", " update_e_value('定性模型数据项12-11.xlsx', 8, 1000)\n", " x = qualitativeModel()\n", " print('**************************************************预测结果:',x)\n", " cur_time,cur_time2 = getNow(date)\n", " pushData(cur_time,x,token)\n", "\n" ] }, { "cell_type": "code", "execution_count": 44, "metadata": {}, "outputs": [], "source": [ "### 原始代码备份\n", "\n", "if __name__ == \"__main__\":\n", " pass\n", "\n", " # 需要单独运行放开\n", " # start_1()\n", " # start()\n", "\n", "\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", "\n", "\n", "\n", "\n", "\n", " # # 判断当前时间是否为执行任务的时间点\n", " # if current_time == \"12:00:00\":\n", " # print(\"执行定时任务\")\n", " # start()\n", "\n", " # # 休眠1秒钟,避免过多占用CPU资源\n", " # time.sleep(1)\n", " \n", " # elif current_time_1 == \"20:00:00\":\n", " # print(\"更新数据\")\n", " # start_1()\n", " # time.sleep(1)" ] }, { "cell_type": "code", "execution_count": 45, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "运行中...\n", "20250408\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "C:\\Users\\EDY\\AppData\\Local\\Temp\\ipykernel_25972\\2961115944.py:99: 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_25972\\2961115944.py:103: 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" ] }, { "name": "stdout", "output_type": "stream", "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 107945.963078 \n", "\n", " 下游客户价格预期 即期成本 订单结构 计划产量 京博产量 \n", "1399 3630.0 3136.0033 1.0 4982.8366 5715.5175 \n", "1400 3630.0 2972.5098 1.0 4982.8366 5522.676 \n", "前一天的 3136.0033 \n", "现在的 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 107945.963078 \n", "\n", " 下游客户价格预期 即期成本 订单结构 计划产量 京博产量 \n", "0 3630 3136.0033 1 4982.8366 5715.5175 \n", "1 3630 2972.5098 1 4982.8366 5522.676 \n", "昨日计划提货偏差改之前 478.28\n", "昨日计划提货偏差改之后 539.8394000000008\n", "**************************************************预测结果: 3567.73\n", "更新前一天数据\n", "更新数据前\n", " 日期 京博指导价 70号沥青开工率 资金因素 昨日计划提货偏差 生产情况 基质沥青库存 下游客户价格预期 \\\n", "1401 2025-04-08 3450 36.784 1 478.28 6000 107945.963078 3630 \n", "\n", " 即期成本 订单结构 计划产量 京博产量 \n", "1401 3096.5238 1 4982.8366 5522.676 \n", "日期存在,即将更新\n", "新数据 [3500.0, 36.784, '', 478.28, '', 107945.9630779, '', 2972.5098, '', 4982.8366, 5522.676]\n", "更新数据后\n", " 日期 京博指导价 70号沥青开工率 资金因素 昨日计划提货偏差 生产情况 基质沥青库存 下游客户价格预期 \\\n", "1401 2025-04-08 3450 36.784 1 478.28 6000 107945.963078 3630 \n", "\n", " 即期成本 订单结构 计划产量 京博产量 \n", "1401 3096.5238 1 4982.8366 5522.676 \n" ] }, { "ename": "KeyboardInterrupt", "evalue": "", "output_type": "error", "traceback": [ "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[1;31mKeyboardInterrupt\u001b[0m Traceback (most recent call last)", "Cell \u001b[1;32mIn[45], line 15\u001b[0m\n\u001b[0;32m 13\u001b[0m token \u001b[38;5;241m=\u001b[39m getLogToken()\n\u001b[0;32m 14\u001b[0m updateYesterdayExcelData(token\u001b[38;5;241m=\u001b[39mtoken)\n\u001b[1;32m---> 15\u001b[0m time\u001b[38;5;241m.\u001b[39msleep(\u001b[38;5;241m1\u001b[39m)\n\u001b[0;32m 16\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m \u001b[38;5;167;01mException\u001b[39;00m \u001b[38;5;28;01mas\u001b[39;00m e:\n\u001b[0;32m 17\u001b[0m \u001b[38;5;28mprint\u001b[39m(\u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m执行失败: \u001b[39m\u001b[38;5;132;01m{\u001b[39;00me\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m\"\u001b[39m)\n", "\u001b[1;31mKeyboardInterrupt\u001b[0m: " ] } ], "source": [ "if __name__ == \"__main__\":\n", " print(\"运行中...\")\n", " # 每天定时12点运行\n", " while True:\n", " # 获取当前时间\n", " current_time = time.strftime(\"%H:%M:%S\", time.localtime())\n", " try:\n", " # 判断当前时间是否为执行任务的时间点\n", " if current_time == \"12:00:00\":\n", " main()\n", " elif current_time == \"20:00:00\":\n", " print(\"更新前一天数据\")\n", " token = getLogToken()\n", " updateYesterdayExcelData(token=token)\n", " time.sleep(1)\n", " except Exception as e:\n", " print(f\"执行失败: {e}\")" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# # 重新上传定性数据\n", "\n", "\n", "\n", "# start_date = datetime(2025, 4, 1)\n", "# end_date = datetime(2025, 4, 2)\n", "# token = getLogToken()\n", "# while start_date < end_date:\n", "# main(start_date,token)\n", "# start_date += timedelta(days=1)\n", "# time.sleep(5)\n", " \n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# # 调试更新数据\n", "# date = '2025-01-24'\n", "# token = getLogToken()\n", "# updateYesterdayExcelData(date=date,token=token)\n", "# print('更新完了')" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# # 快速调试线上\n", "# def main():\n", "# # 获取当前日期\n", "# date = datetime.now().date()\n", "# date = date.strftime('%Y%m%d')\n", "# # 获取登录token\n", "# token = getLogToken()\n", "# updateExcelData(date,token)\n", "# update_e_value('定性模型数据项12-11.xlsx', 8, 1000)\n", "# x = qualitativeModel()\n", "# print('预测结果:',x)\n", "# cur_time,cur_time2 = getNow(date)\n", "# pushData(cur_time,x,token)\n", "\n", "# current_time = time.strftime(\"%H:%M:%S\", time.localtime())\n", "# main()\n", "# token = getLogToken()\n", "# updateYesterdayExcelData(token=token)" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "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": 4 }