Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- rom flask import Flask, render_template, request
- from flask_sqlalchemy import SQLAlchemy
- import requests
- app = Flask(__name__)
- app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
- app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///crs.sqlite3'
- db = SQLAlchemy(app)
- class Films(db.Model):
- id = db.Column(db.Integer, primary_key=True)
- Name = db.Column(db.String(80), unique=True, nullable=False)
- def __repr__(self):
- return '<Films %r>' % self.Name
- db.create_all()
- @app.route('/test')
- def test():
- url = "http://www.nbrb.by/API/ExRates/Rates?Periodicity=0"
- all_courses = requests.get(url).json()
- courses = []
- for k in all_courses:
- n = k["Cur_Name"],k["Cur_OfficialRate"]
- courses.append(n)
- courses = dict(courses)
- for key, value in courses.items():
- db.session.add(key, value)
- db.session.commit()
- return render_template ('test.html', q = Films.query.all())
- if __name__ == '__main__':
- app.debug = True
- app.run()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement