-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathRGPD2csv.py
executable file
·52 lines (47 loc) · 1.19 KB
/
RGPD2csv.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
from __future__ import unicode_literals
import codecs
from ruffus import *
import csv
import re
import string
@files('RGPD_art.txt', 'RGPD_artutf8.txt')
def sample(infile, outfile):
with open(infile, 'r') as f:
# lines = [line for i,line in enumerate(f.readlines()) if i<50]
lines = f.readlines()
with codecs.open(outfile, 'w', encoding='utf-8') as f:
for line in lines:
f.write(line.decode("latin1"))
@follows(sample)
@files('RGPD_artutf8.txt', 'RGPD_art.tsv')
def extract(infile, outfile):
g = codecs.open(outfile, 'w', encoding='utf-8')
with codecs.open(infile, 'r', encoding='utf-8') as f:
lines = f.readlines()
str=""
newline = False
foundArticle = False
for line in lines:
if line.find('Article') != -1:
if newline == True:
g.write("\"" + str + "\"\n")
newline = False
foundArticle = True
str=""
Art = line.strip()
g.write("\"" + Art + "\"\t")
else:
if foundArticle == True:
Obj = line.strip()
g.write("\"" + Obj + "\"\t")
foundArticle = False
newline = True
else:
if len(line) != 2:
str+=line
newline = True
#print str
def __main__():
pipeline_run([extract])
if __name__ == '__main__':
__main__()