feat:增加查询股票信息

This commit is contained in:
2025-10-14 16:50:33 +08:00
parent 9f1b356ee3
commit 449fe40a93
4 changed files with 58 additions and 17 deletions

Binary file not shown.

38
daily_stock.py Normal file
View File

@@ -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> 现价: <font color=\"{color}\">{current_price}</font>\n> 涨跌: <font color=\"{color}\">{change_percent_rounded}%</font>"
}
}
send_wechat_message(message)

View File

@@ -1,14 +1,12 @@
import requests import requests
import json
from datetime import datetime from datetime import datetime
from wechat_message import send_wechat_message
weather_url = 'https://p478kygkjw.re.qweatherapi.com/' weather_url = 'https://p478kygkjw.re.qweatherapi.com/'
weather_api_key = '4aa47f183c694aaa812ff018be8270e4' weather_api_key = '4aa47f183c694aaa812ff018be8270e4'
nanjing_location = '101190101' 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): def get_today_weather(city_location: int):
response = requests.get( response = requests.get(
@@ -37,19 +35,6 @@ def get_today_indices(city_location: int):
return response.json() 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__': if __name__ == '__main__':
weather = get_today_weather(nanjing_location) weather = get_today_weather(nanjing_location)

18
wechat_message.py Normal file
View File

@@ -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()