Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions HyprV/waybar/conf/mesu-imp.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@
"tooltip" : true,
"format" : "{}",
"interval" : 30,
"exec" : "~/.config/HyprV/waybar/scripts/waybar-wttr.py",
// add your postal code (zip code) to the end of this line to customize
// the weathers location. you can also use a 3 letter airport code instead of
// a postal code.
// ex: "~/.config/HyprV/waybar/scripts/waybar-wttr.py 12345",
"exec" : "~/.config/HyprV/waybar/scripts/waybar-wttr.py ",
"return-type" : "json"
},

Expand All @@ -22,4 +26,4 @@
"format-critical": " {temperatureF}°F",
"on-click": "kitty --start-as=fullscreen --title btop sh -c 'btop'"
}
}
}
16 changes: 15 additions & 1 deletion HyprV/waybar/scripts/waybar-wttr.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env python

import sys
import json
import requests
from datetime import datetime
Expand Down Expand Up @@ -57,8 +58,21 @@

data = {}

def get_ip():
response = requests.get("https://api64.ipify.org?format=json").json()
return response["ip"]

weather = requests.get("https://wttr.in/?format=j1").json()
def get_zip():
ip_address = get_ip()
response = requests.get(f"https://ipapi.co/{ip_address}/json").json()
return response["postal"]

if len(sys.argv) > 1:
postal = sys.argv[1]
else:
postal = get_zip()

weather = requests.get(f"https://wttr.in/{postal}?format=j1").json()


def format_time(time):
Expand Down