Add pagination to get_mlh_users
This commit is contained in:
parent
ad158bcbc6
commit
a7bc086f66
1 changed files with 15 additions and 8 deletions
21
flask_app.py
21
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'])
|
||||
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:
|
||||
return req.json()['data']
|
||||
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):
|
||||
|
|
Loading…
Add table
Reference in a new issue