trading-quant/monitors/jin10_cal.py
2024-09-22 09:34:23 +08:00

65 lines
1.7 KiB
Python

import requests
import datetime
import time
import discord_sender
def run():
print('金 10 数据数据日历数据抓取...')
now = datetime.date.today()
year = now.year
month = now.month
day = now.day
addtion_day = 1
items = []
while(addtion_day <= 7):
print(f'addtion_day:{addtion_day}')
day += addtion_day
addtion_day+=1
result = _get_jin10_cal_by_day(year, month, day)
items.extend(result)
time.sleep(1)
if len(items) > 0:
content = ""
for item in items:
print(item)
content += _build_content(item)
# print(content)
url = 'https://discord.com/api/webhooks/1287027684370681939/fzinKKoNK6KXoLNdj1wttSDtIGio-VHijaYzZInoajHHu-PZyZXVpWDxM6_XrxCtPrPY'
discord_sender.send_message(url, '【最近一周数据公布】',content)
def _build_content(item):
content = f"{item['name']} {item['country']} {item['time_period']}\r\n"
content += f"重要星级:"
for s in range(item['star']):
content+=""
pub_date = datetime.datetime.strptime(item['pub_time'],'%Y-%m-%dT%H:%M:%S.%fZ') + datetime.timedelta(hours=8)
content += f"\r\n公布时间: {pub_date.strftime('%Y-%m-%d %H:%M:%S')}\r\n\r\n"
return content
def _fill_number(number):
if number<10:
return "0" + str(number)
return number
def _get_jin10_cal_by_day(year,month, day):
url = f"https://cdn-rili.jin10.com/data/{year}/{_fill_number(month)}{_fill_number(day)}/economics.json"
data = requests.get(url).json()
items = []
for item in data:
if item['star'] >= 4:
items.append(item)
return items