-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtranslate_web.py
executable file
·70 lines (58 loc) · 2.26 KB
/
translate_web.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
#!/usr/bin/env python3.6
#-*- coding:utf-8 -*-
import sys
from os import environ
# подцепляем словарь из внешнего файла
import dicts.dicts as d
import dicts.spells as s
from translate import replacer
import bottle
bottle.debug(True)
@bottle.route('/dict')
def print_dict():
html = bottle.template("templates/dict.tpl",
common_dict=d.common_dict,
damage_dict=d.damage_dict,
alignment_dict=d.alignment_dict,
creature_dict=d.creature_dict,
lang_dict=d.lang_dict,
condition_dict=d.condition_dict,
skill_dict=d.skill_dict,
armor_dict=d.armor_dict,
weapon_dict=d.weapon_dict,
tools_dict=d.tools_dict,
equipment_packs_dict=d.equipment_packs_dict,
mounts_vehicles_dict=d.mounts_vehicles_dict,
adventuring_gear_dict=d.adventuring_gear_dict,
race_dict=d.race_dict,
abilities_dict=d.abilities_dict,
name_dict=d.name_dict)
return html
@bottle.route('/spell_dict')
def print_spell_dict():
html = bottle.template("templates/spell_dict.tpl",
phb_spell=s.phb_spell,
ee_spell=s.ee_spell,
scag_spell=s.scag_spell,
tfyp_spell=s.tfyp_spell)
return html
@bottle.post('/translate')
def print_translate():
input_text = None
input_text = bottle.request.forms.text
if input_text:
text = replacer(input_text, d.all_dict)
else:
text = "Кажется, вы не ввели текст."
html = bottle.template("templates/translate.tpl", text=text)
return html
@bottle.route('/')
def print_index():
latest_commit_date = None
try:
latest_commit_date = environ["UPDATED_DATE"]
except:
latest_commit_date = "Не доступно"
html = bottle.template("templates/index.tpl", latest_commit_date=latest_commit_date)
return html
bottle.run(host='0.0.0.0', port=sys.argv[1])