diff --git a/__pycache__/wechat_message.cpython-310.pyc b/__pycache__/wechat_message.cpython-310.pyc new file mode 100644 index 0000000..653d611 Binary files /dev/null and b/__pycache__/wechat_message.cpython-310.pyc differ diff --git a/daily_stock.py b/daily_stock.py new file mode 100644 index 0000000..92f108b --- /dev/null +++ b/daily_stock.py @@ -0,0 +1,38 @@ +import requests + +from wechat_message import send_wechat_message + +stock_url = 'http://push2.eastmoney.com/api/qt/stock/get' +estun_id = '0.002747' + +def get_today_stock(company_id: str): + response = requests.get( + stock_url, + params={'secid': company_id} + ) + + return response.json() + + +if __name__ == '__main__': + stock = get_today_stock(estun_id) + + # 获取真实数据 + current_price = stock['data']['f43'] / 100 + prev_close = stock['data']['f60'] / 100 + + # 计算涨跌幅 + change_percent = (current_price - prev_close) / prev_close * 100 + change_percent_rounded = round(change_percent, 2) + + # 根据涨跌确定颜色 + color = "warning" if change_percent < 0 else "info" + + message = { + "msgtype": "markdown", + "markdown": { + "content": f"📈 **埃斯顿(002747)**\n> 现价: {current_price}\n> 涨跌: {change_percent_rounded}%" + } + } + + send_wechat_message(message) \ No newline at end of file diff --git a/daily_weather.py b/daily_weather.py index 460bccd..707ba6a 100644 --- a/daily_weather.py +++ b/daily_weather.py @@ -1,14 +1,12 @@ import requests -import json from datetime import datetime +from wechat_message import send_wechat_message + weather_url = 'https://p478kygkjw.re.qweatherapi.com/' weather_api_key = '4aa47f183c694aaa812ff018be8270e4' nanjing_location = '101190101' -webhook_url = 'https://qyapi.weixin.qq.com/cgi-bin/webhook/send' -webhook_key = 'f09eb098-f709-4fc6-83b5-4a08a8431b8f' - def get_today_weather(city_location: int): response = requests.get( @@ -37,19 +35,6 @@ def get_today_indices(city_location: int): return response.json() -def send_wechat_message(message: str): - response = requests.post( - webhook_url, - headers={ - "Content-Type": "application/json" - }, - params={'key': webhook_key}, - data=json.dumps(message, ensure_ascii=False).encode('utf-8') - ) - - return response.json() - - if __name__ == '__main__': weather = get_today_weather(nanjing_location) diff --git a/wechat_message.py b/wechat_message.py new file mode 100644 index 0000000..d57e8e0 --- /dev/null +++ b/wechat_message.py @@ -0,0 +1,18 @@ +import requests +import json + +webhook_url = 'https://qyapi.weixin.qq.com/cgi-bin/webhook/send' +webhook_key = 'f09eb098-f709-4fc6-83b5-4a08a8431b8f' + + +def send_wechat_message(message: str): + response = requests.post( + webhook_url, + headers={ + "Content-Type": "application/json" + }, + params={'key': webhook_key}, + data=json.dumps(message, ensure_ascii=False).encode('utf-8') + ) + + return response.json() \ No newline at end of file