Skip to content

Commit

Permalink
add prec_prob and wind speed in tomorrow forecast
Browse files Browse the repository at this point in the history
  • Loading branch information
amit9838 committed Jan 27, 2024
1 parent 9c1756d commit dcae6b3
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 5 deletions.
1 change: 1 addition & 0 deletions data/icons/hicolor/scalable/weather_icons/wind.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions data/icons/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ install_data(
join_paths(scalable_dir, 'partly-cloudy-day-fog.svg'),
join_paths(scalable_dir, 'partly-cloudy-night-fog.svg'),
join_paths(scalable_dir, 'rain.svg'),
join_paths(scalable_dir, 'wind.svg'),
join_paths(scalable_dir, 'raindrop.svg'),
join_paths(scalable_dir, 'raindrops.svg'),
join_paths(scalable_dir, 'overcast-rain.svg'),
Expand Down
1 change: 1 addition & 0 deletions src/backendWeather.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ def _get_hourly_forecast(self, lat, lon):
"apparent_temperature",
"weathercode",
"precipitation",
"precipitation_probability",
"surface_pressure",
"visibility",
"windspeed_10m",
Expand Down
4 changes: 4 additions & 0 deletions src/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,11 @@
"95n": icon_loc + "thunderstorms-rain.svg",
"96n": icon_loc + "thunderstorms-night-overcast-snow.svg",
"99n": icon_loc + "snowflake.svg",

"arrow": icon_loc + "arrow.svg",
"raindrop": icon_loc + "raindrop.svg",
"raindrops": icon_loc + "raindrops.svg",
"wind": icon_loc + "wind.svg",
}

bg_css = {
Expand Down
2 changes: 1 addition & 1 deletion src/css.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@
}
.custom_card_forecast_item{
padding: .15rem 1.5rem;
padding: 0.15rem 1.5rem;
border-radius: .7rem;
}
Expand Down
38 changes: 34 additions & 4 deletions src/frontendForecast.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ def page_stacks(self, page_name):
orientation=Gtk.Orientation.VERTICAL, margin_top=0, margin_bottom=0)
scrolled_window.set_child(forecast_container)


# Get Tomorrow's data from hourly forecast
tomorrow_date_time_list = [d_t for d_t in hourly_data.time.get("data") if int(
datetime.fromtimestamp(d_t).strftime(r"%d")) == (datetime.today() + timedelta(days=1)).date().day]
Expand Down Expand Up @@ -135,12 +136,41 @@ def page_stacks(self, page_name):
icon_main.set_halign(Gtk.Align.END)
icon_main.set_hexpand(True)
icon_main.set_pixel_size(50)
icon_main.set_margin_end(60)
icon_main.set_margin_end(30)
forecast_item_grid.attach(icon_main, 1, 0, 1, 1)

forecast_cond_grid = Gtk.Grid(valign=Gtk.Align.CENTER,margin_end = 20)
forecast_item_grid.attach(forecast_cond_grid, 2, 0, 1, 1)

# prec probability
if page_name == 'tomorrow':
prec_probability = hourly_data.precipitation_probability.get("data")[i]
wind_probability = hourly_data.windspeed_10m.get("data")[i]


drop_icon = Gtk.Image().new_from_file(icons["raindrop"])
drop_icon.set_pixel_size(25)
drop_icon.set_halign(Gtk.Align.START)
forecast_cond_grid.attach(drop_icon, 0, 0, 1, 1)

prec_probability_label = Gtk.Label(label=f" {prec_probability}%", margin_top=5)
prec_probability_label.set_halign(Gtk.Align.START)
forecast_cond_grid.attach(prec_probability_label, 1, 0, 1, 1)

# Wind speed probability
wind_icon = Gtk.Image().new_from_file(icons["wind"])
wind_icon.set_pixel_size(25)
wind_icon.set_halign(Gtk.Align.START)
forecast_cond_grid.attach(wind_icon, 0, 1, 1, 1)
speed_unit= hourly_data.windspeed_10m.get("unit")
wind_probability_label = Gtk.Label(label=f" {wind_probability} {speed_unit}", margin_top=5)
forecast_cond_grid.attach(wind_probability_label, 1, 1, 1, 1)


# Temp label grid
temp_label_grid = Gtk.Grid(valign=Gtk.Align.CENTER)
forecast_item_grid.attach(temp_label_grid, 2, 0, 1, 1)
forecast_item_grid.attach(temp_label_grid, 3, 0, 1, 1)


# Max temp label ======
temp_max_text = hourly_data.temperature_2m.get("data")[i]
Expand All @@ -149,7 +179,7 @@ def page_stacks(self, page_name):

temp_max = Gtk.Label(label=f"{temp_max_text:.0f}° ", margin_start=10,)
temp_max.set_css_classes(['text-3', 'bold-2'])
temp_label_grid.attach(temp_max, 0, 0, 1, 1)
temp_label_grid.attach(temp_max, 1, 0, 1, 1)

# Min temp label ======
temp_min_text = hourly_data.temperature_2m.get("data")[i]
Expand All @@ -158,4 +188,4 @@ def page_stacks(self, page_name):

temp_min = Gtk.Label(label=f" {temp_min_text:.0f}°", margin_top=5)
temp_min.set_css_classes(['light-4'])
temp_label_grid.attach(temp_min, 0, 1, 1, 1)
temp_label_grid.attach(temp_min, 1, 1, 1, 1)

0 comments on commit dcae6b3

Please sign in to comment.