-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
优化:提高多账户场景下任务执行效率 优化:使显示内容更简洁
- Loading branch information
Showing
4 changed files
with
102 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
|
||
build | ||
dist | ||
__pycache__ | ||
*.spec |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,48 @@ | ||
# @Author : Qiuyelin | ||
# @repo : https://github.com/pooneyy/weiban-tool | ||
|
||
import os | ||
import os, sys | ||
import Utils | ||
import time | ||
import json | ||
import asyncio | ||
|
||
# tenantCode UserId x-token userProjectId | ||
try: | ||
with open("config.json", "r+", encoding='utf8') as file: | ||
usersConfig = json.load(file) | ||
for user in usersConfig: | ||
tenantCode = user['tenantCode'] | ||
userId = user['userId'] | ||
x_token = user['token'] | ||
userProjectId = user['userProjectId'] | ||
main = Utils.main(tenantCode, userId, x_token, userProjectId) | ||
main.init() | ||
try: | ||
finishIdList = main.getFinishIdList() | ||
except json.decoder.JSONDecodeError: | ||
print('账户信息错误或已经过期,请重新获取。详见:https://github.com/pooneyy/weiban-tool') | ||
break | ||
async def weibanTask(user): | ||
# tenantCode UserId x-token userProjectId | ||
tenantCode = user.get('tenantCode') | ||
userId = user.get('userId') | ||
x_token = user.get('token') | ||
userProjectId = user.get('userProjectId') | ||
realName = user.get('realName',userId) | ||
taskName = '未知的任务名' | ||
main = Utils.main(tenantCode, userId, x_token, userProjectId) | ||
main.init() | ||
try: | ||
realName = main.getRealName() | ||
taskName = main.getTaskName() | ||
print(f"开始进行 {realName} 的任务:{taskName}") | ||
finishIdList = main.getFinishIdList() | ||
for i in main.getCourse(): | ||
main.start(i) | ||
time.sleep(20) | ||
await main.start(i) | ||
await asyncio.sleep(20) | ||
main.finish(finishIdList[i]) | ||
os.system("pause") | ||
except FileNotFoundError: | ||
print('未找到 config.json!详见:https://github.com/pooneyy/weiban-tool') | ||
print(f"{realName} 的任务已完成") | ||
except json.decoder.JSONDecodeError:print(f'{realName} 的账户信息错误或已经过期,请重新获取。详见:https://github.com/pooneyy/weiban-tool') | ||
except KeyboardInterrupt:print(f'{realName} 的任务被手动终止') | ||
|
||
async def main(): | ||
usersConfig = {} | ||
try: | ||
with open("config.json", "r+", encoding='utf8') as file: | ||
try:usersConfig = json.load(file) | ||
except json.decoder.JSONDecodeError:print('配置文件格式错误,请仔细检查 config.json 。详见:https://github.com/pooneyy/weiban-tool') | ||
tasks=[] | ||
for user in usersConfig: | ||
tasks.append(weibanTask(user)) | ||
try:await asyncio.gather(*tasks) | ||
except asyncio.CancelledError:pass | ||
except FileNotFoundError:print('未找到 config.json!详见:https://github.com/pooneyy/weiban-tool') | ||
|
||
if __name__ =='__main__': | ||
try:asyncio.run(main()) | ||
except KeyboardInterrupt:print(f'\n任务被手动终止') | ||
os.system("pause") |