diff --git a/config.json b/config.json index 27c13cf..737f0f0 100644 --- a/config.json +++ b/config.json @@ -1,3 +1,4 @@ { - "executable_path": "C:/Program Files/Google/Chrome/Application/chromedriver.exe" + "executable_path": "C:/Program Files/Google/Chrome/Application/chromedriver.exe", + "workers": 5 } \ No newline at end of file diff --git a/main.py b/main.py index 7fa5737..20ac15f 100644 --- a/main.py +++ b/main.py @@ -3,6 +3,13 @@ import sys import proxy import w_token from concurrent.futures import ThreadPoolExecutor, as_completed +import json + +f = open('config.json', 'r') +content = f.read() +f.close() +data = json.loads(content) +workers = data["workers"] def task(aid, username, password): @@ -36,7 +43,8 @@ def main(): if t == "N" or t == "n": sys.exit() - with ThreadPoolExecutor(max_workers=5) as executor: + count = 0 + with ThreadPoolExecutor(max_workers=workers) as executor: # 提交多个任务给线程池 futures = [executor.submit(task, row[0], row[1], row[4]) for row in u] @@ -47,7 +55,9 @@ def main(): print("applyId:【%s】,username:【%s】获取失败" % (result[0], result[1])) continue dao.update_token(result[0], result[2]) + count = count + 1 print("applyId:【%s】,username:【%s】获取成功!!!" % (result[0], result[1])) + print("一共【%d】人,成功【%d】人" % (len(u), count)) if __name__ == "__main__":