-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathkv7kalender-index.py
34 lines (28 loc) · 1.14 KB
/
kv7kalender-index.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
from gzip import GzipFile
import sys
import os
import codecs
from datetime import datetime,timedelta
output = codecs.open('kv7kalender.idx', 'w', 'UTF-8')
lastupdated_filenames = {}
kalender_filenames = [sys.argv[1] + '/' + x for x in os.listdir(sys.argv[1])]
kalender_threshold = (datetime.now() - timedelta(days=3)).isoformat()
for filename in sorted(kalender_filenames):
f = GzipFile(filename, 'r')
try:
firstline = f.readline()[:-1]
values = firstline.split('|')
subscription = values[2]
creationdate = values[7]
if (creationdate < kalender_threshold):
continue
if subscription not in lastupdated_filenames:
lastupdated_filenames[subscription] = {'filename' : filename, 'creationdate' : creationdate}
elif creationdate > lastupdated_filenames[subscription]['creationdate']:
lastupdated_filenames[subscription] = {'filename' : filename, 'creationdate' : creationdate}
finally:
f.close()
for key, values in lastupdated_filenames.items():
print key + ' - ' + values['filename']
output.write(values['filename']+'\n')
output.close()