forked from voc/schedule
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathschedule2wiki.py
executable file
·55 lines (42 loc) · 1.74 KB
/
schedule2wiki.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
#!/usr/bin/env python3
import argparse
import json
from collections import OrderedDict
from datetime import datetime
from urllib.parse import quote_plus
import voc.tools
parser = argparse.ArgumentParser()
parser.add_argument('file', action="store", help="path to input.ods")
#parser.add_argument('-o', action="store", dest="output", help="output filename, e.g. events.wiki")
args = parser.parse_args()
with open(args.file) as f:
schedule_json = f.read()
schedule = json.JSONDecoder(object_pairs_hook=OrderedDict).decode(schedule_json)
lang_map = {
'de': 'de - German',
'en': 'en - English'
}
def to_wiki(event):
pagename = quote_plus(event['title'].replace(' ', '_'))
print('https://events.ccc.de/congress/2017/wiki/index.php/Session:{}?action=edit'.format(pagename))
wiki = '{{Session \n|' + (
"Is for kids=No\n|Has description={text}\n|Has session type={type}\n|Is organized by={persons}\n" +
"|Held in language={lang}\n|Has orga contact=\n").format(
text=event['description'],
type=event['type'],
persons=', '.join([ p['full_public_name'] for p in event['persons'] ]),
lang=lang_map[event['language']],
) + '}}\n'
h,m = event['duration'].split(':', 2)
duration = int(h)*60 + int(m)
wiki += '{{Event \n' + ("|Has subtitle={subtitle}\n|Has start time={startdate} \n" +
"|Has duration={duration} \n|Has session location=Room:{room}\n|GUID={guid}\n").format(
subtitle=event['subtitle'],
startdate=datetime.strptime(event['date'], '%Y-%m-%dT%H:%M:%S').strftime('%Y/%m/%d %H:%M'),
duration=duration,
room=event['room'],
guid=event['guid']
) + '}}'
print(wiki)
print("\n\n")
voc.tools.foreach_event(schedule, to_wiki)