-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprocess.py
executable file
·63 lines (52 loc) · 1.66 KB
/
process.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
#!/usr/bin/env python3
import csv
import re
import json
import os
import unicodedata
"""
Given pelis.csv this script computes pelis.json
"""
def varify(s):
return ''.join(c for c in unicodedata.normalize('NFD', s)
if unicodedata.category(c) != 'Mn')
if __name__ == '__main__':
reader = csv.reader(open('pelis.csv'))
result = []
for row in reader:
match = re.match('([0-9]{2})/([0-9]{2})/([0-9]{4})', row[-1])
if match:
date = '%s-%s-%s'%(match.group(3), match.group(2), match.group(1))
else:
date = row[-1]
fqn = "%s (%s) %s %s [%s]"%(row[0], row[1], row[2], row[3], row[4])
result.append({
'title' : row[0],
'original_title': row[1],
'director' : row[2],
'year' : row[3],
'country' : row[4],
'date' : date,
'fqn' : varify(fqn).lower(),
})
json_data = json.dumps(result, indent=2)
# add padding (jsonp)
with open('pelis.jsonp', 'w') as jsonp:
jsonp.write('mvm.loadItems(')
jsonp.write(json_data)
jsonp.write(');')
dir_name = "%s_%s"%(date, row[0])
if not os.path.isdir('proyecciones/%s'%dir_name):
os.mkdir('proyecciones/%s'%dir_name)
with open('proyecciones/%s/data.yaml'%dir_name, 'w') as data_file:
data_file.write("""Título original: {0}
Año: {1}
Duración: <n> min.
País: {2}
Director: {3}
Guión: <guión>
Música: <música>
Fotografía: <fotografía>
Género: <genero>
Sinopsis:
Bla bla bla""".format(row[0], row[3], row[4], row[2]))