48 lines
1.8 KiB
Python
48 lines
1.8 KiB
Python
import json
|
|
from configparser import RawConfigParser
|
|
from os import sep, mkdir
|
|
from os.path import exists
|
|
|
|
from pyrogram import Client
|
|
from apscheduler.schedulers.asyncio import AsyncIOScheduler
|
|
from httpx import AsyncClient
|
|
from sqlitedict import SqliteDict
|
|
|
|
if not exists("data"):
|
|
mkdir("data")
|
|
sqlite = SqliteDict(f"data{sep}data.sqlite", encode=json.dumps, decode=json.loads, autocommit=True)
|
|
# data.sqlite 结构如下:
|
|
# {
|
|
# "update_time": int,
|
|
# }
|
|
# 读取配置文件
|
|
config = RawConfigParser()
|
|
config.read("config.ini")
|
|
api_id: int = 0
|
|
api_hash: str = ""
|
|
bot_token: str = ""
|
|
admin_id: int = 0
|
|
channel_id: int = 0
|
|
api_id = config.getint("pyrogram", "api_id", fallback=api_id)
|
|
api_hash = config.get("pyrogram", "api_hash", fallback=api_hash)
|
|
bot_token = config.get("basic", "bot_token", fallback=bot_token)
|
|
admin_id = config.getint("basic", "admin", fallback=admin_id)
|
|
channel_id = config.getint("basic", "channel_id", fallback=channel_id)
|
|
""" Init httpx client """
|
|
# 使用自定义 UA
|
|
headers = {
|
|
"Host": "papi.jiemian.com",
|
|
"Referer": "https://www.jiemian.com/",
|
|
"Connection": "keep-alive",
|
|
"Accept": "application/json, text/javascript, */*; q=0.01",
|
|
"Content-Type": "application/x-www-form-urlencoded; charset=UTF-8",
|
|
"Accept-Encoding": "gzip, deflate",
|
|
"Accept-Language": "en-US,en;q=0.9,zh-CN;q=0.8,zh;q=0.7",
|
|
"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/101.0.4951.54 Safari/537.36",
|
|
}
|
|
client = AsyncClient(timeout=10.0, headers=headers, follow_redirects=True)
|
|
|
|
# 初始化客户端
|
|
scheduler = AsyncIOScheduler(timezone="Asia/ShangHai")
|
|
app = Client("bot", api_id=api_id, api_hash=api_hash, bot_token=bot_token, plugins={"root": "plugins"})
|