Merge pull request #1393 from matrix-org/travis/proposals-pagination

Improve pagination handling in proposals.py
pull/977/head
Ben Parsons 6 years ago committed by GitHub
commit 57ce0c3691
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -12,13 +12,18 @@ authors = set()
prs = set() prs = set()
def getpage(url, page): def getpage(url, page):
resp = requests.get(url + str(page)) url = url + str(page)
resp = requests.get(url)
for link in resp.links.values(): for link in resp.links.values():
if link['rel'] == 'last': if link['rel'] == 'last':
pagecount = re.search('page=(.+?)', link['url']).group(1) pagecount = re.search('page=(.+?)', link['url']).group(1)
return resp.json() val = resp.json()
if not isinstance(val, list):
print(val) # Just dump the raw (likely error) response to the log
raise Exception("Error calling %s" % url)
return val
def getbylabel(label): def getbylabel(label):
pagecount = 1 pagecount = 1
@ -27,7 +32,7 @@ def getbylabel(label):
print(urlbase) print(urlbase)
json.extend(getpage(urlbase, 1)) json.extend(getpage(urlbase, 1))
for page in range(2, int(pagecount) + 1): for page in range(2, int(pagecount) + 1):
getpage(urlbase, page) json.extend(getpage(urlbase, page))
return json return json

Loading…
Cancel
Save