Add pagination to get_mlh_users
This commit is contained in:
parent
ad158bcbc6
commit
a7bc086f66
1 changed files with 15 additions and 8 deletions
23
flask_app.py
23
flask_app.py
|
@ -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):
|
||||||
|
|
Loading…
Add table
Reference in a new issue