-
Notifications
You must be signed in to change notification settings - Fork 77
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[BUG] Trying to make the weather widget work #103
Comments
temporary fix : but can't display "label_alt" items |
fix 2.0 : but when i try to acces the french information in 'curl.exe "wttr.in/Ixelles?format=j1&lang=fr"' (whit correct path in label and label_alt) nothing work |
I have solved this issue using an external python script to get the data from the api: weather:
type: "yasb.custom.CustomWidget"
options:
label: "\uf0c2 {data[current][temp]}\u00b0C|\uf773{data[current][humidity]}%"
label_alt: "\uf0c2 {data[current][weather][0][description]}"
class_name: "weather-widget"
exec_options:
run_cmd: python.exe <Path_to_script>\weather.py
run_interval: 3600000
return_format: "json" and the script is something like: import requests
import json
def get_location():
url = "https://ipinfo.io"
try:
response = requests.get(url)
response.raise_for_status() # Raise an HTTPError for bad responses (4xx and 5xx)
data = response.json()
location = data["loc"]
location = location.split(',')
return location
except requests.exceptions.RequestException as e:
print(f"Error: {e}")
def get_weather_data(api_key):
location = get_location()
url = "https://api.openweathermap.org/data/3.0/onecall"
params = {
"lat": float(location[0]),
"lon": float(location[1]),
"units": "metric",
"appid": api_key
}
try:
response = requests.get(url, params=params)
response.raise_for_status() # Raise an HTTPError for bad responses (4xx and 5xx)
# Print the JSON response
print(json.dumps(response.json(), indent=2))
except requests.exceptions.RequestException as e:
print(f"Error: {e}")
if __name__ == "__main__":
api_key = YOUR_API_KEY
get_weather_data(api_key) |
Expected Behavior
should display weather information collected by API
Current Behavior
display "{data[main][temp]}" instead
Possible Solution
Steps to Reproduce
add to config.yaml :
weather:
type: "yasb.custom.CustomWidget"
options:
label: "\uf0c2 {data[main][temp]}\u00b0c"
label_alt: "\uf0c2 {data[weather][0][description]}"
class_name: "weather-widget"
exec_options:
run_cmd: "curl.exe "http://api.weatherapi.com/v1/forecast.json?key=0244eac47d8c4bbcb7b205535231907&q=Brussels&days=1&aqi=no&alerts=no""
# run every hour
run_interval: 3600000
return_format: "json"
Context (Environment)
line 480 = run_cmd: "curl.exe "http://api.weatherapi.com/v1/forecast.json?key=0244eac47d8c4bbcb7b205535231907&q=Brussels&days=1&aqi=no&alerts=no""
log:
2023-07-20 12:33:39 INFO log.py: Yasb - Yet Another Status Bar
2023-07-20 12:33:39 ERROR config.py: The file 'C:\yasb-main\src\config.yaml' contains Parser Error(s). Please fix:
while parsing a block mapping
in "C:\yasb-main\src\config.yaml", line 480, column 9
expected , but found ''
in "C:\yasb-main\src\config.yaml", line 480, column 29
2023-07-20 12:33:40 ERROR config.py: User config file could not be loaded. Exiting Application.
when use alone in another terminale [ curl.exe http://api.weatherapi.com/v1/forecast.json?key=0244eac47d8c4bbcb7b205535231907&q=Brussels&days=1&aqi=no&alerts=no ] : {"location":{"name":"Brussels","region":"","country":"Belgium","lat":50.83,"lon":4.33,"tz_id":"Europe/Brussels","localtime_epoch":1689844265,"localtime":"2023-07-20 11:11"}, .......(too long to paste here)
The text was updated successfully, but these errors were encountered: