From a7bc086f66bb81c722e5a9292aa30f74e82ac33c Mon Sep 17 00:00:00 2001 From: Nick Krichevsky Date: Fri, 11 Jan 2019 19:19:35 -0500 Subject: [PATCH] Add pagination to get_mlh_users --- flask_app.py | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/flask_app.py b/flask_app.py index b775ad2..2c346b4 100644 --- a/flask_app.py +++ b/flask_app.py @@ -23,9 +23,6 @@ app.config.from_pyfile('config.py') db = SQLAlchemy(app) - - - class Hacker(db.Model): __tablename__ = 'hackers' @@ -515,11 +512,21 @@ def get_mlh_user(mlh_id): def get_mlh_users(): - req = requests.get( - 'https://my.mlh.io/api/v2/users.json?client_id=' + api_keys['mlh']['client_id'] + '&secret=' + api_keys['mlh'][ - 'secret']) - if req.status_code == 200: - return req.json()['data'] + page_index = 1 + num_pages = 1 + users = [] + while page_index <= num_pages: + req = requests.get('https://my.mlh.io/api/v2/users.json?client_id={client_id}&secret={secret}&page={page}'.format( + client_id=api_keys['mlh']['client_id'], + secret=api_keys['mlh']['secret'], + page=page_index + )) + if req.status_code == 200: + users += req.json()['data'] + num_pages = req.json()['pagination']['total_pages'] + page_index += 1 + + return users if users else None def gen_new_auto_promote_keys(n=50):