|
|
@@ -6,6 +6,7 @@ import json
|
|
|
from datetime import datetime
|
|
|
from cachetools import TTLCache
|
|
|
import pickle
|
|
|
+import multiprocessing
|
|
|
|
|
|
cache = None;
|
|
|
cache_file_path = 'elife.cache.pickle';
|
|
|
@@ -118,6 +119,7 @@ class OfpayGrabber:
|
|
|
sort_num += 1;
|
|
|
if len(all_ret_list):
|
|
|
save_cache();
|
|
|
+ return all_ret_list;
|
|
|
|
|
|
def get_will_market_buy_list_all(self):
|
|
|
def_val = '星巴克|霸王茶姬|百果园|京东E卡|滴滴快车';
|
|
|
@@ -448,15 +450,41 @@ class OfpayGrabber:
|
|
|
response = requests.post(url, data=data, headers=self.headers, cookies=self.cookies);
|
|
|
return response;
|
|
|
|
|
|
-def main():
|
|
|
+def award_grab_worker(account_info, activities_data):
|
|
|
+ global cache;
|
|
|
init_cache();
|
|
|
- cache.get('xxx',111)
|
|
|
+ print('########账号[%s]开始抢券工作########' % account_info['account']);
|
|
|
+ grabber = OfpayGrabber(account_info, activities_data);
|
|
|
+ results = grabber.start();
|
|
|
+ print('########################################');
|
|
|
+ return f"账号[{account_info['account']}]任务完成";
|
|
|
+
|
|
|
+def main():
|
|
|
+ cpu_threads = multiprocessing.cpu_count();
|
|
|
+ print(f"CPU支持 {cpu_threads} 个线程/核心");
|
|
|
activities_data = read_json('elife_activities_data.json');
|
|
|
accout_data = read_csv('elife_accout_data.csv');
|
|
|
- for item in accout_data:
|
|
|
- # print(item);
|
|
|
- grabber = OfpayGrabber(item, activities_data);
|
|
|
- grabber.start();
|
|
|
+ if cpu_threads > 1:
|
|
|
+ # 创建进程池
|
|
|
+ pool = multiprocessing.Pool(cpu_threads);
|
|
|
+ results = [];
|
|
|
+ for item in accout_data:
|
|
|
+ result = pool.apply_async(award_grab_worker,(item, activities_data,));
|
|
|
+ results.append(result);
|
|
|
+ # 关闭进程池,不再接受新的任务
|
|
|
+ pool.close();
|
|
|
+ # 等待所有任务完成
|
|
|
+ pool.join();
|
|
|
+ # for result in results:
|
|
|
+ # print(result.get());
|
|
|
+ else:
|
|
|
+ global cache;
|
|
|
+ init_cache();
|
|
|
+ for item in accout_data:
|
|
|
+ print('########账号[%s]开始抢券工作########' % item['account']);
|
|
|
+ grabber = OfpayGrabber(item, activities_data);
|
|
|
+ grabber.start();
|
|
|
+ print('########################################');
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
main();
|