Skip to content

Commit

Permalink
webservice now hosted on api.sanskritworld.in
Browse files Browse the repository at this point in the history
  • Loading branch information
drdhaval2785 committed Dec 15, 2017
1 parent e059a2b commit 783d31f
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 60 deletions.
79 changes: 43 additions & 36 deletions dhatu.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
app.url_map.strict_slashes = False


@app.route('/api/v0.0.1/<string:verbform>', methods=['GET'])
@app.route('/v0.0.1/<string:verbform>', methods=['GET'])
def get_full_data(verbform):
"""Return the whole data regarding given verb form.
Expand All @@ -18,67 +18,68 @@ def get_full_data(verbform):
See https://github.com/drdhaval2785/SanskritVerb/blob/master/jsongenerator.sh for details.
"""
uris = giveuris(verbform)
fileofinterest = 'data/json/' + verbform + '.json'
fileofinterest = filepath(verbform)
if os.path.exists(fileofinterest):
with open(fileofinterest, 'r') as fin:
return jsonify({'uris': uris, 'result': json.load(fin)})
else:
return jsonify({'uris': uris, 'error': 'The verb form is not in our database. If you feel it deserves to be included, kindly notify us on https://github.com/drdhaval2785/sktderivation/issues.'})
return jsonify({'uris': uris, 'filesearched': fileofinterest, 'error': 'The verb form is not in our database. If you feel it deserves to be included, kindly notify us on https://github.com/drdhaval2785/sktderivation/issues.'})


@app.route('/api/v0.0.1/<string:verbform>/prakriya', methods=['GET'])
@app.route('/v0.0.1/<string:verbform>/prakriya', methods=['GET'])
def get_prakriya(verbform):
"""Return the specific sought for information of a given verb form."""
fileofinterest = 'data/json/' + verbform + '.json'
fileofinterest = filepath(verbform)
uris = giveuris(verbform)
if not os.path.exists('data/sutrainfo.json'):
if not os.path.exists('/var/www/html/sanskritworldflask/data/sutrainfo.json'):
return jsonify({'error': 'file data/sutrainfo.json missing. You can obtain it from https://github.com/drdhaval2785/SanskritVerb/blob/master/Data/sutrainfo.json'})
elif os.path.exists(fileofinterest):
with open(fileofinterest, 'r') as fin:
verbdata = json.load(fin)
result = []
with open('data/sutrainfo.json', 'r') as sutrafile:
with open('/var/www/html/sanskritworldflask/data/sutrainfo.json', 'r') as sutrafile:
sutrainfo = json.load(sutrafile)
data = verbdata
for datum in data:
subresult = []
for member in datum['derivation']:
subresult.append(sutrainfo[member['sutra_num']] + ' (' + member['sutra_num'] + ') -> ' + ','.join(member['text']))
result.append(subresult)
return jsonify({'uris': uris, 'message': 'for machine friendly output, use /api/v0.0.1/verbform/prakriya/jsonified', 'result': result})
return jsonify({'uris': uris, 'message': 'for machine friendly output, use api.sanskritworld.in/v0.0.1/verbform/prakriya/machine', 'result': result})
else:
return jsonify({'uris': uris, 'error': 'The verb form is not in our database. If you feel it deserves to be included, kindly notify us on https://github.com/drdhaval2785/sktderivation/issues.'})


@app.route('/api/v0.0.1/<string:verbform>/prakriya/machine', methods=['GET'])
@app.route('/v0.0.1/<string:verbform>/prakriya/machine', methods=['GET'])
def get_prakriya_jsonified(verbform):
"""Return the specific sought for information of a given verb form."""
uris = giveuris(verbform)
fileofinterest = 'data/json/' + verbform + '.json'
if not os.path.exists('data/sutrainfo.json'):
fileofinterest = filepath(verbform)
if not os.path.exists('/var/www/html/sanskritworldflask/data/sutrainfo.json'):
return jsonify({'error': 'file data/sutrainfo.json missing. You can obtain it from https://github.com/drdhaval2785/SanskritVerb/blob/master/Data/sutrainfo.json'})
elif os.path.exists(fileofinterest):
with open(fileofinterest, 'r') as fin:
verbdata = json.load(fin)
result = []
with open('data/sutrainfo.json', 'r') as sutrafile:
with open('/var/www/html/sanskritworldflask/data/sutrainfo.json', 'r') as sutrafile:
sutrainfo = json.load(sutrafile)
data = verbdata
for datum in data:
subresult = []
for member in datum['derivation']:
subresult.append((sutrainfo[member['sutra_num']], member['sutra_num'], ','.join(member['text'])))
result.append(subresult)
return jsonify({'uris': uris, 'message': 'for human readable output, use /api/v0.0.1/verbform/prakriya', 'result': result})
return jsonify({'uris': uris, 'message': 'for human readable output, use api.sanskritworld.in/v0.0.1/verbform/prakriya', 'result': result})
else:
return jsonify({'uris': uris, 'error': 'The verb form is not in our database. If you feel it deserves to be included, kindly notify us on https://github.com/drdhaval2785/sktderivation/issues.'})


@app.route('/api/v0.0.1/<string:verbform>/<string:argument>', methods=['GET'])
@app.route('/v0.0.1/<string:verbform>/<string:argument>', methods=['GET'])
def get_specific_info(verbform, argument):
"""Return the specific sought for information of a given verb form."""
uris = giveuris(verbform)
with open('data/json/' + verbform + '.json', 'r') as fin:
fileofinterest = filepath(verbform)
with open(fileofinterest, 'r') as fin:
verbdata = json.load(fin)
tmp = []
for datum in verbdata:
Expand All @@ -98,28 +99,34 @@ def not_found(error):
return jsonify({'uris': uris, 'error': 'Use any of the URIs given below.'})


def giveuris(verbform='<verbform>', webserver='127.0.0.1:5000', version='v0.0.1'):
def filepath(verbform):
"""Return absolute path of file on server."""
result = '/var/www/html/sanskritworldflask/data/json/' + verbform + '.json'
return result


def giveuris(verbform='<verbform>', webserver='api.sanskritworld.in', version='v0.0.1'):
"""Give the URIs list for RESTful service."""
uris = {'prakriya_human_readable': webserver + '/api/' + version + '/' + verbform + '/prakriya',
'prakriya_machine_readable': webserver + '/api/' + version + '/' + verbform + '/prakriya/machine',
'verb_devanagari': webserver + '/api/' + version + '/' + verbform + '/verb',
'verb_meaning': webserver + '/api/' + version + '/' + verbform + '/meaning',
'verb_number': webserver + '/api/' + version + '/' + verbform + '/number',
'verb_gana': webserver + '/api/' + version + '/' + verbform + '/gana',
'madhaviyadhatuvritti_link': webserver + '/api/' + version + '/' + verbform + '/madhaviya',
'kshiratarangini_link': webserver + '/api/' + version + '/' + verbform + '/kshiratarangini',
'dhatupradipa_link': webserver + '/api/' + version + '/' + verbform + '/dhatupradipa',
'UoHyd_link': webserver + '/api/' + version + '/' + verbform + '/uohyd',
'JNU_link': webserver + '/api/' + version + '/' + verbform + '/jnu',
'verb_slp': webserver + '/api/' + version + '/' + verbform + '/verbslp',
'lakAra_or_tense': webserver + '/api/' + version + '/' + verbform + '/lakara',
'upasarga': webserver + '/api/' + version + '/' + verbform + '/upasarga',
'padadecider_id': webserver + '/api/' + version + '/' + verbform + '/padadecider_id',
'padadecider_sutra': webserver + '/api/' + version + '/' + verbform + '/padadecider_sutra',
'it_sutra': webserver + '/api/' + version + '/' + verbform + '/it_sutra',
'it_id': webserver + '/api/' + version + '/' + verbform + '/it_id',
'it_status': webserver + '/api/' + version + '/' + verbform + '/it_status',
'all_details': webserver + '/api/' + version + '/' + verbform,
uris = {'prakriya_human_readable': webserver + '/' + version + '/' + verbform + '/prakriya',
'prakriya_machine_readable': webserver + '/' + version + '/' + verbform + '/prakriya/machine',
'verb_devanagari': webserver + '/' + version + '/' + verbform + '/verb',
'verb_meaning': webserver + '/' + version + '/' + verbform + '/meaning',
'verb_number': webserver + '/' + version + '/' + verbform + '/number',
'verb_gana': webserver + '/' + version + '/' + verbform + '/gana',
'madhaviyadhatuvritti_link': webserver + '/' + version + '/' + verbform + '/madhaviya',
'kshiratarangini_link': webserver + '/' + version + '/' + verbform + '/kshiratarangini',
'dhatupradipa_link': webserver + '/' + version + '/' + verbform + '/dhatupradipa',
'UoHyd_link': webserver + '/' + version + '/' + verbform + '/uohyd',
'JNU_link': webserver + '/' + version + '/' + verbform + '/jnu',
'verb_slp': webserver + '/' + version + '/' + verbform + '/verbslp',
'lakAra_or_tense': webserver + '/' + version + '/' + verbform + '/lakara',
'upasarga': webserver + '/' + version + '/' + verbform + '/upasarga',
'padadecider_id': webserver + '/' + version + '/' + verbform + '/padadecider_id',
'padadecider_sutra': webserver + '/' + version + '/' + verbform + '/padadecider_sutra',
'it_sutra': webserver + '/' + version + '/' + verbform + '/it_sutra',
'it_id': webserver + '/' + version + '/' + verbform + '/it_id',
'it_status': webserver + '/' + version + '/' + verbform + '/it_status',
'all_details': webserver + '/' + version + '/' + verbform,
}
return uris

Expand Down
45 changes: 21 additions & 24 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,26 @@ v0.0.1 - Baby steps

# Usage

1. api/v0.0.1/form/verb
2. api/v0.0.1/form/meaning
3. api/v0.0.1/form/gana
4. api/v0.0.1/form/number
5. api/v0.0.1/form/madhaviya
6. api/v0.0.1/form/kshiratarangini
7. api/v0.0.1/form/dhatupradipa
8. api/v0.0.1/form/uohyd
9. api/v0.0.1/form/jnu
10. api/v0.0.1/form/verbslp
11. api/v0.0.1/form/lakara
12. api/v0.0.1/form/upasarga
13. api/v0.0.1/form/padadecider_id
14. api/v0.0.1/form/padadecider_sutra
15. api/v0.0.1/form/it_sutra
16. api/v0.0.1/form/it_id
17. api/v0.0.1/form/it_status
18. api/v0.0.1/form/derivation
19. api/v0.0.1/form/prakriya
20. api/v0.0.1/form/prakriya/machine
21. api/v0.0.1/form
1. api.sanskritworld.in/v0.0.1/verbform/verb
2. api.sanskritworld.in/v0.0.1/verbform/meaning
3. api.sanskritworld.in/v0.0.1/verbform/gana
4. api.sanskritworld.in/v0.0.1/verbform/number
5. api.sanskritworld.in/v0.0.1/verbform/madhaviya
6. api.sanskritworld.in/v0.0.1/verbform/kshiratarangini
7. api.sanskritworld.in/v0.0.1/verbform/dhatupradipa
8. api.sanskritworld.in/v0.0.1/verbform/uohyd
9. api.sanskritworld.in/v0.0.1/verbform/jnu
10. api.sanskritworld.in/v0.0.1/verbform/verbslp
11. api.sanskritworld.in/v0.0.1/verbform/lakara
12. api.sanskritworld.in/v0.0.1/verbform/upasarga
13. api.sanskritworld.in/v0.0.1/verbform/padadecider_id
14. api.sanskritworld.in/v0.0.1/verbform/padadecider_sutra
15. api.sanskritworld.in/v0.0.1/verbform/it_sutra
16. api.sanskritworld.in/v0.0.1/verbform/it_id
17. api.sanskritworld.in/v0.0.1/verbform/it_status
18. api.sanskritworld.in/v0.0.1/verbform/derivation
19. api.sanskritworld.in/v0.0.1/verbform/prakriya
20. api.sanskritworld.in/v0.0.1/verbform/prakriya/machine
21. api.sanskritworld.in/v0.0.1/verbform

# Problems with data

1. acIkarat has data of acIkaRat. Something to do with the case sensitivity. #1
2. cakAra can be generated from qukfY and kF both. Currently it is overwritten. #2
5 changes: 5 additions & 0 deletions yourapplication.wsgi
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import sys
sys.path.insert(0, '/var/www/html/sanskritworldflask')
sys.path.append('/usr/local/lib/python3.5/dist-packages')
sys.path.append('/usr/lib/python3/dist-packages')
from dhatu import app as application

0 comments on commit 783d31f

Please sign in to comment.