-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcontentsToCSV.py
51 lines (35 loc) · 1.1 KB
/
contentsToCSV.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
import os
import re
def saveAsFile(ondnr, data):
try:
# Opslaan onder /scores/
path = "C:/DEPGroep1/scores/"
file = 'data.csv'
path = path + file
#print(path)
with open(path, "a+") as file_object:
text = ["", "", "", "", ""]
text[0] = ondnr
text[3] = ondnr
text[4] = data
text = ";".join(text)
# Append text at the end of file
file_object.write(text)
file_object.write('\n')
except:
# Niet gelukt om bestand op te slaan
print(f'Niet gelukt om de uitslag aan het bestand toe te voegen.')
dir = os.listdir('contents')
writeTo = open
for file in dir:
filename = 'contents/' + file
bestand = open(filename, 'r')
text = bestand.read()
text = text.lower()
woorden = text.split()
woorden = [word.strip('.,!;()[]') for word in woorden]
unique = []
for word in woorden:
if word not in unique:
unique.append(word)
saveAsFile(file.split('.')[0], " ".join(unique))