Created
May 1, 2023 13:03
-
-
Save bbelderbos/ca135aff7379e4e97ee11928d5ace12d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from pprint import pprint as pp | |
import random | |
import requests | |
def get_random_tip(): | |
url = "https://codechalleng.es/api/pytips/" | |
response = requests.get(url) | |
if response.status_code == 200: | |
tips = response.json() | |
random_tip = random.choice(tips) | |
return random_tip | |
else: | |
print(f"Error: Unable to fetch tips. Status code: {response.status_code}") | |
return None | |
if __name__ == "__main__": | |
random_tip = get_random_tip() | |
if random_tip: | |
pp(random_tip) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment