mirror of
https://github.com/roles-ansible/ansible_role_i3wm.git
synced 2024-08-16 10:09:53 +02:00
Create waybar config
This commit is contained in:
parent
7e988b5315
commit
932c0817a5
6 changed files with 251 additions and 4 deletions
|
@ -18,6 +18,7 @@ sway__keyboard_settings: true
|
|||
sway__keyboard_lang: 'de'
|
||||
sway__lock: 'swaylock --color 000000 --image /usr/share/backgrounds/sway/Sway_Wallpaper_Blue_1920x1080.png'
|
||||
sway__waybar: true
|
||||
sway__waybar_modules_right: ["idle_inhibitor", "custom/weather", "pulseaudio", "network", "cpu", "memory", "temperature", "backlight", "keyboard-state", "sway/language", "battery", "clock", "tray"]
|
||||
|
||||
sway__keybindings:
|
||||
- keybinding:
|
||||
|
|
|
@ -17,6 +17,15 @@
|
|||
ansible.builtin.import_tasks:
|
||||
file: "config.yml"
|
||||
|
||||
- name: Create waybar config
|
||||
ansible.builtin.include_tasks:
|
||||
file: "waybar.yml"
|
||||
loop: "{{ sway__user_list | flatten(1) }}"
|
||||
loop_control:
|
||||
loop_var: swayusr
|
||||
label: "{{ swayusr.home }}/.config/waybar/"
|
||||
when: sway__waybar | bool
|
||||
|
||||
# - name: Ensure i3 packages are installed [Archlinux}
|
||||
# ansible.builtin.include_tasks:
|
||||
# file: setup-Archlinux.yml
|
||||
|
|
36
tasks/waybar.yml
Normal file
36
tasks/waybar.yml
Normal file
|
@ -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 }}"
|
|
@ -6,9 +6,9 @@
|
|||
// "width": 1280, // Waybar width
|
||||
"spacing": 4, // Gaps between modules (4px)
|
||||
// Choose the order of the modules
|
||||
"modules-left": ["sway/workspaces", "sway/mode", "sway/scratchpad", "custom/media"],
|
||||
"modules-left": ["sway/workspaces", "sway/mode", "sway/scratchpad"],
|
||||
"modules-center": ["sway/window"],
|
||||
"modules-right": ["idle_inhibitor", "pulseaudio", "network", "cpu", "memory", "temperature", "backlight", "keyboard-state", "sway/language", "battery", "clock", "tray"],
|
||||
"modules-right": {{ sway__waybar_modules_right | tojson }},
|
||||
// Modules configuration
|
||||
"sway/workspaces": {
|
||||
"disable-scroll": false,
|
||||
|
@ -151,6 +151,13 @@
|
|||
"escape": true,
|
||||
"exec": "$HOME/.config/waybar/mediaplayer.py 2> /dev/null" // Script in resources folder
|
||||
// "exec": "$HOME/.config/waybar/mediaplayer.py --player spotify 2> /dev/null" // Filter player based on name
|
||||
}
|
||||
},
|
||||
"custom/weather": {
|
||||
"format": "{}",
|
||||
"tooltip": true,
|
||||
"interval": 900,
|
||||
"exec": "{{ swayusr.home }}/.config/waybar/wttr.py",
|
||||
"return-type": "json"
|
||||
},
|
||||
}
|
||||
|
||||
|
|
194
templates/wttr.py.j2
Normal file
194
templates/wttr.py.j2
Normal file
|
@ -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))
|
|
@ -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'
|
||||
|
|
Loading…
Reference in a new issue