-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
251 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
--- | ||
- name: Create waybar config folder | ||
become: true | ||
ansible.builtin.file: | ||
path: "{{ swayusr.home }}/.config/waybr/" | ||
state: directory | ||
mode: '0750' | ||
owner: "{{ swayusr.user }}" | ||
group: "{{ swayusr.user }}" | ||
|
||
- name: Deploy waybar weather script | ||
become: true | ||
ansible.builtin.template: | ||
src: 'templates/wttr.py.j2' | ||
dest: "{{ swayusr.home }}/.config/waybar/wttr.py" | ||
mode: '0750' | ||
owner: "{{ swayusr.user }}" | ||
group: "{{ swayusr.user }}" | ||
|
||
- name: Deploy waybar stylesheet | ||
become: true | ||
ansible.builtin.template: | ||
src: 'templates/waybar.css.j2' | ||
dest: "{{ swayusr.home }}/.config/waybar/style.css" | ||
mode: '0640' | ||
owner: "{{ swayusr.user }}" | ||
group: "{{ swayusr.user }}" | ||
|
||
- name: Deploy waybar config | ||
become: true | ||
ansible.builtin.template: | ||
src: 'templates/waybar.json.j2' | ||
dest: "{{ swayusr.home }}/.config/waybar/config" | ||
mode: '0640' | ||
owner: "{{ swayusr.user }}" | ||
group: "{{ swayusr.user }}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,194 @@ | ||
#!/usr/bin/env python | ||
""" | ||
wttr.in waybar widget | ||
{{ ansible_managed }} | ||
""" | ||
import json | ||
from datetime import datetime | ||
import requests | ||
|
||
localization = { | ||
"en": { | ||
"feels_like": "Feels like", | ||
"wind": "Wind", | ||
"humidity": "Humidity", | ||
"today": "Today", | ||
"tomorrow": "Tomorrow", | ||
"weatherDesc": "weatherDesc", | ||
"chanceoffog": "Fog", | ||
"chanceoffrost": "Frost", | ||
"chanceofovercast": "Overcast", | ||
"chanceofrain": "Rain", | ||
"chanceofsnow": "Snow", | ||
"chanceofsunshine": "Sunshine", | ||
"chanceofthunder": "Thunder", | ||
"chanceofwindy": "Wind", | ||
"weatherfor": "Weather for" | ||
}, | ||
"de": { | ||
"feels_like": "Gefühlt wie", | ||
"wind": "Wind", | ||
"humidity": "Luftfeuchtigkeit", | ||
"today": "Heute", | ||
"tomorrow": "Morgen", | ||
"weatherDesc": "lang_de", | ||
"chanceoffog": "Nebel", | ||
"chanceoffrost": "Frost", | ||
"chanceofovercast": "Bewölkt", | ||
"chanceofrain": "Regen", | ||
"chanceofsnow": "Schnee", | ||
"chanceofsunshine": "Sonne", | ||
"chanceofthunder": "Gewitter", | ||
"chanceofwindy": "Wind", | ||
"weatherfor": "Wetter für" | ||
}, | ||
"el": { | ||
"feels_like": "Πραγματική αίσθηση", | ||
"wind": "Άνεμος", | ||
"humidity": "Υγρασία", | ||
"today": "Σήμερα", | ||
"tomorrow": "Αύριο", | ||
"day_after_tomorrow": "Μεθαύριο", | ||
"weatherDesc": "lang_el", | ||
"chanceoffog": "Ομίχλη", | ||
"chanceoffrost": "Παγετός", | ||
"chanceofovercast": "Πυκνή νέφωση", | ||
"chanceofrain": "Βροχή", | ||
"chanceofsnow": "Χιόνι", | ||
"chanceofsunshine": "Λιακάδα", | ||
"chanceofthunder": "Κεραυνοί", | ||
"chanceofwindy": "Άνεμος", | ||
"weatherfor": "Καιρός για" | ||
} | ||
} | ||
|
||
LANG = "de" | ||
text = localization[LANG] | ||
|
||
WEATHER_CODES = { | ||
'113': '☀️', | ||
'116': '⛅️', | ||
'119': '☁️', | ||
'122': '☁️', | ||
'143': '🌫', | ||
'176': '🌦', | ||
'179': '🌧', | ||
'182': '🌧', | ||
'185': '🌧', | ||
'200': '⛈', | ||
'227': '🌨', | ||
'230': '❄️', | ||
'248': '🌫', | ||
'260': '🌫', | ||
'263': '🌦', | ||
'266': '🌦', | ||
'281': '🌧', | ||
'284': '🌧', | ||
'293': '🌦', | ||
'296': '🌦', | ||
'299': '🌧', | ||
'302': '🌧', | ||
'305': '🌧', | ||
'308': '🌧', | ||
'311': '🌧', | ||
'314': '🌧', | ||
'317': '🌧', | ||
'320': '🌨', | ||
'323': '🌨', | ||
'326': '🌨', | ||
'329': '❄️', | ||
'332': '❄️', | ||
'335': '❄️', | ||
'338': '❄️', | ||
'350': '🌧', | ||
'353': '🌦', | ||
'356': '🌧', | ||
'359': '🌧', | ||
'362': '🌧', | ||
'365': '🌧', | ||
'368': '🌨', | ||
'371': '❄️', | ||
'374': '🌧', | ||
'377': '🌧', | ||
'386': '⛈', | ||
'389': '🌩', | ||
'392': '⛈', | ||
'395': '❄️' | ||
} | ||
|
||
data = {} | ||
|
||
|
||
weather = requests.get(f"https://{LANG}.wttr.in/?format=j1", timeout=10).json() | ||
|
||
|
||
def format_time(time): | ||
""" | ||
Make sure times get properly formated... | ||
""" | ||
return time.replace("00", "").zfill(2) | ||
|
||
|
||
def format_temp(temp): | ||
""" | ||
Make sure temperature get properly formated... | ||
""" | ||
return (f"{temp}°").ljust(3) | ||
|
||
def format_chances(format_hour): | ||
""" | ||
Make sure weather wil be properly ranslated | ||
""" | ||
chances = [ | ||
"chanceoffog", | ||
"chanceoffrost", | ||
"chanceofovercast", | ||
"chanceofrain", | ||
"chanceofsnow", | ||
"chanceofsunshine", | ||
"chanceofthunder", | ||
"chanceofwindy" | ||
] | ||
|
||
probs = {text[e]: int(prb) for e, prb in format_hour.items() if e in chances and int(prb) > 0} | ||
sorted_probs = {e: probs[e] for e in sorted(probs, key=probs.get, reverse=True)} | ||
conditions = [f"{event} {prb}%" for event, prb in sorted_probs.items()] | ||
return ", ".join(conditions) | ||
|
||
data['text'] = f"{weather['nearest_area'][0]['areaName'][0]['value']}: " | ||
data['text'] += f"{WEATHER_CODES[weather['current_condition'][0]['weatherCode']]} " | ||
data['text'] += f"{weather['current_condition'][0]['FeelsLikeC']}°C" | ||
|
||
WEATHER_DESC = text['weatherDesc'] | ||
data['tooltip'] = f"<b>{text['weatherfor']} " | ||
data['tooltip'] += f"{weather['nearest_area'][0]['areaName'][0]['value']}, " | ||
data['tooltip'] += f"{weather['nearest_area'][0]['country'][0]['value']}:</b>\n\n" | ||
data['tooltip'] += f"<b>{weather['current_condition'][0][WEATHER_DESC][0]['value']}" | ||
data['tooltip'] += f"{weather['current_condition'][0]['temp_C']}°</b>\n" | ||
data['tooltip'] += f"{text['feels_like']}: " | ||
data['tooltip'] += f"{weather['current_condition'][0]['FeelsLikeC']}°\n" | ||
data['tooltip'] += f"{text['wind']}: " | ||
data['tooltip'] += f"{weather['current_condition'][0]['windspeedKmph']}Km/h\n" | ||
data['tooltip'] += f"{text['humidity']}: {weather['current_condition'][0]['humidity']}%\n" | ||
for i, day in enumerate(weather['weather']): | ||
data['tooltip'] += "\n<b>" | ||
if i == 0: | ||
data['tooltip'] += f"{text['today']}, " | ||
if i == 1: | ||
data['tooltip'] += f"{text['tomorrow']}, " | ||
if i == 2 and 'day_after_tomorrow' in text: | ||
data['tooltip'] += f"{text['day_after_tomorrow']}, " | ||
data['tooltip'] += f"{day['date']}</b>\n" | ||
data['tooltip'] += f"⬆️ {day['maxtempC']}° ⬇️ {day['mintempC']}° " | ||
data['tooltip'] += f"🌅 {day['astronomy'][0]['sunrise']} 🌇 {day['astronomy'][0]['sunset']}\n" | ||
for hour in day['hourly']: | ||
if i == 0: | ||
if int(format_time(hour['time'])) < datetime.now().hour-2: | ||
continue | ||
data['tooltip'] += f"{format_time(hour['time'])} " | ||
data['tooltip'] += f"{WEATHER_CODES[hour['weatherCode']]} " | ||
data['tooltip'] += f"{format_temp(hour['FeelsLikeC'])} " | ||
data['tooltip'] += f"{hour[WEATHER_DESC][0]['value']}, {format_chances(hour)}\n" | ||
|
||
|
||
print(json.dumps(data)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
--- | ||
playbook_version_number: 4 # should be int | ||
playbook_version_number: 5 # should be int | ||
playbook_version_path: 'role-roles-ansible.sway.version' |