Last active
April 25, 2022 08:32
-
-
Save debendraoli/ef302ae1187c4126ed02d12403c7f318 to your computer and use it in GitHub Desktop.
Get Nepali date tithi meeti on status bar
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
#!/usr/bin/env python | |
""" | |
@uthor @debendraoli | |
Compitable with waybar. | |
""" | |
import re | |
from json import dumps | |
from urllib.request import Request, urlopen | |
url = "https://www.hamropatro.com" | |
req = Request( | |
url=url, | |
headers={ | |
"User-Agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/101.0.4430.72 Safari/537.36" | |
}, | |
) | |
try: | |
with urlopen(req) as res: | |
regex = r'<div class="logo">\n<div class="date">\n<span class="nep">\n(.+), .+ <\/span>\n<br \/>\n<\/div>\n<div style="margin: 10px 0; color: white; font-size: 1.3rem">\n(.+) <\/div>\n<div style="line-height: 1.9">\n.+:\n(.+) (:?, <a class="event" href=\'\/date\/([0-9-]{8,10})\' style=\'text-decoration:none;color:#ffffff;pointer:cursor;\'>\n(.+)<\/a>\n)?<\/div>\n<div class="time">\n<span> (.+)<\/span><br \/>\n<span class="eng"> ([a-zA-z0-9\s,]+) <\/span>\n<br \/>\n<\/div>' | |
search_dates = re.search(regex, res.read().decode("utf-8", "ignore")) | |
( | |
nepali_date, | |
tithi, | |
panchang, | |
_, | |
_, | |
_, | |
nepali_clock, | |
eng_date, | |
) = search_dates.groups() | |
format_date = { | |
"text": " ".join(nepali_date), | |
"alt": f"<small>{tithi} {panchang}</small><br/>{nepali_clock}, {eng_date}", | |
"tooltip": f"{tithi}, {panchang}", | |
"class": "custom-nepal_clock", | |
} | |
print(dumps(format_date, ensure_ascii=False)) | |
except Exception as e: | |
raise e |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
preview: