-
Notifications
You must be signed in to change notification settings - Fork 0
/
ics_infos.py
61 lines (45 loc) · 1.43 KB
/
ics_infos.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
#!/bin/python3
# coding: utf-8
import argparse
import datetime
from icalendar import Calendar
import urllib.request
import sys
def parse_args():
"""Arguments parsing."""
parser = argparse.ArgumentParser(description='Basic instruction parser')
parser.add_argument('input',
type=str,
help='ICS file')
args = parser.parse_args()
return args
if __name__ == '__main__':
# Arguments parsing
args = parse_args()
# Load config
input_file = args.input
cal = None
if input_file.startswith('http'):
ics_file = urllib.request.urlopen(input_file)
cal = Calendar.from_ical(ics_file.read())
else:
with open(input_file, 'r') as ics_file:
try:
cal = Calendar.from_ical(ics_file.read())
except ValueError as e:
print("[!] Input file is not an ICalendar file")
sys.exit(1)
vevents = cal.walk("VEVENT")
count = len(vevents)
dates = [i.decoded('DTSTART') for i in vevents if type(i.decoded('DTSTART')) != datetime.date]
minDate = min(*dates)
maxDate = max(*dates)
# print('Dates:')
# for i in dates: print(i)
first = vevents[0]
keys = list(dict(first).keys())
print("Keys : %s" % keys)
print("Calendar %s" % input_file)
print("Events count %d" % count)
print("Events from %s" % minDate)
print("Events to %s" % maxDate)