This repository has been archived by the owner on Jul 15, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathmain.py
71 lines (47 loc) · 1.78 KB
/
main.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#! /usr/bin/env python3
# -*- coding: utf-8 -*-
import logging
import signal
from queue import Empty
from threading import Thread
from time import sleep
import uvicorn
from wcferry import Wcf
from lib.httpapi_core import Http
from configuration import Config
from job_mgmt import Job
from base.history_msg import clear_history
from base.func_job import Job_
logging.basicConfig(
level='DEBUG', format="%(asctime)s [%(levelname)s] %(message)s", datefmt="%Y-%m-%d %H:%M:%S")
LOG = logging.getLogger("Demo")
def run_http_server(app, host, port):
uvicorn.run(app=app, host=host, port=port)
def main():
LOG.info("Start demo...")
config = Config()
job=Job()
cb = config.BOT_CONFIG["callback"]
http_port = config.BOT_CONFIG["http_port"]
http_host = config.BOT_CONFIG["http_host"]
print(http_port, http_host, cb)
wcf = Wcf(debug=False)
runjob=Job_(wcf)
sleep(5) # 等微信加载好,以免信息显示异常
LOG.info(f"已经登录: {True if wcf.is_login() else False}")
LOG.info(f"wxid: {wcf.get_self_wxid()}")
if not cb:
print("没有设置接收消息回调,消息直接通过日志打印;请通过 --cb 设置消息回调")
print(f"回调接口规范参考接收消息回调样例:http://{http_host}:{http_port}/docs")
http = Http(wcf=wcf,
cb=cb,
title="WeChatFerry HTTP 客户端",
description=f"Github: <a href='https://github.com/x-dr/wechat-bot'>",)
# 启动http服务
Thread(target=run_http_server, name="HttpServer", args=(
http, http_host, http_port,), daemon=True).start()
job.onEveryMinutes(10, clear_history)
job.onEveryTime("01:38", runjob.toJobBbing)
job.runPendingJobs()
if __name__ == "__main__":
main()