└── README.md /README.md: -------------------------------------------------------------------------------- 1 | # laslos 2 | import requests 3 | import pandas as pd 4 | 5 | API_KEY = 'ваш_ключ_API' 6 | CITIES = ['Beijing', 'Tokyo', 'Seoul', 'Shanghai', 'Hong Kong'] 7 | 8 | def get_weather_data(city): 9 | url = f'http://api.openweathermap.org/data/2.5/weather?q={city}&appid={API_KEY}' 10 | response = requests.get(url) 11 | return response.json() 12 | 13 | def categorize_weather(weather_description): 14 | if 'clear' in weather_description: 15 | return 'Sunny' 16 | elif 'cloud' in weather_description: 17 | return 'Cloudy' 18 | else: 19 | return 'Other' 20 | 21 | def main(): 22 | weather_data = [] 23 | 24 | for city in CITIES: 25 | city_weather = get_weather_data(city) 26 | weather_description = city_weather['weather'][0]['description'] 27 | category = categorize_weather(weather_description) 28 | weather_data.append({'City': city, 'Weather': category}) 29 | 30 | df = pd.DataFrame(weather_data) 31 | print(df) 32 | 33 | sunny_days = df[df['Weather'] == 'Sunny'].shape[0] 34 | cloudy_days = df[df['Weather'] == 'Cloudy'].shape[0] 35 | 36 | print(f'Total Sunny Days: {sunny_days}') 37 | print(f'Total Cloudy Days: {cloudy_days}') 38 | 39 | if __name__ == "__main__": 40 | main() 41 | --------------------------------------------------------------------------------