Initial commit

This commit is contained in:
root
2025-07-06 23:48:33 +02:00
commit 137f8c1c93
6 changed files with 236 additions and 0 deletions

54
client.py Normal file
View File

@ -0,0 +1,54 @@
import requests
def get_weather_by_city(city):
url = "http://127.0.0.1:8000/weather"
params = {"city": city}
response = requests.get(url, params=params)
response.raise_for_status()
return response.json()
def get_weather_by_geo(latitude, longitude):
url = "http://127.0.0.1:8000/weather/geo"
params = {"latitude": latitude, "longitude": longitude}
response = requests.get(url, params=params)
response.raise_for_status()
return response.json()
def main():
print("=== POBIERANIE POGODY Z SERWERA ===")
choice = input("Wybierz sposób pobierania pogody (1 - miasto, 2 - współrzędne): ").strip()
try:
if choice == "1":
city = input("Podaj miasto (np. warszawa, krakow, gdansk): ").strip().lower()
data = get_weather_by_city(city)
if "error" in data:
print("Błąd:", data["error"])
return
print("\n=== AKTUALNA POGODA DLA MIASTA ===")
print(f"Miasto: {data.get('city')}")
print(f"Temperatura: {data.get('temperature')} °C")
print(f"Wiatr: {data.get('windspeed')} km/h")
print(f"Czas pomiaru: {data.get('time')}")
elif choice == "2":
latitude = input("Podaj szerokość geograficzną (latitude): ").strip()
longitude = input("Podaj długość geograficzną (longitude): ").strip()
data = get_weather_by_geo(latitude, longitude)
print("\n=== AKTUALNA POGODA WG WSPÓŁRZĘDNYCH ===")
print(f"Miasto: {data.get('city')}")
print(f"Szerokość: {data.get('latitude')}")
print(f"Długość: {data.get('longitude')}")
print(f"Temperatura: {data.get('temperature')} °C")
print(f"Wiatr: {data.get('windspeed')} km/h")
print(f"Czas pomiaru: {data.get('time')}")
else:
print("Nieprawidłowy wybór. Wybierz 1 lub 2.")
except requests.RequestException as e:
print("Błąd połączenia z serwerem lub serwer zwrócił błąd:", e)
if __name__ == "__main__":
main()