二手产品经理

二手产品经理

THIS IS RENO

JSON - 92 days - Learn Python online for 100 days

Record#

  1. Today is coding practice, fetching information from a weather API and printing it.
  2. Not sure about the specific meaning of weathercode, so I made a small modification to the coding requirements.
  3. chatgpt taught me how to find the most common occurrence of a number.

CODE#

main.py#

import requests, json
from collections import Counter

timezone = "GMT"
latitude = 51.5002
longitude = -0.1262

result = requests.get(
  f"https://api.open-meteo.com/v1/forecast?latitude={latitude}&longitude={longitude}&daily=weathercode,temperature_2m_max,temperature_2m_min&timezone={timezone.upper()}"
)

user = result.json()
#print(json.dumps(user, indent=2))
#print("++++")
number_count = Counter(user['daily']['weathercode'])
most_common_number, count = number_count.most_common(1)[0]
print(
  f"The weather conditions are mostly {most_common_number}\nHighest temperature: {max(user['daily']['temperature_2m_max'])}-----Lowest temperature: {min(user['daily']['temperature_2m_min'])}"
)


Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.