Advertisement
Guest User

Untitled

a guest
Dec 5th, 2019
497
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.02 KB | None | 0 0
  1. rom flask import Flask, render_template, request
  2. from flask_sqlalchemy import SQLAlchemy
  3. import requests
  4.  
  5. app = Flask(__name__)
  6. app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
  7. app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///crs.sqlite3'
  8. db = SQLAlchemy(app)
  9.  
  10.  
  11. class Films(db.Model):
  12.     id = db.Column(db.Integer, primary_key=True)
  13.     Name = db.Column(db.String(80), unique=True, nullable=False)
  14.    
  15.     def __repr__(self):
  16.         return '<Films %r>' % self.Name
  17.  
  18. db.create_all()
  19.  
  20. @app.route('/test')
  21. def test():
  22.  
  23.     url = "http://www.nbrb.by/API/ExRates/Rates?Periodicity=0"
  24.     all_courses = requests.get(url).json()
  25.     courses = []
  26.     for k in all_courses:
  27.         n = k["Cur_Name"],k["Cur_OfficialRate"]
  28.         courses.append(n)
  29.     courses = dict(courses)
  30.     for key, value in courses.items():  
  31.         db.session.add(key, value)
  32.         db.session.commit()
  33.  
  34.  
  35.     return render_template ('test.html', q = Films.query.all())
  36.  
  37.  
  38. if __name__ == '__main__':
  39.     app.debug = True
  40.     app.run()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement