Beispiel #1
0
def main():
    if len(sys.argv) == 2:
        if sys.argv[1] == 'createdb':
            db.create_all()
            print("Created database.")
        elif sys.argv[1] == 'deltables':
            db.reflect()
            db.drop_all()
            db.session.commit()
    app.run(host='0.0.0.0', port='8080')
Beispiel #2
0
def db(request, app):
    nonogram_db.reflect()
    nonogram_db.create_all()

    def teardown():
        nonogram_db.session.close_all()
        nonogram_db.reflect()

    request.addfinalizer(teardown)
    return nonogram_db
Beispiel #3
0
import urllib.request
import json
import ssl
import time
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
from models import db, Hero, TopPlayer, Achievement, Event, Skin, Item
import psycopg2

baseurl = 'https://overwatch-api.net/api/v1'
context = ssl._create_unverified_context()

db.reflect()
db.drop_all()
db.create_all()


def scrapeHeroes():
    #24 heroes
    for h in range(1, 25):
        tempurl = baseurl + '/hero/' + str(h)
        req = urllib.request.Request(tempurl,
                                     headers={'User-Agent': 'Mozilla/5.0'})
        thejson = urllib.request.urlopen(req, context=context)
        data_bytes = thejson.read().decode('utf-8')
        data = json.loads(data_bytes)

        Hero_id = data['id']
        name = data['name']
        description = data['description']
        role_name = data['role']['name']
Beispiel #4
0
from flask_migrate import Migrate, MigrateCommand
from models import db
from models.teacher import Teacher
from models.goal import Goal
from models.request import Request
from models.booking import Booking
from sqlalchemy.sql.expression import func

app = Flask(__name__)
SECRET_KEY = os.urandom(32)
app.config['SECRET_KEY'] = SECRET_KEY
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///test.db'
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False

db.init_app(app)
db.reflect(app=app)
manager = Manager(app)
migrate = Migrate(app, db)
# db.create_all()
manager.add_command('db', MigrateCommand)


@app.route('/')
def main():
    return render_template("index.html",
                           goals=Goal.query.all(),
                           teachers=Teacher.query.order_by(
                               func.random()).limit(6).all())


@app.route('/goals/<goal>/')
Beispiel #5
0
 def teardown():
     nonogram_db.session.close_all()
     nonogram_db.reflect()
Beispiel #6
0
def drop():
    db.reflect()
    db.drop_all()