##Get Total Active cases active = covid.get_total_active_cases() ##Get Total Confirmed cases confirmed = covid.get_total_confirmed_cases() ##Get Total Recovered cases recovered = covid.get_total_recovered() ##Get Total Deaths deaths = covid.get_total_deaths()
covid = Covid() countries = covid.list_countries() covid.get_status_by_country_id(int(countries[0]['id']))
## 多線程快速獲取 import multiprocessing as mp
defworker(i, return_dict): '''worker function''' Result = covid.get_status_by_country_id(int(countries[i]['id'])) return_dict[Result] = Result print(Result)
defmulticore(Pool=10): pool = mp.Pool(processes=Pool) #return_dict = manager.dict() for i inrange(10): # Working function "echo" and the arg 'i' multi_res = [pool.apply_async(worker,(i,return_dict))] pool.close() pool.join()
if __name__ == '__main__': manager = mp.Manager() return_dict = manager.dict() jobs = [] Num = 0 for i inrange(10): Num +=1 print (Num) p = mp.Process(target=worker, args=(i,return_dict)) jobs.append(p) p.start() for proc in jobs: proc.join()