Skip to content

Commit c7240b9

Browse files
Add files via upload
This basic exercise carries the Weather Information Retrieval Using API.
1 parent 2900d44 commit c7240b9

File tree

1 file changed

+84
-0
lines changed

1 file changed

+84
-0
lines changed
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
import json
2+
from requests import get
3+
from pprint import pprint
4+
5+
import requests
6+
from pprint import pprint
7+
8+
api_key = "b4e35b2eeae8a0d1125b206a527d5675"
9+
city = ("Marrakesh")
10+
base_url = "http://api.weatherstack.com/current"
11+
12+
url = f"{base_url}?access_key={api_key}&query={city}"
13+
response = requests.get(url)
14+
15+
data = response.json()
16+
17+
pprint(data)
18+
19+
#ekrana şehrin current temperature, current wind_speed ve location name değerlerini yazdıralım.
20+
21+
if response.status_code == 200 and 'current' in data:
22+
location_name = data['location']['name']
23+
24+
current_temperature = data['current']['temperature']
25+
current_wind_speed = data['current']['wind_speed']
26+
27+
print(f'City: {location_name}')
28+
print(f'Current Temperature: {current_temperature}°C')
29+
print(f'Current Wind Speed: {current_wind_speed} km/h')
30+
else:
31+
print('Error: Could not retrieve data for the specified city.')
32+
33+
#searching mekanizması, ve Crud operasyonu yapın.
34+
35+
import requests
36+
37+
def search_weather(city):
38+
39+
api_key = "b4e35b2eeae8a0d1125b206a527d5675"
40+
base_url = "http://api.weatherstack.com/current"
41+
42+
url = f'{base_url}?access_key={api_key}&query={city}'
43+
44+
response = requests.get(url)
45+
46+
data = response.json()
47+
48+
if response.status_code == 200 and 'current' in data:
49+
location_name = data['location']['name']
50+
current_temperature = data['current']['temperature']
51+
current_wind_speed = data['current']['wind_speed']
52+
print(f'City: {location_name}')
53+
print(f'Current Temperature: {current_temperature}°C')
54+
print(f'Current Wind Speed: {current_wind_speed} km/h')
55+
else:
56+
print(f'Error: Could not retrieve data for the city: {city}')
57+
58+
59+
city = input('Enter the city name to search the weather: ')
60+
search_weather(city)
61+
62+
63+
import requests
64+
65+
def get_weather(city):
66+
api_key = "b4e35b2eeae8a0d1125b206a527d5675"
67+
68+
base_url = "http://api.weatherstack.com/current"
69+
70+
url = f'{base_url}?access_key={api_key}&query={city}'
71+
72+
response = requests.get(url)
73+
74+
data = response.json()
75+
76+
if response.status_code == 200 and 'current' in data:
77+
location_name = data['location']['name']
78+
current_temperature = data['current']['temperature']
79+
current_wind_speed = data['current']['wind_speed']
80+
print(f'City: {location_name}')
81+
print(f'Current Temperature: {current_temperature}°C')
82+
print(f'Current Wind Speed: {current_wind_speed} km/h')
83+
else:
84+
print(f'Error: Could not retrieve data for {city}')

0 commit comments

Comments
 (0)