-
Notifications
You must be signed in to change notification settings - Fork 2
/
app.py
37 lines (27 loc) · 1.11 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
from flask import Flask,render_template,request
import requests
api_key = "Sizin API Keyiniz"
url = "http://data.fixer.io/api/latest?access_key=" + api_key
app = Flask(__name__)
@app.route("/",methods = ["GET","POST"])
def index():
if request.method == "POST":
firstCurrency = request.form.get("firstCurrency") # USD
secondCurrency = request.form.get("secondCurrency") # TRY
amount = request.form.get("amount") # 15
response = requests.get(url)
app.logger.info(response)
infos = response.json()
firstValue = infos["rates"][firstCurrency] # 1.231066
secondValue = infos["rates"][secondCurrency] # 8.690815
result = (secondValue / firstValue) * float(amount)
currencyInfo = dict()
currencyInfo["firstCurrency"] = firstCurrency
currencyInfo["secondCurrency"] = secondCurrency
currencyInfo["amount"] = amount
currencyInfo["result"] = result
return render_template("index.html",info = currencyInfo)
else:
return render_template("index.html" )
if __name__ == "__main__":
app.run(debug=True)