Skip to content

Instantly share code, notes, and snippets.

@bbelderbos
Created May 1, 2023 13:03
Show Gist options
  • Save bbelderbos/ca135aff7379e4e97ee11928d5ace12d to your computer and use it in GitHub Desktop.
Save bbelderbos/ca135aff7379e4e97ee11928d5ace12d to your computer and use it in GitHub Desktop.
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