-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvortaro.py
116 lines (95 loc) · 3.72 KB
/
vortaro.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
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
from flask import Flask, send_from_directory, request, make_response, jsonify, url_for, redirect
import subprocess, os, sys, shutil, time
app = Flask(__name__)
#app.config['SERVER_NAME'] = 'vortaro.esperanto.or.kr:5005'
#@app.route('/index.html')
#def serve_index():
# return redirect('/ekma')
@app.route('/')
def serve_root():
# return redirect('/ekma/index.html')
response = make_response(send_from_directory('./', 'index.html'))
# response.headers['Cache-Control'] = 'max-age=3600'
return response
@app.route('/ex', defaults={'path': 'index.html'})
@app.route('/ex/', defaults={'path': 'index.html'})
@app.route('/ex/<path:path>')
def serve_ex(path):
# if path == '' or path == None: path = 'index.html'
response = make_response(send_from_directory('./ex', path))
# response.headers['Cache-Control'] = 'max-age=3600'
return response
@app.route('/th', defaults={'path': 'index.html'})
@app.route('/th/', defaults={'path': 'index.html'})
@app.route('/th/<path:path>')
def serve_th(path):
# if path == '' or path == None: path = 'index.html'
response = make_response(send_from_directory('./th', path))
# response.headers['Cache-Control'] = 'max-age=3600'
return response
@app.route('/tw', defaults={'path': 'index.html'})
@app.route('/tw/', defaults={'path': 'index.html'})
@app.route('/tw/<path:path>')
def serve_tw(path):
# if path == '' or path == None: path = 'index.html'
response = make_response(send_from_directory('./tw', path))
# response.headers['Cache-Control'] = 'max-age=3600'
return response
@app.route('/b', defaults={'path': 'index.html'})
@app.route('/b/', defaults={'path': 'index.html'})
@app.route('/b/<path:path>')
def serve_b(path):
# if path == '' or path == None: path = 'index.html'
response = make_response(send_from_directory('./b', path))
# response.headers['Cache-Control'] = 'max-age=3600'
return response
@app.route('/ekma', defaults={'path': 'index.html'})
@app.route('/ekma/', defaults={'path': 'index.html'})
@app.route('/ekma/<path:path>')
def serve_ekma(path):
print(path)
# if path == '' or path == None or path == '/': path = 'index.html'
# elif path[0] == '/': path = path[1:]
response = make_response(send_from_directory('./ekma', path))
# response.headers['Cache-Control'] = 'max-age=3600'
return response
# favicon.ico 파일 서비스
@app.route('/favicon.ico')
def serve_favicon():
return send_from_directory('.', 'favicon.ico')
@app.route('/api/sendmail.api', methods=['POST'])
def sendmail():
who = request.json['who']
text = request.json['text']
fp = open("./sendmail.txt", "w")
fp.write("SUBJECT: 사전 수정요청, " + who)
fp.write("\n" + text +"\n")
fp.close()
fp = open("./ekma/correction.txt", "a+")
fp.write("\n요청 시간: " + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(time.time())))
fp.write("\n처리결과: ")
fp.write("\n작성자: " + who)
fp.write("\n수정 요청 내용: \n" + text +"\n")
fp.close()
cmd = ["python3", "sendmail.py", "memlingo.service@gmail.com", "sendmail.txt", "sendmail.html"]
output = subprocess.run(cmd, stdout=subprocess.PIPE)
result = {'ok': 'yes', "msg": "발송되었습니다."}
resp = make_response(jsonify(result))
return resp
def read_conf():
svc = {}
fp = open("svc.conf", "r")
for line in fp:
if line[0] == "#":
continue
row = line.strip().split("=")
if len(row) != 2:
continue
svc[row[0].strip()] = row[1].strip()
fp.close()
return svc
svc_conf = read_conf()
app.run(debug=True, host=svc_conf["IP"], port=int(svc_conf["PORT"]))
#IP=192.168.117.129
#PORT=5002
# app.run(debug=True, host='192.168.117.129', port=5005)