aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/.gitignore15
-rwxr-xr-xsrc/panahone100
-rw-r--r--src/panahone.pngbin0 -> 16653 bytes
-rw-r--r--src/requirements.txt7
4 files changed, 122 insertions, 0 deletions
diff --git a/src/.gitignore b/src/.gitignore
new file mode 100644
index 0000000..9c64fb6
--- /dev/null
+++ b/src/.gitignore
@@ -0,0 +1,15 @@
+__pycache__/
+*.py[cod]
+*.swp
+*.log
+env/
+venv/
+.venv/
+.vscode/
+*.vscode/
+.idea/
+*.idea/
+*.vscode/
+*.atom/
+.DS_Store # macOS
+Thumbs.db # Windows
diff --git a/src/panahone b/src/panahone
new file mode 100755
index 0000000..0332a92
--- /dev/null
+++ b/src/panahone
@@ -0,0 +1,100 @@
+#!/usr/bin/env python3
+
+import argparse
+import gi
+import requests
+import signal
+import warnings
+# import sys
+# import json
+
+# will fix this when it breaks :D
+warnings.filterwarnings(
+ "ignore",
+ category=DeprecationWarning,
+ message="Gtk.StatusIcon.*",
+)
+
+gi.require_version("Gtk", "3.0")
+gi.require_version("Notify", "0.7")
+from gi.repository import Gtk, Notify
+
+
+class PanahoneApplet:
+ def __init__(self, location, use_fahrenheit):
+ icon_file = "./panahone.png"
+
+ self.location = location or ""
+ self.use_fahrenheit = use_fahrenheit
+ Notify.init("Panahone")
+ self.icon = Gtk.StatusIcon()
+ self.icon.set_from_file(icon_file)
+ self.icon.set_tooltip_text("Panahone: click to get weather")
+ self.icon.connect("button-press-event", self.on_click)
+ signal.signal(signal.SIGINT, self.quit)
+
+ def on_click(self, icon, event):
+ if event.button == 1:
+ Notify.Notification.new(
+ "Panahone",
+ "Retrieving Weather Data…",
+ "weather"
+ ).show()
+ self.fetch_and_notify()
+ elif event.button == 2:
+ self.quit()
+
+ def fetch_and_notify(self):
+ if not self.location:
+ url = "https://wttr.in/?format=j1"
+ else:
+ url = f"https://wttr.in/{self.location}?format=j1"
+ try:
+ r = requests.get(url, timeout=10)
+ data = r.json()
+ current = data["current_condition"][0]
+ location = data["nearest_area"][0]["areaName"][0]["value"]
+ temp_c = current["temp_C"]
+ temp_f = current["temp_F"]
+ unit = "°F" if self.use_fahrenheit else "°C"
+ temp = temp_f if self.use_fahrenheit else temp_c
+ weather = current["weatherDesc"][0]["value"]
+ message = f"Weather in {location}: {weather}, Temp: {temp}{unit}"
+ except Exception as e:
+ if not self.location:
+ message = f"Error fetching weather: {e}"
+ else:
+ message = f"Error fetching weather for {self.location}: {e}"
+
+ Notify.Notification.new(
+ "Panahone",
+ message,
+ "weather"
+ ).show()
+
+ def quit(self, *args):
+ Gtk.main_quit()
+
+ def run(self):
+ Gtk.main()
+
+
+def parse_args():
+ p = argparse.ArgumentParser(prog="panahone")
+ p.add_argument("-l", "--location", help="location for weather")
+ p.add_argument("-f", "--fahrenheit", action="store_true",
+ help="use Fahrenheit instead of Celsius")
+ return p.parse_args()
+
+
+def main():
+ args = parse_args()
+ app = PanahoneApplet(args.location, args.fahrenheit)
+ try:
+ app.run()
+ except KeyboardInterrupt:
+ app.quit()
+
+
+if __name__ == "__main__":
+ main()
diff --git a/src/panahone.png b/src/panahone.png
new file mode 100644
index 0000000..5ab2b0d
--- /dev/null
+++ b/src/panahone.png
Binary files differ
diff --git a/src/requirements.txt b/src/requirements.txt
new file mode 100644
index 0000000..7c78635
--- /dev/null
+++ b/src/requirements.txt
@@ -0,0 +1,7 @@
+certifi==2025.7.14
+charset-normalizer==3.4.2
+idna==3.10
+pycairo==1.28.0
+PyGObject==3.52.3
+requests==2.32.4
+urllib3==2.5.0