Created
January 15, 2020 12:06
-
-
Save ishank-dev/0b8e4a600984804b045575b3e55dbc1b to your computer and use it in GitHub Desktop.
Translate
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from googletrans import Translator | |
from flask import Flask, request #import main Flask class and request object | |
import requests | |
app = Flask(__name__) #create the Flask app | |
app.secret_key = "secret" | |
texts = {} | |
@app.route('/') | |
def hello_world(): | |
return '<h1>Welcome to Reva Hack</h1>' | |
@app.route('/query-example') | |
def query_example(): | |
# text = request.args.get('text') | |
texts = {'sugar':'200 grams','rice':'2 pounds','tomato':'3 kg','wheat':'1 kg'} | |
print(texts) | |
destination_languages = { | |
'Spanish': 'es', | |
'Simplified Chinese': 'zh-CN', | |
'Italian': 'it', | |
'Hindi': 'hi', | |
'Mongolian': 'mn', | |
'Russian': 'ru', | |
'Ukrainian': 'uk', | |
'French': 'fr', | |
'Indonesian': 'id', | |
'Japanese': 'ja', | |
'Slovak': 'sk' | |
} | |
for key,value in texts.items(): | |
if "kg" in value: | |
texts[key] = float(value.split()[0]) | |
if "grams" in value: | |
value = round(float(value.split()[0])/1000,2) | |
texts[key] = value | |
elif "pounds" in value: | |
value = round(float(value.split()[0])/2.205,2) | |
texts[key] = value | |
translator = Translator() | |
translated = {} | |
print(texts) | |
for key, value in texts.items(): | |
translated[translator.translate(key, dest='hi').text]=value | |
return '''{}'''.format(translated) | |
@app.route('/shopkeeper') | |
def shopkeeper(): | |
print(texts) | |
database = {'sugar':30,'rice':20,'kurkure':5,'tomato':39,'onion':100,'wheat':40,'potato':15} | |
cost = 0 | |
for key,value in texts.items(): | |
cost = cost + texts[key]*database[key] | |
return 'Total Cost ' + str(cost) | |
if __name__ == '__main__': | |
app.run(debug=True, port=5000) #run app in debug mode on port 5000 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment