Asynchronous JSON Requests in Python -


i'm using api doing http requests return json. calling of api, however, depends on start , end page indicated, such this:

def api_request(url):     while(true):         try:             response = requests.get(url)             data = response.json()             return(data['data'])         except exception apierror:             print(apierror)             continue         break def build_orglist(start_page, end_page):     apilink = ("http://sc-api.com/?api_source=live&system=organizations&action="                "all_organizations&source=rsi&start_page={0}&end_page={1}&items_"                "per_page=500&sort_method=&sort_direction=ascending&expedite=1&f"                "ormat=json".format(start_page, end_page))     return(api_request(apilink)) 

the way know if you're not longer @ existing page when json null, this.

if wanted multiple build_orglist going on every single page asynchronously until reach end (null json) how so?

i went mix of @lukasgraf's answer of using sessions unify of http connections single session made use of grequests making group of http requests in parallel.


Comments

Popular posts from this blog

javascript - Chart.js (Radar Chart) different scaleLineColor for each scaleLine -

apache - Error with PHP mail(): Multiple or malformed newlines found in additional_header -

java - Android – MapFragment overlay button shadow, just like MyLocation button -