Advertisement
SipriusPT

Untitled

Apr 24th, 2020
433
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.86 KB | None | 0 0
  1. # Request 100 repositories per page (and only their slugs), and the next page URL
  2. next_page_url = 'https://api.bitbucket.org/2.0/repositories/%s?pagelen=100&fields=next,values.slug' %team
  3.  
  4. # Keep fetching pages while there's a page to fetch
  5. full_repo_list = []
  6.  
  7. while next_page_url is not None:
  8.     response = requests.get(next_page_url, auth=(username, password))
  9.     print ("response> %s" %response)
  10.     page_json = response.json()
  11.     print ("page_json> %s" %page_json)
  12.  
  13.     # Parse repositories from the JSON
  14.     for repo in page_json['values']:
  15.         full_repo_list.append(repo['slug'])
  16.  
  17.     # Get the next page URL, if present
  18.     # It will include same query parameters, so no need to append them again
  19. next_page_url = page_json.get('next', None)
  20.  
  21. # Result length will be equal to `size` returned on any page
  22. print ("Result: \n", len(full_repo_list))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement