-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.py
47 lines (39 loc) · 1.8 KB
/
main.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
"""This script manages the 3aransia API routes for its multiple features"""
from flask import Flask, jsonify, request
from aaransia import transliterate, get_alphabets_codes, get_alphabets
app = Flask(__name__)
app.config['JSON_AS_ASCII'] = False
# Index route
@app.route('/', methods=['GET'])
def hello_world():
"""This is the base route function of 3aransia"""
return jsonify({'message' : '3arania - Transliteration of languages and dialects - 3aransia.com'})
# Get alphabets codes route
@app.route('/get_alphabets_codes_route/', methods=['GET'])
def get_alphabets_codes_route():
"""This route returns the alphabets codes available in 3aransia"""
return jsonify({'alphabets_codes' : get_alphabets_codes()})
# Get alphabets route
@app.route('/get_alphabets_route/', methods=['GET'])
def get_alphabets_route():
"""This route returns the alphabets available in 3aransia"""
return jsonify({'alphabets' : get_alphabets()})
# Transliteration moroccan to moroccan arabic
@app.route('/transliteration_route/', methods=['GET'])
def transliteration_route():
"""This route returns the transliteration of the text entry using the source
and target language parameters
text: first value, string
source-language: second value, language code, string
target-language: third value, language code, string
"""
try:
return jsonify({'transliteration':
transliterate(' '.join(request.args.get('text').split('+')),
request.args.get('source-language'),
request.args.get('target-language'),
universal=True)})
except SourceLanguageException as sle:
return jsonify({'sourceLanguageException': sle})
if __name__ == "__main__":
app.run(debug=True)