#!/usr/bin/env python3

import requests

print("# --- ----------- ---")
print("# --- weather app ---")
print("# --- ----------- ---")

city = input("City: ")

# https://wttr.in/London?format=j1
url = f"https://wttr.in/{city}?format=j1"

response = requests.get(url)

if response.status_code == 200:
    data = response.json()
    current = data["current_condition"][0]

    print(f"Temperature: {current['temp_C']}°C")
    print(f"Weather: {current['weatherDesc'][0]['value']}")
else:
    print("Request failed")

print("# --- --------- ---")
print("# --- send data ---")
print("# --- --------- ---")

data = { "name": "Alice",      # a dictionary
         "age": 25 }

# https://httpbin.org/post
# is a HTTP request and response service
response = requests.post("https://httpbin.org/post",
                         json=data)

print(response.json())
