This repository was archived by the owner on Aug 1, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdict.py
More file actions
193 lines (166 loc) · 4.11 KB
/
dict.py
File metadata and controls
193 lines (166 loc) · 4.11 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
#TODO
#zahlen statt buchstaben im menue
#random auf beiden sprachen?
#random als lernkartei
import json
import sys
import random
def version():
if (sys.version.split('.')[0] != '3'):
print("This script is written for python3")
exit()
#TODO
def header():
print('')
print('bebibebibebibebibebibebibebibebibebi')
print('bebi|| ||bebi')
print('bebi|| header in progress.. ||bebi')
print('bebi|| ||bebi')
print('bebibebibebibebibebibebibebibebibebi')
def pi():
print(',-,,-,,-,')
print('|U||U||U|')
print('|.||.||.|')
print('|.||.||.| ____')
print('| || || |/ __ \ ')
print('( ( ( ( | \_\ ')
print('| |__/ /')
print('| __/')
print('| /')
def menu():
print('')
print('~~~~~~~~|[menu-header]|~~~~~~~')
print('\t (h) hamsara dictionary')
print('\t (d) german dictionary')
print('\t (z) time dictionary')
print('\t (a) add new word')
print('\t (t) translate')
print('\t (q) quit')
def menu_select(selction):
if selection == 'h':
dictionary(hr)
elif selection == 'd':
dictionary(de)
elif selection == 'z':
date_dict(de,date)
elif selection == 'a':
add(de,date)
elif selection == 't':
transl(de,hr)
elif selection=='quit()' or selection=='quit' or selection=='exit' or selection==':q':
exit()
else:
rand(de,hr)
def dictionary(de):
sde=sorted(de.keys())
for i in sde:
if (len(i) >= 8):
print(i+'\t'+de[i])
else:
print(i+'\t\t'+de[i])
def date_dict(de,date):
for i in date:
if (len(de[i]) >= 8):
print(de[i]+'\t'+i)
else:
print(de[i]+'\t\t'+i)
def update_hr(de):
hr = {v:k for k,v in de.items()}
return hr
def add(de,date):
print('Type exit/quit to abbort')
deutsch = input('german: ')
if deutsch=='quit()' or deutsch=='quit' or deutsch=='exit' or deutsch==':q':
return
hamsara = input('hamsara: ')
if hamsara=='quit()' or hamsara=='quit' or hamsara=='exit' or hamsara==':q':
return
de[deutsch]=hamsara
date.append(deutsch)
hr = update_hr(de)
print('...word added successfully...')
#TODO please more elegant
def transl(de,hr):
wort = input('Zu uebersetzen: ')
try:
print(de[wort])
except KeyError:
try:
print(hr[wort])
except:
print("not a word")
def rand(de,hr):
if (random.randint(0,1)):
base = de
else:
base = hr
words = list(base.keys())
number = random.randint(0,len(words))
if (number == len(words)):
pi()
else:
print(words[number])
def ending():
print(' ____ ... ')
print(' //o o\\\ c/o o\ ')
print(' || u || \ u / ')
print(' _||_ _||_ ')
print(' |. .\ /. .| ')
print(' || |\\\//| || ')
print(' O| .| @@ | .|O ')
print(' | || | || ')
print(' | || | || ')
print(' \'-`-` \'-`-` ')
############################################
############################################
version()
header()
########
# READ #
########
#TODO read in jason file
#file_name1='dick.json'
filename_de='dict.json'
filename_time='timeline.json'
try:
dic = open(filename_de)
de_str = dic.read()
de = json.loads(de_str)
hr = {v:k for k,v in de.items() }
except:
print('file not found')
print(filename_de+' should be in same directory')
yesno= input('wanna start with empty dictionary? (yes/no): ')
if (yesno == 'no'):
exit()
finally:
dic.close()
try:
tmln = open(filename_time)
time_str = tmln.read()
date = json.loads(time_str)
except:
print(filename_time+' could not be found')
exit()
finally:
tmln.close()
##############
#### MAIN ####
##############
selection=''
while selection != 'q':
menu()
selection = input()
menu_select(selection)
#########
# WRITE #
#########
text = json.dumps(de)
dic= open(filename_de, 'w')
dic.write(text)
dic.close()
ttext = json.dumps(date)
tmln = open(filename_time, 'w')
tmln.write(ttext)
tmln.close()
ending()