-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
54 lines (36 loc) · 1.48 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
from flask import Flask, render_template
import requests
import json
app = Flask(__name__)
@app.route("/")
@app.route("/moedas")
def Home():
#parte das moedas
from Moedas import Moedas
names_moedas = ["USD", "EUR", "GBP", "ARS", "CAD", "AUD", "JPY", "CNY", "BTC"]
api_url = json.loads(requests.get(f"https://api.hgbrasil.com/finance/quotations?key=a99c1c5e").text)
list_moedas = []
api_url_moedas = api_url["results"]["currencies"]
for itens in names_moedas:
url = api_url_moedas[itens]
abre = itens
nome = url["name"]
preco = round(float(url["buy"]), 2)
preco = '{0:_}'.format(preco).replace('.',',').replace('_','.')
variacao = url["variation"]
list_moedas.append(Moedas(abre, nome, preco, variacao))
#parte das bitcoin
from Bitcoin import Bitcoin
names_bitcoin = ["blockchain_info" , "coinbase" , "bitstamp" , "foxbit" , "mercadobitcoin"]
list_bitcoin = []
api_url_bitcoin = api_url["results"]["bitcoin"]
for itens in names_bitcoin:
url = api_url_bitcoin[itens]
nome = url["name"]
preco = round(float(url["last"]), 2)
preco = '{0:_}'.format(preco).replace('.',',').replace('_','.')
variacao = url["variation"]
list_bitcoin.append(Bitcoin(nome, preco, variacao))
return render_template("home-moedas.html", list_moedas = list_moedas, list_bitcoin = list_bitcoin)
if (__name__ == "__main__"):
app.run(debug=True)