Add pagination to get_mlh_users

This commit is contained in:
Nick Krichevsky 2019-01-11 19:19:35 -05:00
parent ad158bcbc6
commit a7bc086f66
No known key found for this signature in database
GPG key ID: A7567E699BE5AAE4

View file

@ -23,9 +23,6 @@ app.config.from_pyfile('config.py')
db = SQLAlchemy(app) db = SQLAlchemy(app)
class Hacker(db.Model): class Hacker(db.Model):
__tablename__ = 'hackers' __tablename__ = 'hackers'
@ -515,11 +512,21 @@ def get_mlh_user(mlh_id):
def get_mlh_users(): def get_mlh_users():
req = requests.get( page_index = 1
'https://my.mlh.io/api/v2/users.json?client_id=' + api_keys['mlh']['client_id'] + '&secret=' + api_keys['mlh'][ num_pages = 1
'secret']) users = []
if req.status_code == 200: while page_index <= num_pages:
return req.json()['data'] 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): def gen_new_auto_promote_keys(n=50):