feat:增加查询股票信息
This commit is contained in:
BIN
__pycache__/wechat_message.cpython-310.pyc
Normal file
BIN
__pycache__/wechat_message.cpython-310.pyc
Normal file
Binary file not shown.
38
daily_stock.py
Normal file
38
daily_stock.py
Normal 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)
|
||||
@@ -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)
|
||||
|
||||
|
||||
18
wechat_message.py
Normal file
18
wechat_message.py
Normal 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()
|
||||
Reference in New Issue
Block a user