{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "31c0e11d-c87a-4e95-92a0-d1d09625e255", "metadata": {}, "outputs": [], "source": [ "from config_jingbo import *\n", "import requests\n", "import json\n", "import datetime" ] }, { "cell_type": "code", "execution_count": 2, "id": "83c81b9e", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'http://192.168.100.53:8080/jingbo-dev/api/server/login'" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "login_pushreport_url\n" ] }, { "cell_type": "code", "execution_count": null, "id": "a058f507", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": 3, "id": "2b330ee3-c006-4ab1-8558-59c51ac8d86f", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'data': {'account': 'api_test',\n", " 'password': 'ZTEwYWRjMzk0OWJhNTlhYmJlNTZlMDU3ZjIwZjg4M2U=',\n", " 'tenantHashCode': '8a4577dbd919675758d57999a1e891fe',\n", " 'terminal': 'API'},\n", " 'funcModule': 'API',\n", " 'funcOperation': '获取token'}" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "login_data" ] }, { "cell_type": "code", "execution_count": 4, "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": 5, "id": "22c0c7c4", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "{'confirmFlg': False, 'data': {'accessToken': 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJhcGlfdGVzdCIsInRoIjoiOGE0NTc3ZGJkOTE5Njc1NzU4ZDU3OTk5YTFlODkxZmUiLCJsdCI6ImFwaSIsImlzcyI6IiIsInRtIjoiUEMiLCJleHAiOjE3MzM3NjQxODAsImp0aSI6IjEzYWRlMTljYzg2OTQ4ODk4YjFiY2FkNTVmODEyZDI3In0.hx0thhOdqnjhFDWkJF0ZdCAK9qwAv5HB15gO7o5mXbY', 'md5Token': '22e1a4c6206d348848cb2fac1ed67312'}, 'status': True}\n" ] } ], "source": [ "token = get_head_auth_report()" ] }, { "cell_type": "code", "execution_count": 6, "id": "12077ead", "metadata": {}, "outputs": [], "source": [ "# token = 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJhcGlfdGVzdCIsInRoIjoiOGE0NTc3ZGJkOTE5Njc1NzU4ZDU3OTk5YTFlODkxZmUiLCJsdCI6ImFwaSIsImlzcyI6IiIsInRtIjoiUEMiLCJleHAiOjE3MzE5NTkzNjUsImp0aSI6IjRiMjcwNTgzN2YyZDQxOWM4MzQ3NjI2NDQwZDlhZGQzIn0.PPgnoiJt412dJiceqVW8w7qkJFY4s-VqU9z6ZIkpqho'" ] }, { "cell_type": "code", "execution_count": 10, "id": "a7ae21d1", "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "上传预警信息\n", "INFO:my_logger:上传预警信息\n", "预警上传中...\n", "INFO:my_logger:预警上传中...\n", "token:eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJhcGlfdGVzdCIsInRoIjoiOGE0NTc3ZGJkOTE5Njc1NzU4ZDU3OTk5YTFlODkxZmUiLCJsdCI6ImFwaSIsImlzcyI6IiIsInRtIjoiUEMiLCJleHAiOjE3MzM3Njg3NjMsImp0aSI6ImEzYTMwMGNmZjRkNzRiYjY5YTFhMWI0ODMzMjYzOWJmIn0.xPmT4E0ckxfNZbcBEsnTzU8zzxij8zvROBpXeTZMn_U\n", "INFO:my_logger:token:eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJhcGlfdGVzdCIsInRoIjoiOGE0NTc3ZGJkOTE5Njc1NzU4ZDU3OTk5YTFlODkxZmUiLCJsdCI6ImFwaSIsImlzcyI6IiIsInRtIjoiUEMiLCJleHAiOjE3MzM3Njg3NjMsImp0aSI6ImEzYTMwMGNmZjRkNzRiYjY5YTFhMWI0ODMzMjYzOWJmIn0.xPmT4E0ckxfNZbcBEsnTzU8zzxij8zvROBpXeTZMn_U\n", "warning_data:{'funcModule': '原油特征停更预警', 'funcOperation': '原油特征停更预警', 'data': {'WARNING_TYPE_NAME': '特征数据停更预警', 'WARNING_CONTENT': '2024-12-09有30个停更', 'WARNING_DATE': '2024-12-09'}}\n", "INFO:my_logger:warning_data:{'funcModule': '原油特征停更预警', 'funcOperation': '原油特征停更预警', 'data': {'WARNING_TYPE_NAME': '特征数据停更预警', 'WARNING_CONTENT': '2024-12-09有30个停更', 'WARNING_DATE': '2024-12-09'}}\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "{'confirmFlg': False, 'data': {'accessToken': 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJhcGlfdGVzdCIsInRoIjoiOGE0NTc3ZGJkOTE5Njc1NzU4ZDU3OTk5YTFlODkxZmUiLCJsdCI6ImFwaSIsImlzcyI6IiIsInRtIjoiUEMiLCJleHAiOjE3MzM3Njg3NjMsImp0aSI6ImEzYTMwMGNmZjRkNzRiYjY5YTFhMWI0ODMzMjYzOWJmIn0.xPmT4E0ckxfNZbcBEsnTzU8zzxij8zvROBpXeTZMn_U', 'md5Token': '0d22e2eedf2857a4c5ef80a56b4b6569'}, 'status': True}\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "上传预警信息成功\n", "INFO:my_logger:上传预警信息成功\n" ] } ], "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}有30个停更'\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": null, "id": "54942e1a", "metadata": {}, "outputs": [], "source": [] } ], "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 }