forked from brifsttar/tapudsou
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
51 lines (39 loc) · 1.42 KB
/
main.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
from tkinter.messagebox import showinfo
import argparse
import webbrowser
import requests
import keyring
def message_box(title, text):
return showinfo(title, text)
def main():
parser = argparse.ArgumentParser()
parser.add_argument('username')
parser.add_argument('threshold', type=float, help='Account balance in € below which to alert')
args = parser.parse_args()
pwd = keyring.get_password("tapudsou", args.username)
if not pwd:
message_box("Tapudsou", f"Impossible de trouver le mot de passe")
return
headers = {
"password": pwd,
"rememberMe": "false",
"grant_type": "password",
"brandId": 1249,
"username": args.username,
}
with requests.Session() as s:
r = s.post("https://api.innovorder.fr/oauth/login", headers)
rr = r.json()
customer_id = rr['data']['customer']['customerId']
headers = {
"authorization": f"Bearer {rr['access_token']}"
}
r = s.get(f"https://api.innovorder.fr/customers/{customer_id}/balance", headers=headers)
rr = r.json()
balance = rr['data']['customerBalance']
balance = float(balance) / 100.
if balance < args.threshold:
message_box("Tapudsou", f"Il reste {balance}€ sur ta carte de cantine!")
webbrowser.open_new_tab("https://ewallet.innovorder.fr/1249/home")
if __name__ == '__main__':
main()