-
Notifications
You must be signed in to change notification settings - Fork 0
/
tasks.py
50 lines (34 loc) · 1.52 KB
/
tasks.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import asyncio
from datetime import datetime
from commands import (
FundApi, get_all_fund_codes_from_db, get_daily_report, get_subscribers, send_message_to_user,
update_fund_detail_in_db, update_fund_realtime_in_db)
# 你的数据库更新函数
async def update_fund_details():
# 获取所有基金代码
fund_codes = await get_all_fund_codes_from_db()
# 假设你使用requests库来获取基金数据
data = FundApi().get_fund_details(fund_codes)
for fund in data:
await update_fund_detail_in_db(fund)
print(f"Updating fund details at {datetime.now()}")
async def update_realtime_fund_details():
# 获取所有基金代码
fund_codes = await get_all_fund_codes_from_db()
data = FundApi().get_real_time_fund(fund_codes)
for fund in data:
await update_fund_realtime_in_db(fund)
print(f"Updating fund details at {datetime.now()}")
def sync_update_realtime_fund_details():
asyncio.run(update_realtime_fund_details())
def sync_update_fund_details():
asyncio.run(update_fund_details())
async def send_daily_report_to_subscribers():
# 获取所有订阅了 daily report 的用户
subscribers = await get_subscribers()
# 对每个用户发送 daily report
for user_id in subscribers:
message, image_path = await get_daily_report(user_id, True)
await send_message_to_user(user_id, message, image_path) # 你可能需要实现这个函数
def sync_send_daily_report_to_subscribers():
asyncio.run(send_daily_report_to_subscribers())