Skip to content

Commit 10d942a

Browse files
committed
Updated context
1 parent 868f4e2 commit 10d942a

File tree

5 files changed

+17
-24
lines changed

5 files changed

+17
-24
lines changed

View/HomeScreen/components/components.kv

+11-12
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<DisplayContentData>:
2-
md_bg_color:0,.4,1,.05
2+
md_bg_color:0,.4,1,.07
33
orientation: 'vertical'
44
padding: ('7dp', '7dp', '7dp', '7dp')
55
spacing: '4dp'
@@ -18,12 +18,12 @@
1818
id:city_name
1919
font_name: app.basic_bold_font
2020
adaptive_height:True
21-
text:app.weather_data["location"]["city"]
21+
text:app.weather_data["name"]
2222
font_size:"27sp"
2323

2424
CustomLabel:
2525
id:city_temp
26-
text:f"{app.weather_data['current_observation']['condition']['temperature']}\xb0 F\n{app.weather_data['current_observation']['condition']['text']}"
26+
text:f"{int(app.weather_data['main']['temp']-273.15)}\xb0 C\n{app.weather_data['weather'][0]['main']}"
2727
adaptive_height:True
2828
font_size:"21sp"
2929

@@ -33,11 +33,10 @@
3333
orientation:'vertical'
3434
adaptive_size:True
3535

36-
StyledIconButton:
37-
icon:'weather-sunny'
38-
icon_size:"115sp"
39-
icon_color:app.theme_cls.accent_dark
40-
_no_ripple_effect:True
36+
FitImage:
37+
source:f"https://openweathermap.org/img/wn/{app.weather_data['weather'][0]['icon']}@2x.png"
38+
size_hint: None, None
39+
size: '135dp','135dp'
4140

4241
MDSeparator:
4342

@@ -59,19 +58,19 @@
5958
padding: ('4dp', '4dp', '4dp', '4dp')
6059
Item:
6160
icon:"water-percent"
62-
text:f"Humidity : {app.weather_data['current_observation']['atmosphere']['humidity']} \x25"
61+
text:f"Humidity : {app.weather_data['main']['humidity']} \x25"
6362
Item:
6463
icon:"weather-windy"
65-
text:f"Wind : {app.weather_data['current_observation']['wind']['speed']} kph"
64+
text:f"Wind : {app.weather_data['wind']['speed']} kph"
6665
Item:
6766
icon:"weather-sunny"
6867
text:f"UV Index : Sorry"
6968
Item:
7069
icon:"eye"
71-
text:f"Visibility : {app.weather_data['current_observation']['atmosphere']['visibility']}"
70+
text:f"Visibility : {app.weather_data['visibility']}"
7271
Item:
7372
icon:"arrow-collapse"
74-
text:f"Pressure : {app.weather_data['current_observation']['atmosphere']['pressure']} mb"
73+
text:f"Pressure : {app.weather_data['main']['pressure']} mb"
7574
MDSeparator:
7675
MDBoxLayout:
7776
orientation: 'vertical'

View/HomeScreen/components/weather_api_data.py

+3-9
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,11 @@
22

33
def get_weather(city):
44

5-
url = "https://yahoo-weather5.p.rapidapi.com/weather"
6-
7-
querystring = {"location":city,"format":"json","u":"f"}
8-
9-
headers = {
10-
"x-rapidapi-key":"your-api-key",
11-
"x-rapidapi-host":"yahoo-weather5.p.rapidapi.com"
12-
}
5+
api_key="your-api-key"
6+
url = f"https://api.openweathermap.org/data/2.5/weather?q={city}&appid={api_key}"
137

148
try:
15-
response =requests.get(url, headers=headers,params=querystring)
9+
response =requests.get(url)
1610
return response.json()
1711
except Exception as e:
1812
return False

View/HomeScreen/home_screen.kv

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
icon: "reload"
3232
ripple_color:app.theme_cls.primary_color
3333
on_release:
34-
app.update_context_data(['delhi'])
34+
app.update_context_data(['new york'])
3535

3636
StyledIconButton:
3737
icon: "plus"

assets/json/data.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"location": {"city": "Delhi", "woeid": 2295019, "country": "India", "lat": 28.643999, "long": 77.091003, "timezone_id": "Asia/Kolkata"}, "current_observation": {"pubDate": 1725020824, "wind": {"chill": 101, "direction": "ENE", "speed": 5}, "atmosphere": {"humidity": 61, "visibility": 7.02, "pressure": 1005.1}, "astronomy": {"sunrise": "5:59 AM", "sunset": "6:44 PM"}, "condition": {"temperature": 92, "text": "Mostly Cloudy", "code": 28}}, "forecasts": [{"day": "Fri", "date": 1725033600, "high": 95, "low": 81, "text": "Mostly Cloudy", "code": 28}, {"day": "Sat", "date": 1725120000, "high": 96, "low": 81, "text": "Thunderstorms", "code": 4}, {"day": "Sun", "date": 1725206400, "high": 96, "low": 83, "text": "Cloudy", "code": 26}, {"day": "Mon", "date": 1725292800, "high": 94, "low": 79, "text": "Cloudy", "code": 26}, {"day": "Tue", "date": 1725379200, "high": 89, "low": 78, "text": "Thunderstorms", "code": 4}, {"day": "Wed", "date": 1725465600, "high": 88, "low": 77, "text": "Showers", "code": 11}, {"day": "Thu", "date": 1725552000, "high": 87, "low": 80, "text": "Thunderstorms", "code": 4}, {"day": "Fri", "date": 1725638400, "high": 88, "low": 78, "text": "Showers", "code": 11}, {"day": "Sat", "date": 1725724800, "high": 95, "low": 80, "text": "Showers", "code": 11}, {"day": "Sun", "date": 1725811200, "high": 94, "low": 79, "text": "Showers", "code": 11}, {"day": "Mon", "date": 1725897600, "high": 95, "low": 80, "text": "Thunderstorms", "code": 4}]}
1+
{"coord": {"lon": -74.006, "lat": 40.7143}, "weather": [{"id": 804, "main": "Clouds", "description": "overcast clouds", "icon": "04d"}], "base": "stations", "main": {"temp": 293.61, "feels_like": 293.9, "temp_min": 291.79, "temp_max": 294.42, "pressure": 1020, "humidity": 84, "sea_level": 1020, "grnd_level": 1019}, "visibility": 10000, "wind": {"speed": 3.09, "deg": 60}, "clouds": {"all": 100}, "dt": 1725104455, "sys": {"type": 2, "id": 2037026, "country": "US", "sunrise": 1725099762, "sunset": 1725147007}, "timezone": -14400, "id": 5128581, "name": "New York", "cod": 200}

main.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,10 @@
4343

4444
class nfsWeather(MDApp):
4545
KV_DIRS = [os.path.join(os.getcwd(), "View")]
46+
DEBUG=True
4647

4748
def __init__(self, **kwargs):
4849
super().__init__(**kwargs)
49-
self.DEBUG = True
5050
self.theme_cls.primary_palette = "Indigo"
5151
self.theme_cls.primary_dark_hue = "800"
5252
self.theme_cls.primary_light_hue = "50"

0 commit comments

Comments
 (0)