-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathankistatsmenu copy.py
109 lines (90 loc) · 3.92 KB
/
ankistatsmenu copy.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
import json
import urllib.request
def request(action, **params):
return {"action": action, "params": params, "version": 6}
def invoke(action, **params):
requestJson = json.dumps(request(action, **params)).encode("utf-8")
response = json.load(urllib.request.urlopen(urllib.request.Request("http://localhost:8765", requestJson)))
if len(response) != 2:
raise Exception("response has an unexpected number of fields")
if "error" not in response:
raise Exception("response is missing required error field")
if "result" not in response:
raise Exception("response is missing required result field")
if response["error"] is not None:
raise Exception(response["error"])
return response["result"]
""" invoke("createDeck", deck="test1") """
def curanki():
Japanese = len(invoke("findCards", query='"deck:2 日本語" is:due'))
Deutsch = len(invoke("findCards", query='"deck:0 Deutsch" is:due'))
Programming = len(invoke("findCards", query='"deck:0 Programming::0 CP Past Problem Tricks" is:due'))
Español = len(invoke("findCards", query='"deck:3 Español (Audible)" is:due'))
医学 = len(invoke("findCards", query='"deck:1 医学::MTW deck" is:due'))
return (Japanese, Deutsch, Programming, Español, 医学)
import rumps
collection = []
class AwesomeStatusBarApp(rumps.App):
def __init__(self):
"""temp = curanki()
a = "Japanese: {} Deutsch: {} Programming: {} Español: {} 医学: {}".format(
temp[0], temp[1], temp[2], temp[3], temp[4]
)"""
""" self.icon= """
super(AwesomeStatusBarApp, self).__init__("Start by adding your first deck!")
""" @rumps.clicked("Update")
def test(self, _):
temp = curanki()
a = "Japanese: {} Deutsch: {} Programming: {} Español: {} 医学: {}".format(
temp[0], temp[1], temp[2], temp[3], temp[4]
)
self.title = a """
@rumps.clicked("Add decks")
def test2(self, sender):
window = rumps.Window(f"Current:", "Add another deck to menu bar display")
""" window.icon = self.icon """
response = window.run()
""" temp = curanki() """
""" finding = len(invoke("findCards", query='"deck:{}" is:due'.format(response.text))) """
""" a = "Japanese: {} Deutsch: {} Programming: {} Español: {} 医学: {}".format(
temp[0], temp[1], temp[2], temp[3], temp[4]
) """
if response.text != "":
collection.append(response.text)
finaltitle = ""
for x in collection:
finaltitle += x
finaltitle += ": "
finaltitle += str(len(invoke("findCards", query='"deck:{}" is:due'.format(x))))
finaltitle += " "
""" print(finaltitle) """
""" self.title = "{}: {}".format(response.text, finding) """
self.title = finaltitle
@rumps.clicked("Remove decks")
def test3(self, sender):
window = rumps.Window(f"Current:", "Remove a deck from the menu bar display")
""" window.icon = self.icon """
response = window.run()
collection.remove(response.text)
finaltitle = ""
for x in collection:
finaltitle += x
finaltitle += ": "
finaltitle += str(len(invoke("findCards", query='"deck:{}" is:due'.format(x))))
finaltitle += " "
""" print(finaltitle) """
""" self.title = "{}: {}".format(response.text, finding) """
self.title = finaltitle
@rumps.timer(30)
def prefs(self, _):
finaltitle = ""
for x in collection:
finaltitle += x
finaltitle += ": "
finaltitle += str(len(invoke("findCards", query='"deck:{}" is:due'.format(x))))
finaltitle += " "
""" print(finaltitle) """
""" self.title = "{}: {}".format(response.text, finding) """
self.title = finaltitle
if __name__ == "__main__":
AwesomeStatusBarApp().run()