-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdateAde.py
executable file
·69 lines (51 loc) · 1.7 KB
/
updateAde.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
#!/usr/bin/python3
import logging
logging.basicConfig(format='[%(levelname)s] %(message)s', level=logging.INFO)
from icalendar.discover import discoverAllGroups, discoverAll, discoverRemaining
from icalendar.update import updateAllGroups
from icalendar.creation import createCalendar, createCalendarGroup
from icalendar.notifiers.terminal import TerminalNotifier
from icalendar.notifiers.discord import DiscordNotifier
from sources import getSources
import sys
def help(exit_code=0) :
script_name = sys.argv[0]
print(f"usage : {script_name} --createGroup <group_name> <source_name>")
print(f" {script_name} --createCal <group_name> <cal_name>")
print(f" {script_name} --sources")
print(f" {script_name} [-n] --update")
print(f" {script_name} [-n] --all")
print(f" {script_name} [-n] --remaining")
sys.exit(exit_code)
if __name__ == '__main__' :
args = sys.argv[1:]
if len(args) > 0 and args[0] == '-n' :
args = args[1:]
notifier = TerminalNotifier()
else :
notifier = DiscordNotifier()
if len(args) > 0 and args[0] in ['-h', '--help'] :
help(0)
if len(args) == 0 :
help(1)
if args[0] == '--update' :
updateAllGroups(notifier)
sys.exit(0)
if args[0] == '--all' :
discoverAllGroups(discoverAll, notifier)
sys.exit(0)
if args[0] == '--remaining' :
discoverAllGroups(discoverRemaining, notifier)
sys.exit(0)
if args[0] == '--sources' :
for source in getSources() :
print(source)
sys.exit(0)
if args[0] == '--createGroup' :
if len(args) < 3 :
help(1)
sys.exit(0 if createCalendarGroup(args[1], args[2]) else 1)
if args[0] == '--createCal' :
if len(args) < 3 :
help(1)
sys.exit(0 if createCalendar(args[1], args[2]) else 1)