-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmake_json.py
More file actions
81 lines (54 loc) · 1.49 KB
/
make_json.py
File metadata and controls
81 lines (54 loc) · 1.49 KB
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import os
import json
def make(name):
dic = {str(name):[]}
f = open(str(name)+".txt", encoding="utf8")
line = f.readline()
while line != "\n":
#print("hej")
dic[str(name)].append(line[0:-1])
line = f.readline()
js = json.dumps(dic)
with open("data.json", "w") as outfile:
json.dump(dic, outfile)
#make("facts")
def make_01(name):
#a = 0
l = []
f = open(str(name)+".txt", encoding="utf8")
line = f.readline()
while line != "":
#print(a)
#a += 1
l.append(line[0:-1])
line = f.readline()
return l
dic = {"quotes":{}, "facts":[], "rhyme":{}}
f = open("rest/facts.txt", encoding="utf8")
line = f.readline()
while line != "\n":
dic["facts"].append(line[0:-1])
line = f.readline()
f.close()
f = open("rest/quotes.txt", encoding="utf8")
line = f.readline()[0:-1]
while line != "":
author = line.split(" ")[0]
author = author.split("\t")[0]
quote = line[len(author):len(line)]
while quote.startswith(" " or "\t" or " "):
quote = quote[1:len(quote)]
if quote.startswith("\t"):
quote = quote[1:len(quote)]
if author in dic["quotes"].keys():
dic["quotes"][author].append(quote)
else:
dic["quotes"][author] = [quote]
line = f.readline()[0:-1]
l = ["elf", "cze", "eng", "lat"]
for i in l:
print("hej")
dic["rhyme"][i] = make_01(i)
js = json.dumps(dic)
with open("data.json", "w") as outfile:
json.dump(dic, outfile)