-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRain_Prediction.py
More file actions
56 lines (47 loc) · 2.36 KB
/
Rain_Prediction.py
File metadata and controls
56 lines (47 loc) · 2.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import requests
import datetime as dt
API_ENDPOINT = "http://api.weatherapi.com/v1/forecast.json" #Forecast Weather
KEY = "fed9cc83b6b241a380c185639250502"
LOCATION = "Bhubaneswar"
PARAMETER = {
"key" : KEY,
"q" : LOCATION,
"aqi" : "no"
}
weather_details = requests.get(url = API_ENDPOINT, params = PARAMETER)
weather_details.raise_for_status()
currentWeather = weather_details.json()
printDetails = f"""Location: {currentWeather["location"]["name"]}, {currentWeather["location"]["region"]}, {currentWeather["location"]["country"]}
Latitude: {currentWeather["location"]["lat"]} Longitude: {currentWeather["location"]["lon"]}
Timezone: {currentWeather["location"]["tz_id"]}
Temperature: {currentWeather["current"]["temp_c"]}°C or {currentWeather["current"]["temp_f"]}°F
Feels like: {currentWeather["current"]["feelslike_c"]}°C or {currentWeather["current"]["feelslike_f"]}°F
Current Condition: {currentWeather["current"]["condition"]["text"]}
Wind Intensity: {currentWeather["current"]["wind_mph"]}mph or {currentWeather["current"]["wind_kph"]}kph, Direction: {currentWeather["current"]["wind_dir"]}
Humidity: {currentWeather["current"]["humidity"]}%
Forcast Details for next 12 hours:
Date : {currentWeather["forecast"]["forecastday"][0]["date"]}
"""
print(printDetails)
time = dt.datetime.now()
hourCheck = time.hour
futureHour = hourCheck + 12
# print(hourCheck)
prev_condition = None
start_time = None
for i in range(hourCheck, futureHour + 1):
time_check = int(currentWeather["forecast"]["forecastday"][0]["hour"][i]["time"].split(" ")[1].split(":")[0])
sky_condition = currentWeather["forecast"]["forecastday"][0]["hour"][i]["condition"]["text"]
if currentWeather["forecast"]["forecastday"][0]["hour"][i]["will_it_rain"] == 1:
print(f"The Sky seems {sky_condition} at {time_check}:00 hours")
print("Rain expected !! Be Sure to Carry an Umbrella Please !!")
else:
if prev_condition is None:
prev_condition = sky_condition
start_time = time_check
elif sky_condition != prev_condition:
print(f"The Sky seems {prev_condition} from {start_time}:00 to {time_check - 1}:00 hours. Have a great day!")
prev_condition = sky_condition
start_time = time_check
if prev_condition:
print(f"The Sky seems {prev_condition} from {start_time}:00 to {futureHour}:00 hours. Have a great day!")