#πŸ”’ From Seconds To Formatted Hours; Minutes; Seconds

9 messages Β· Page 1 of 1 (latest)

harsh umbra
#

Hey Guys so im stuck here for like an hour ill poste the code;

import requests
import time

base_url = "https://minecraftonline.com/cgi-bin/"

def get_user_info(user):
    firstseen = f"{base_url}/getfirstseen?{user}"
    lastseen = f"{base_url}/getlastseen?{user}"
    timeonline = f"{base_url}/gettimeonline?{user}"
    response = requests.get(firstseen)

    if response.status_code == 200:
        print(f"First Seen;\n{response.text}")
    else:
        print(f"Failed To Retrieve Data {response.status_code}")

    response = requests.get(lastseen)

    if response.status_code == 200:
        print(f"Last Seen;\n{response.text}")
    else:
        print(f"Failed To Retrieve Data {response.status_code}")

    response = requests.get(timeonline)
    seconds = response.text
    clean_seconds = seconds.strip()
    convert = time.strftime("%H:%M:%S", time.gmtime(clean_seconds))

    if response.status_code == 200:
        print(f"Time Played;\n{convert}")
    else:
        print(f"Failed To Retrieve Data {response.status_code}")


user_name = "Egitto"
user_info = get_user_info(user_name)

Im trying to get the seconds (The seconds are formatted as "2718289\n" thats why i do clean_seconds) from an API, and i would need to transform it into a readable time

old cedarBOT
#

@harsh umbra

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

harsh umbra
#

Traceback (most recent call last):
File "/Users/adam/IdeaProjects/apimco/apiprotocol.py", line 39, in <module>
user_info = get_user_info(user_name)
File "/Users/adam/IdeaProjects/apimco/apiprotocol.py", line 30, in get_user_info
convert = time.strftime("%H:%M:%S", time.gmtime(clean_seconds))
~~~~~~~~~~~^^^^^^^^^^^^^^^
TypeError: 'str' object cannot be interpreted as an integer

#

this is the error i get

remote wind
prisma snow
#

ngl the compiler is telling you what went wrong and how to fix it

#

@harsh umbra basically you should convert it to intiger first before passing

old cedarBOT
#
Python help channel closed for inactivity

This help channel has been closed. Feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.