-
Notifications
You must be signed in to change notification settings - Fork 0
/
rescue_time_status.py
41 lines (32 loc) · 1.07 KB
/
rescue_time_status.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
30
31
32
33
34
35
36
37
38
39
40
41
import rumps
import urllib2
import json
import webbrowser
import config
class RescueTimeStatus(rumps.App):
def __init__(self):
super(RescueTimeStatus, self).__init__("RescueTime Productivity")
self.menu = ["Logged", "Details", None]
self.update_stats()
@rumps.timer(300) # 5 minutes
def peridioc_update(self, sender):
self.update_stats()
def update_stats(self):
try:
data = urllib2.urlopen("https://www.rescuetime.com/anapi/data/?rs=day&format=json&key={}&rk=efficiency&pv=interval".format(config.key)).read()
except Exception:
return
data = json.loads(data)
prod_pulse = str(int(round(data['rows'][0][4])))
time_logged = data['rows'][0][1]
self.title = prod_pulse
self.menu['Logged'].title = seconds_to_datestr(time_logged)
@rumps.clicked("Details")
def go_to_dashboard(self):
webbrowser.open_new("https://www.rescuetime.com/dashboard")
def seconds_to_datestr(seconds):
m, s = divmod(seconds, 60)
h, m = divmod(m, 60)
return "%d:%02d:%02d" % (h, m, s)
if __name__ == "__main__":
RescueTimeStatus().run()