-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfin_main.py
More file actions
198 lines (152 loc) · 4.61 KB
/
Copy pathfin_main.py
File metadata and controls
198 lines (152 loc) · 4.61 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
193
194
195
196
197
198
# -*- coding: utf-8 -*-
"""
Created on Sun Jul 31 02:40:05 2022
"""
# this file might be replaced by GUI app with wxpython.
import fin_analysis
import glob
import json
import sys
JSON_path=glob.glob("*data_json.json")[0]
print("options")
print("1. make memo & show another memo similar to the memo")
print("2. overwrite the memo & show another memo similar to the memo")
print("3. analyze the memo & show another memo similar to the memo")
print("4. show all memo's name")
print("5. show the content of the memo")
print("6. update the system file (update JSON file) ")
# input option
while True:
opt=input("enter number of above options : ")
if opt in {"1","2","3","4","5","6"}:
opt=int(opt)
break
else:
print("invalid input!")
#load filename
filenames=set(glob.glob("*.txt"))
# opt finctions
def make_memo():
while True:
#filename
memoname=input("enter the name of the memo :")
if memoname in filenames:
print("the file already exist")
yn=input("stop this option? (y/n)")
if yn=="y":
return "@![]{}"
else:
break
#file content
print("enter the content of the memo (entering 'EOF' will stop the input)")
memo_content=""
while True:
line=input(">>")
if line == "EOF":
memo_content.rsplit()
break
else:
memo_content += line+"\n"
#make .txt file
memoname+=".txt"
with open(memoname, mode="w", encoding="utf-8") as f:
f.write(memo_content)
return memoname
# the result of analysis
def result_of_analysis(filename, JSON_path):
result=fin_analysis.similar(filename, JSON_path)
result=sorted(result.items(), key = lambda k : k[1][1], reverse=True)
#print(result)
print("degree of similarity\tfilename\tpoints of similarity")
for i in result:
compared_filename = i[0]
print(i[1][1],"\t",compared_filename,"\t",i[1][0])
def overwrite_memo(memoname):
print("the previous content:")
with open(memoname, encoding="utf-8") as f:
txt=f.read()
print(txt)
memo_content=""
while True:
line=input(">>")
if line == "EOF":
memo_content.rsplit()
break
else:
memo_content += line+"\n"
with open(memoname, mode="w", encoding="utf-8") as f:
f.write(memo_content)
# exec option
if opt == 1:
tmp=make_memo()
if tmp=="@![]{}":
pass
else:
fin_analysis.analyze(tmp, tmp, JSON_path)
result_of_analysis(tmp, JSON_path)
if opt==2:
while True:
fn=input("which memo do you overwrite? :")
fn2=fn+".txt"
if fn in filenames or fn2 in filenames:
break
else:
print("such file doesn't exist")
yn=input("stop this option? (y/n)")
if yn=="y":
sys.exit()
if fn[-3:]!="txt":
fn=fn2
overwrite_memo(fn)
fin_analysis.analyze(fn, fn, JSON_path)
result_of_analysis(fn, JSON_path)
if opt==3:
while True:
fn=input("which memo do you analyze? :")
fn2=fn+".txt"
if fn in filenames or fn2 in filenames:
break
else:
print("such file doesn't exist")
yn=input("stop this option? (y/n)")
if yn=="y":
sys.exit()
if fn[-3:]!="txt":
fn=fn2
fin_analysis.analyze(fn, fn, JSON_path)
result_of_analysis(fn, JSON_path)
if opt==4:
for i in filenames:
print(i)
if opt==5:
while True:
fn=input("which memo do you want to know about? :")
fn2=fn+".txt"
if fn in filenames or fn2 in filenames:
break
else:
print("such file doesn't exist")
yn=input("stop this option? (y/n)")
if yn=="y":
sys.exit()
if fn[-3:]!="txt":
fn=fn2
with open(fn, encoding="utf-8") as f:
txt=f.read()
print(txt)
if opt==6:
datam={}
for i in filenames:
datam[i]=fin_analysis.for_overwiteJSON(i, i, JSON_path)
with open(JSON_path, mode="w", encoding="utf-8") as f:
datam=json.dumps(datam,ensure_ascii=False)
f.write(datam)
"""
file_path=glob.glob("*sumple1.txt")[0]
json_path=glob.glob("*data_json.json")[0]
with open(json_path, mode="r", encoding="utf-8") as f:
Jr=json.load(f)
print(Jr)
fin_analysis.analyze(file_path,file_path,json_path)
fin_analysis.similar(file_path, json_path)
"""