vendredi 23 avril 2021

Flask loop takes long time to complete

I have this loop in my app.py. For some reason it extends the load time by over 3 seconds. Are there any solutions?

import dateutil.parser as dp

# Converts date from ISO-8601 string to formatted string and returns it
def dateConvert(date):
    return dp.parse(date).strftime("%H:%M @ %e/%b/%y")

def nameFromID(userID):
    if userID is None:
       return 'Unknown'
    else:
       response = requests.get("https://example2.org/" + str(userID), headers=headers)
       return response.json()['firstName'] + ' ' + response.json()['lastName']

logs = []
response = requests.get("https://example.org", headers=headers)
for response in response.json():
    logs.append([nameFromID(response['member']), dateConvert(response['createdAt'])])



Aucun commentaire:

Enregistrer un commentaire