-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSingMenuData.py
29 lines (21 loc) · 938 Bytes
/
SingMenuData.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import rumps, requests, bs4, time
class SingMenuData(rumps.App):
def __init__(self, title):
super(SingMenuData, self).__init__(title)
self.title = "loading..."
self.last_update = time.time()
@rumps.clicked("update")
def sayhi(self, _):
self.request_data(False)
@rumps.timer(60)
def request_data(self, sender):
doc = bs4.BeautifulSoup(requests.get("https://hi.singtel.com/welcome.do").text, "html.parser")
totals = doc.select(".divTblSocialPlans .tblRowMiddle span")
total = sum(map((lambda plan: int(plan.getText().strip().split()[0])), totals))
self.title = str(total) + " MB"
self.last_update = time.time()
@rumps.timer(1)
def update_menu(self, sender):
self._menu['update'].title = "Updated " + str(int(time.time() - self.last_update)) + " seconds ago"
if __name__ == "__main__":
SingMenuData("Singtel Data").run()