-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
40 lines (31 loc) · 1.05 KB
/
app.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
from flask import Flask, request, jsonify, make_response
from translate import TanslateAPI
app = Flask(__name__)
textTranslate = TanslateAPI
@app.route('/')
def home():
return "<h1>Welcome to API-GoogleTranslate</h1>"
@app.route('/text', methods=["GET"])
def Translator(ogText):
trnText = textTranslate(ogText)
return trnText, 200
@app.route('/textTranslate', methods=["POST"])
def json():
if request.is_json:
req = request.get_json()
response = {
"info": "JSON received!",
"message": req.get("message")
}
pairs = response.items()
for key, value in pairs:
if key == "name":
textTrans = Translator(value)
res = make_response(jsonify(textTrans), 200)
return res
else:
res = make_response(jsonify({"message": "Status: 400 - No JSON! Try again"}), 400)
return res
if __name__ == '__main__':
# Threaded option to enable multiple instances for multiple user access support
app.run(threaded=True, port=5000)