-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpython_lesson_2.py
More file actions
42 lines (31 loc) · 812 Bytes
/
Copy pathpython_lesson_2.py
File metadata and controls
42 lines (31 loc) · 812 Bytes
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
import requests
import json
from flask import Flask
def get_valutes_list():
url = 'https://www.cbr-xml-daily.ru/daily_json.js'
response = requests.get(url)
data = json.loads(response.text)
valutes = list(data['Valute'].values())
return valutes
app = Flask(__name__)
def create_html(valutes):
text = '<h1>Курс валют</h1>'
text += '<table>'
text += '<tr>'
for _ in valutes[0]:
text += f'<th><th>'
text += '</tr>'
for valute in valutes:
text += '<tr>'
for v in valute.values():
text += f'<td>{v}</td>'
text += '</tr>'
text += '</table>'
return text
@app.route("/")
def index():
valutes = get_valutes_list()
html = create_html(valutes)
return html
if __name__ == "__main__":
app.run()