代码拉取完成,页面将自动刷新
import asyncio
import json
import datetime
import os
import sys
from bili.login import BiliUser
from bili.smallheart import SmallHeartTask
from bili.dailyclockin import DailyClockIn
from push import serverchan
from apscheduler.schedulers.blocking import BlockingScheduler
from apscheduler.triggers.cron import CronTrigger
async def run(user: BiliUser):
await user.login()
await SmallHeartTask(user).do_work()
await DailyClockIn(user).do_work()
await user.session.close()
message = f"用户:{user.uname}({user.uid})\n" + "\n".join(user.message)
if user.message_err:
message += "\n错误日志:\n" + "\n".join(user.message_err)
return message + "\n\n"
def main_handler(event, context):
data = json.loads(context["environment"])
cookie = data["cookie"]
ruid = int(data.get("ruid", 0))
sendkey = data.get("sendkey", None)
loop = asyncio.get_event_loop()
message = ""
try:
user = BiliUser(cookie=cookie, ruid=ruid, cloud_service=True)
message = loop.run_until_complete(run(user))
except Exception as e:
message = str(e)
print(message)
if sendkey:
loop.run_until_complete(serverchan.push_message(sendkey, message))
return True
def main():
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
sendkey = config["serverchan"]["sendkey"]
message = ""
for u in config["users"]:
if u["cookie"] == "":
continue
try:
user = BiliUser(u["cookie"], u["ruid"])
message += loop.run_until_complete(run(user))
except Exception as e:
message += f"{e}\n"
print(message)
if sendkey and len(sendkey) > 0:
loop.run_until_complete(serverchan.push_message(sendkey, message))
if __name__ == "__main__":
if "--fromdocker" in sys.argv:
config = {"users": [{"cookie": os.environ["COOKIE"], "ruid":int(os.environ["RUID"])}], "cron": {
"cron": os.environ["CRON"]}, "serverchan": {"sendkey": os.environ["SERVER_CHAN_SENDKEY"]}}
else:
import toml
config = toml.load("user.toml")
cron = config["cron"]["cron"] if config["cron"]["cron"] else "0 0 * * *"
schedulers = BlockingScheduler()
schedulers.add_job(
main,
CronTrigger.from_crontab(cron),
next_run_time=datetime.datetime.now(),
)
schedulers.start()
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。