I use globse instead of wf.
This commit is contained in:
parent
b30a5f614e
commit
c0f8db6c71
5 changed files with 78 additions and 53 deletions
|
@ -47,33 +47,50 @@ def ask_for_text():
|
|||
@app.route('/_find_translations')
|
||||
def find_translations():
|
||||
text_for_translation = request.args.get('text', 0)
|
||||
language = request.args.get('language', 0)
|
||||
dictionary_link = "http://api.wordreference.com/a95ae/json/" + language + "/"
|
||||
from_language = request.args.get('from_language', 0)
|
||||
dest_language = request.args.get('dest_language', 0)
|
||||
words = text_for_translation.split(" ")
|
||||
translations = []
|
||||
for word in words:
|
||||
translation = get_exact_translation(requests.get(dictionary_link + strip_punctuation(word)).json)
|
||||
translation = find_translation_in_glosbe(prepare_word(word), from_language, dest_language)
|
||||
translations.append(translation)
|
||||
return jsonify(result=translations, words=words, html_output=prepare_html_output(words))
|
||||
|
||||
|
||||
def find_translation_in_glosbe(phrase, from_language, dest):
|
||||
url = "http://glosbe.com/gapi/translate?from=" + from_language
|
||||
url += "&dest=" + dest + "&format=json&phrase="
|
||||
url += phrase + "&pretty=true"
|
||||
response = requests.get(url).json
|
||||
try:
|
||||
return response["tuc"][0]["phrase"]["text"]
|
||||
except:
|
||||
return "no translation"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@app.route('/_send_mail')
|
||||
def send_mail():
|
||||
from_address = "attero@hackerspace.pl"
|
||||
to_address = request.args.get('mail_address', 0)
|
||||
message_text = request.args.get('message', 0)
|
||||
msg = ("From: %s\r\nTo: %s\r\nSubject: Lanre\r\n" % (from_address, to_address))
|
||||
server = smtplib.SMTP('hackerspace.pl', 587)
|
||||
server.starttls()
|
||||
server.login("attero", "dupa.8")
|
||||
server.set_debuglevel(1)
|
||||
print(from_address)
|
||||
print(to_address)
|
||||
print(msg + message_text)
|
||||
print("somethin wrong in loging to server")
|
||||
server.sendmail(from_address, to_address, msg + message_text)
|
||||
server.quit()
|
||||
return jsonify(result="success")
|
||||
try:
|
||||
from_address = "attero@hackerspace.pl"
|
||||
to_address = request.args.get('mail_address', 0)
|
||||
message_text = request.args.get('message', 0)
|
||||
msg = ("From: %s\r\nTo: %s\r\nSubject: Lanre\r\n" % (from_address, to_address))
|
||||
server = smtplib.SMTP('hackerspace.pl', 587)
|
||||
server.starttls()
|
||||
server.login("attero", "dupa.8")
|
||||
server.set_debuglevel(1)
|
||||
print(from_address)
|
||||
print(to_address)
|
||||
print(msg + message_text)
|
||||
print("somethin wrong in loging to server")
|
||||
server.sendmail(from_address, to_address, msg + message_text)
|
||||
server.quit()
|
||||
return jsonify(result="success")
|
||||
except:
|
||||
return jsonify(result="failure")
|
||||
|
||||
|
||||
|
||||
|
@ -82,6 +99,12 @@ def prepare_html_output(words):
|
|||
output = " ".join(words_with_html)
|
||||
return output
|
||||
|
||||
def prepare_word(word):
|
||||
try:
|
||||
word = strip_punctuation(word)
|
||||
return word[0].lower() + word[1:]
|
||||
except:
|
||||
return ""
|
||||
|
||||
def strip_punctuation(word):
|
||||
try:
|
||||
|
@ -93,15 +116,6 @@ def strip_punctuation(word):
|
|||
return word
|
||||
|
||||
|
||||
def get_exact_translation(retrieved_json):
|
||||
try:
|
||||
response = fetch_translations(retrieved_json)
|
||||
if len(response) == 0:
|
||||
response = "No translation"
|
||||
except:
|
||||
response = "No translation"
|
||||
return response
|
||||
|
||||
|
||||
def fetch_translations(retrieved_json):
|
||||
response = ""
|
||||
|
@ -109,7 +123,8 @@ def fetch_translations(retrieved_json):
|
|||
response += retrieved_json["term0"]["PrincipalTranslations"]["0"]["FirstTranslation"]["term"] + ", "
|
||||
return response
|
||||
|
||||
#this api is broken and inconsistent, I don't like it, mayby it'd be better to start with something different soon?
|
||||
|
||||
#this api is broken and inconsistent, I don't like it, mayby it'd be better to start with something different soon?
|
||||
#a95ae api key for word reference is: a95ae
|
||||
#http://www.wordreference.com/docs/api.aspx
|
||||
|
||||
|
|
|
@ -69,7 +69,9 @@
|
|||
inkscape:groupmode="layer"
|
||||
id="layer1">
|
||||
<g
|
||||
id="g5284">
|
||||
id="g5284"
|
||||
inkscape:export-xdpi="90"
|
||||
inkscape:export-ydpi="90">
|
||||
<path
|
||||
sodipodi:nodetypes="cccsssccccsscccc"
|
||||
d="m 133.65126,305.42431 5.48814,13.13199 c -2.376,5.616 -4.82615,8.85816 -7.34615,11.16215 -2.952,2.664 -6.98401,3.96 -12.528,3.96 -4.392,0 -14.89328,0.42393 -15.86153,-2.51677 -3.778633,-11.47617 1.31369,-38.17384 9.09138,-45.09568 4.03385,-3.58997 10.09938,-9.87153 8.28215,2.97245 l 12.12183,-23.51828 -37.24983,21.71828 0,1.8 c 4.896,0.288 5.40951,1.51386 4.67677,5.112 -2.33197,11.45126 -2.920393,18.26407 -5.050762,28.28201 -0.84387,3.96825 -1.424417,9.44808 -6.697076,10.16276 l -3.535534,15.43706 c 13.803124,-4.99722 27.517632,-10.79193 42.626152,-4.04061 l 17.09414,-25.43537"
|
||||
|
|
Before Width: | Height: | Size: 7.8 KiB After Width: | Height: | Size: 7.9 KiB |
|
@ -74,62 +74,68 @@ $("#thanks-for-help").click(function() {
|
|||
});
|
||||
|
||||
$("#lifren").click(function() {
|
||||
$LANGUAGE = "fren";
|
||||
$DEST_LANGUAGE = "eng";
|
||||
$FROM_LANGUAGE = "fra";
|
||||
$(this).addClass("active");
|
||||
$("#liiten").removeClass("active");
|
||||
$("#lienit").removeClass("active");
|
||||
$("#liesen").removeClass("active");
|
||||
$("#lienes").removeClass("active");
|
||||
$("#lideen").removeClass("active");
|
||||
$("#liende").removeClass("active");
|
||||
$("#lienfr").removeClass("active");
|
||||
});
|
||||
|
||||
$("#lienfr").click(function() {
|
||||
$LANGUAGE = "enfr";
|
||||
$DEST_LANGUAGE = "fra";
|
||||
$FROM_LANGUAGE = "eng";
|
||||
$(this).addClass("active");
|
||||
$("#liesen").removeClass("active");
|
||||
$("#lienes").removeClass("active");
|
||||
$("#lideen").removeClass("active");
|
||||
$("#liende").removeClass("active");
|
||||
$("#lifren").removeClass("active");
|
||||
|
||||
$("#liiten").removeClass("active");
|
||||
$("#lienit").removeClass("active");
|
||||
});
|
||||
|
||||
$("#liesen").click(function() {
|
||||
$LANGUAGE = "esen";
|
||||
$("#lideen").click(function() {
|
||||
$DEST_LANGUAGE = "eng";
|
||||
$FROM_LANGUAGE = "deu";
|
||||
$(this).addClass("active");
|
||||
$("#liiten").removeClass("active");
|
||||
$("#lienit").removeClass("active");
|
||||
$("#lienfr").removeClass("active");
|
||||
$("#lienes").removeClass("active");
|
||||
$("#liende").removeClass("active");
|
||||
$("#lifren").removeClass("active");
|
||||
});
|
||||
|
||||
$("#lienes").click(function() {
|
||||
$LANGUAGE = "enes";
|
||||
$("#liende").click(function() {
|
||||
$DEST_LANGUAGE = "deu";
|
||||
$FROM_LANGUAGE = "eng";
|
||||
$(this).addClass("active");
|
||||
$("#liiten").removeClass("active");
|
||||
$("#lienit").removeClass("active");
|
||||
$("#liesen").removeClass("active");
|
||||
$("#lideen").removeClass("active");
|
||||
$("#lienfr").removeClass("active");
|
||||
$("#lifren").removeClass("active");
|
||||
});
|
||||
|
||||
|
||||
$("#liiten").click(function() {
|
||||
$LANGUAGE = "iten";
|
||||
$DEST_LANGUAGE = "eng";
|
||||
$FROM_LANGUAGE = "ita";
|
||||
$(this).addClass("active");
|
||||
$("#liesen").removeClass("active");
|
||||
$("#lienes").removeClass("active");
|
||||
$("#lideen").removeClass("active");
|
||||
$("#liende").removeClass("active");
|
||||
$("#lifren").removeClass("active");
|
||||
$("#lienfr").removeClass("active");
|
||||
$("#lienit").removeClass("active");
|
||||
});
|
||||
|
||||
$("#lienit").click(function() {
|
||||
$LANGUAGE = "enit";
|
||||
$DEST_LANGUAGE = "ita";
|
||||
$FROM_LANGUAGE = "eng";
|
||||
$(this).addClass("active");
|
||||
$("#liesen").removeClass("active");
|
||||
$("#lienes").removeClass("active");
|
||||
$("#lideen").removeClass("active");
|
||||
$("#liende").removeClass("active");
|
||||
$("#lienfr").removeClass("active");
|
||||
$("#lifren").removeClass("active");
|
||||
$("#liiten").removeClass("active");
|
||||
|
@ -170,7 +176,8 @@ function get_translation(text_for_translation) {
|
|||
change_communicat("It may take some time..." );
|
||||
$.getJSON( $SCRIPT_ROOT + '/_find_translations', {
|
||||
text:text_for_translation,
|
||||
language:$LANGUAGE
|
||||
from_language:$FROM_LANGUAGE,
|
||||
dest_language:$DEST_LANGUAGE
|
||||
}, function(data) {
|
||||
$("#translated-text").html(data.html_output);
|
||||
translated_words = data.result;
|
||||
|
|
|
@ -14,11 +14,11 @@
|
|||
<li id="lienit">
|
||||
<a href="#language-options">English Italian</a>
|
||||
</li>
|
||||
<li id="lienes">
|
||||
<a href="#language-options">English Spanish</a>
|
||||
<li id="liende">
|
||||
<a href="#language-options">English German</a>
|
||||
</li>
|
||||
<li id="liesen">
|
||||
<a href="#language-options">Spanish English</a>
|
||||
<li id="lideen">
|
||||
<a href="#language-options">German English</a>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
|
|
|
@ -4,7 +4,8 @@
|
|||
|
||||
<script type=text/javascript>
|
||||
$SCRIPT_ROOT = {{ request.script_root|tojson|safe }};
|
||||
$LANGUAGE = "fren";
|
||||
$FROM_LANGUAGE = "eng";
|
||||
$DEST_LANGUAGE = "fra";
|
||||
</script>
|
||||
|
||||
<script type="text/javascript" src="http://code.jquery.com/jquery-1.8.3.min.js"></script>
|
||||
|
|
Loading…
Add table
Reference in a new issue