feat: config.json file (v1.0.1)

master
wlt233 2 months ago
parent 0debf35541
commit b5cd47758b

2
.gitignore vendored

@ -1,4 +1,4 @@
config.json
chromedriver.exe

@ -0,0 +1,12 @@
{
"userid": "foobar123",
"username": "114514@1919.com",
"password": "810810",
"callback_url": "http://localhost:114514/xxx",
"check_interval": 42,
"check_list": {
"1145141919": {
"url": "https://x.com/i/lists/1873731145141919810"
}
}
}

@ -0,0 +1,4 @@
requests
loguru
retry
selenium

@ -0,0 +1,24 @@
@REM @echo off
@REM set SCRIPT_NAME=twitter.py
@REM set SCRIPT_PATH=C:\users\wlt233\Desktop\Overflow\asset\twitter\twitter.py
@REM set CHECK_INTERVAL=30
@REM :LOOP
@REM rem 检查 Python 脚本是否正在运行
@REM wmic process where "caption='python.exe' and commandline like '%%twitter.py%%'" get commandline 2>nul | findstr /I "%SCRIPT_NAME%" >nul
@REM if %errorlevel% neq 0 (
@REM echo Script not running, starting...
@REM start "" "C:\Python39\python.exe" "%SCRIPT_PATH%"
@REM ) else (
@REM echo Script running
@REM )
@REM rem 等待 CHECK_INTERVAL 秒后再次检查
@REM timeout /T %CHECK_INTERVAL% >nul
@REM goto LOOP
:start
start /wait C:\Python39\python.exe C:\path\to\twitter\twitter.py
echo script dead... restarting
goto start

@ -171,31 +171,32 @@ def check_timeline(driver, url):
def main(userid, username, password, config):
def main(config):
userid = config["userid"] # screenid @后面那个)
username = config["username"] # 登录用户名或邮箱
password = config["password"] # 密码
driver = login(userid, username, password)
while 1:
json_data = {}
for group_id, url in config.items():
new_tweets = check_timeline(driver, url)
check_list = config.get("check_list", [])
for group_id, group_config in check_list.items():
new_tweets = check_timeline(driver, group_config["url"])
if new_tweets:
json_data[group_id] = new_tweets
if json_data:
pprint(json_data)
try:
requests.post("http://localhost:8520/twitter", json=json_data)
requests.post(config["callback_url"], json=json_data)
except Exception as e:
logger.error(str(e))
time.sleep(55)
time.sleep(config.get("check_interval", 42))
if __name__ == "__main__":
userid = "<userid>"
username = "<username>"
password = "<password>"
config = {
"<qq_group_id>": "https://x.com/i/lists/<...>",
}
main(userid, username, password, config)
with open("config.json", 'r') as f:
config = json.load(f)
main(config)
# with open("lovelive.json", 'r') as f: pprint(parse_timeline(json.load(f)))

Loading…
Cancel
Save