-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
78 lines (62 loc) · 2.81 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
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
import os
import sys
from dealabs import Dealabs, Utils
from dotenv import load_dotenv
load_dotenv()
def help():
print("""Usage: python3 main.py [refresh_seconds] [minimum_discount] [free_products] [expire_notification] [open_dealabs] [priority_only_first] [free_products_priority]
- refresh_seconds: Nombre de secondes entre chaque rafraichissement
- minimum_discount: Pourcentage minimum de réduction pour être notifié
- free_products: Être notifié des produits gratuits
- expire_notification: Recevoir une notification avant que les tokens pushover ne soient expirés
- open_dealabs: Ouvrir dealabs au lieu du site du deal
- priority_only_first: Notifier uniquement en priorité a l'apparition du deal et pas à chaque mise à jour
- free_products_priority: Envoi également les notifications des produits gratuit en priorité
""")
sys.exit(0)
def main(args):
if os.getenv("PUSHOVER_TOKEN") is None:
print("PUSHOVER_TOKEN not found in .env file")
exit(1)
if os.getenv("PUSHOVER_USER") is None:
print("PUSHOVER_USER not found in .env file")
exit(1)
if len(args) > 0 and "h" in args[0]:
help()
# Prend les arguments donnés en priorité puis les variables d'environnement, sinon prend les valeurs par défaut
if len(args) > 0:
refresh_seconds = int(args[0])
else:
refresh_seconds = int(os.getenv("REFRESH_SECONDS")) if os.getenv("REFRESH_SECONDS") else 60
if len(args) > 1:
minimum_discount = int(args[1])
else:
minimum_discount = int(os.getenv("MIN_DISCOUNT")) if os.getenv("MIN_DISCOUNT") else 90
if len(args) > 2:
free_products = int(args[2])
else:
free_products = int(os.getenv("FREE_PRODUCTS")) if os.getenv("FREE_PRODUCTS") else 0
if len(args) > 3:
expire_notification = int(args[3])
else:
expire_notification = int(os.getenv("EXPIRE_NOTIFICATION")) if os.getenv("EXPIRE_NOTIFICATION") else 0
if len(args) > 4:
open_dealabs = int(args[4])
else:
open_dealabs = int(os.getenv("OPEN_DEALABS")) if os.getenv("OPEN_DEALABS") else 1
if len(args) > 5:
priority_only_first = int(args[5])
else:
priority_only_first = int(os.getenv("PRIORITY_ONLY_FIRST")) if os.getenv("PRIORITY_ONLY_FIRST") else 1
if len(args) > 6:
free_products_priority = int(args[6])
else:
free_products_priority = int(os.getenv("FREE_PRODUCTS_PRIORITY")) if os.getenv("FREE_PRODUCTS_PRIORITY") else 0
dealabs = Dealabs(minimum_discount, free_products, expire_notification, open_dealabs, priority_only_first, free_products_priority)
dealabs.setPushOver(os.getenv("PUSHOVER_TOKEN"), os.getenv("PUSHOVER_USER"))
dealabs.watch(refresh_seconds)
if __name__ == "__main__":
try:
main(sys.argv[1:])
except KeyboardInterrupt:
pass