0

At the moment, I am trying to compare the timestamp from an API that is in yyyy-mm-ddThh:mm:ss.000Z and the current time stamp. In theory, my code should get all of these content from the responses during a certain time period, but i'm jsut confuse dabout line
14.

def retrieve_messages(auth, channelid, sec):

    now = datetime.datetime.now()
    format_iso_now = now.isoformat()

    headers = {
        'authorization': auth 
    }
    t_end = time.time() + sec
    while time.time() < t_end:
        r = requests.get(f'REDACTED', headers=headers)
        jsonn = json.loads(r.text)
        for value in jsonn:
            if value['timestamp'] <= format_iso_now:
                print(value['content'], '\n')

I redacted out the API link for my own well being, but it responds with a timestamp such as "2022-04-05T06:12:53.267000+00:00". How would I complete this function to reach my goal? Thank you.

Timus
  • 10,974
  • 5
  • 14
  • 28
underunder
  • 13
  • 2
  • Does this answer your question? [Python 3 How to format to yyyy-mm-ddThh:mm:ssZ](https://stackoverflow.com/questions/55021984/python-3-how-to-format-to-yyyy-mm-ddthhmmssz) – Joe_Bao Apr 05 '22 at 06:33
  • @Joe_Bao the OP is looking to parse string to datetime, not vice versa – FObersteiner Apr 05 '22 at 10:15

0 Answers0