Skip to content

Instantly share code, notes, and snippets.

@bjesus
Last active September 22, 2025 16:10
Show Gist options
  • Save bjesus/f8db49e1434433f78e5200dc403d58a3 to your computer and use it in GitHub Desktop.
Save bjesus/f8db49e1434433f78e5200dc403d58a3 to your computer and use it in GitHub Desktop.

Revisions

  1. bjesus revised this gist Apr 17, 2023. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,3 @@
    This Python script is not maintained and was replaced by the more robust Rust version below:

    https://github.com/bjesus/wttrbar
  2. bjesus revised this gist Sep 13, 2020. 2 changed files with 2 additions and 2 deletions.
    2 changes: 1 addition & 1 deletion config.json
    Original file line number Diff line number Diff line change
    @@ -2,6 +2,6 @@
    "format": "{}",
    "tooltip": true,
    "interval": 3600,
    "exec": "/home/bjesus/.scripts/waybar_weather.py",
    "exec": "waybar-wttr.py",
    "return-type": "json"
    },
    2 changes: 1 addition & 1 deletion waybar-wttr.py
    Original file line number Diff line number Diff line change
    @@ -58,7 +58,7 @@
    data = {}


    weather = requests.get("https://wttr.in/Sodermalm?format=j1").json()
    weather = requests.get("https://wttr.in/?format=j1").json()


    def format_time(time):
  3. bjesus created this gist Sep 13, 2020.
    7 changes: 7 additions & 0 deletions config.json
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,7 @@
    "custom/weather": {
    "format": "{}",
    "tooltip": true,
    "interval": 3600,
    "exec": "/home/bjesus/.scripts/waybar_weather.py",
    "return-type": "json"
    },
    114 changes: 114 additions & 0 deletions waybar-wttr.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,114 @@
    #!/usr/bin/env python

    import json
    import requests
    from datetime import datetime

    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("https://wttr.in/Sodermalm?format=j1").json()


    def format_time(time):
    return time.replace("00", "").zfill(2)


    def format_temp(temp):
    return (hour['FeelsLikeC']+"Β°").ljust(3)


    def format_chances(hour):
    chances = {
    "chanceoffog": "Fog",
    "chanceoffrost": "Frost",
    "chanceofovercast": "Overcast",
    "chanceofrain": "Rain",
    "chanceofsnow": "Snow",
    "chanceofsunshine": "Sunshine",
    "chanceofthunder": "Thunder",
    "chanceofwindy": "Wind"
    }

    conditions = []
    for event in chances.keys():
    if int(hour[event]) > 0:
    conditions.append(chances[event]+" "+hour[event]+"%")
    return ", ".join(conditions)


    data['text'] = WEATHER_CODES[weather['current_condition'][0]['weatherCode']] + \
    " "+weather['current_condition'][0]['FeelsLikeC']+"Β°"

    data['tooltip'] = f"<b>{weather['current_condition'][0]['weatherDesc'][0]['value']} {weather['current_condition'][0]['temp_C']}Β°</b>\n"
    data['tooltip'] += f"Feels like: {weather['current_condition'][0]['FeelsLikeC']}Β°\n"
    data['tooltip'] += f"Wind: {weather['current_condition'][0]['windspeedKmph']}Km/h\n"
    data['tooltip'] += f"Humidity: {weather['current_condition'][0]['humidity']}%\n"
    for i, day in enumerate(weather['weather']):
    data['tooltip'] += f"\n<b>"
    if i == 0:
    data['tooltip'] += "Today, "
    if i == 1:
    data['tooltip'] += "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'])} {WEATHER_CODES[hour['weatherCode']]} {format_temp(hour['FeelsLikeC'])} {hour['weatherDesc'][0]['value']}, {format_chances(hour)}\n"


    print(json.dumps(data))