Exemplo n.º 1
0
def refresh():
    """Pull fresh data from Open AQ and replace existing data."""
    db.drop_all()
    db.create_all()
    # todo get all of the data from api and save it to a db

    # fetch data
    api = openaq.OpenAQ()
    _, body = api.measurements(city='Los Angeles', parameter='pm25')
    t = body['results']

    # save to list of tuples
    out = []
    for i in t:
        out.append((i['date']['utc'], i['value']))

    # put that list of tuples in a db
    # oneliners mean for each entry in dates and for each entry in values do:
    for k, v in zip([x['date']['utc'] for x in t], [x['value'] for x in t]):
        r = Record()
        r.utc_time = k
        r.value = v
        db.session.add(r)
    db.session.commit()

    return redirect('/')
Exemplo n.º 2
0
def reset_db():
    print(type(db))
    # drop all tablees in database
    db.drop_all()
    # create tables base on models
    db.create_all()
    return jsonify({"message": "DB RESET OK"})
Exemplo n.º 3
0
def reset_db():
    print("RESET ROUTE...")
    print("FORM DATA:", dict(request.form))
    print(type(db))
    db.drop_all()
    db.create_all()
    return render_template("reset_db.html", db=db)
Exemplo n.º 4
0
def reset_db():
    db.drop_all()
    db.create_all()
    return render_template(
        "twitter.html",
        message=
        "This is Twitter central. Either get a specific users tweets or display all past retrieved users and their tweets."
    )
Exemplo n.º 5
0
def reset_db():
    print("URL PARMS", dict(request.args))

    if "api_key" in dict(request.args) and request.args["api_key"] == API_KEY:
        print(type(db))
        db.drop_all()
        db.create_all()
        return jsonify({"message": "DB RESET OK"})
    else:
        flash("OOPS Permission Denied", "danger")
        return redirect("/users")
Exemplo n.º 6
0
def reset_db():
    # print("URL PARMS", dict(request.args))

    # if "api_key" in dict(request.args) and request.args["api_key"] == API_KEY:
    #     print(type(db))
    #     db.drop_all()
    #     db.create_all()
    #     # return jsonify({"message": "DB RESET OK"})
    #     return redirect("/tweets")
    # else:
    #     return redirect("/tweets")
    db.drop_all()
    db.create_all()
    # return jsonify({"message": "DB RESET OK"})
    return redirect("/tweets")
Exemplo n.º 7
0
def reset_db():
    print(type(db))
    db.drop_all()
    db.create_all()
    return jsonify({"message": "DB RESET OK"})


# @admin_routes.route("/admin/db/seed")
# def seed_db():
#     print(type(db))
#     # TODO: refactor the existing user and tweet storage logic from our twitter_routes into a re-usable function
#     # ... so we can "seed" our database with some example users and tweets
#     # ... to ensure that it is ready to make predictions later

#     # FYI: you might run into Timeout errors, which you'll need to think about how to avoid

#     return jsonify({"message": "DB SEEDED OK (TODO)"})
Exemplo n.º 8
0
def reset_db():
    print("URL PARMS", dict(request.args))

    if "api_key" in dict(request.args) and request.args["api_key"] == API_KEY:
        print(type(db))
        db.drop_all()
        db.create_all()
        return jsonify({"message": "DB RESET OK"})
    else:
        flash("OOPS Permission Denied", "danger")
        return redirect("/users")


#example without api key verification
#@admin_routes.route("/admin/db/reset")
# def reset_db():
#     print(type(db))
#     db.drop_all()
#     db.create_all()
#     return jsonify({"message": "DB RESET OK"})
Exemplo n.º 9
0
def reset_db():
    # Grab arguments from the URI
    if len(request.args) == 0:
        print(f"ERROR: query arguments missing")
        flash("Missing API Key. Please check and try again", "danger")
        return redirect("/db_reset")

    if "api_key" not in dict(request.args):
        print(f"ERROR: missing API Key. Reset database not allowed")
        flash("Missing API Key. Please check and try again", "danger")
        return redirect("/db_reset")

    if request.args["api_key"] != API_KEY:
        print(f"WARN: invalid API Key. Reset database not allowed")
        flash("Invalid API Key. Please check and try again", "danger")
        return redirect("/db_reset")

    print(f"INFO: resetting the database")
    db.drop_all()   # drop all tables
    db.create_all() # create tables from scratch
    print(f"INFO: database has been reset")
    flash('Your database has been reset!', "success")
    return redirect("/db_reset")
Exemplo n.º 10
0
def reset_db():
    print("URL PARMS", dict(request.args))

    if "api_key" in dict(request.args) and request.args["api_key"] == API_KEY:
        print(type(db))
        db.drop_all()
        db.create_all()
        return jsonify({"message": "DB RESET OK"})
    else:
        print("Permission Denied")
        flash("OOPS Permission Denied", "danger")
        return redirect("/")


# @admin_routes.route("/admin/db/seed")
# def seed_db():
#    print(type(db))
#    # TODO: refactor the existing user and tweet storage logic from our twitter_routes into a re-usable function
#    # ... so we can "seed" our database with some example users and tweets
#    # ... to ensure that it is ready to make predictions later

#    # FYI: you might run into Timeout errors, which you'll need to think about how to avoid

#    return jsonify({"message": "DB SEEDED OK (TODO)"})
def reset_db():
    db.drop_all()
    db.create_all()
    # return jsonify({'message': 'Database has been reset'})
    return redirect('/')
def reset():
    db.drop_all()
    db.create_all()
    return render_template('layout.html', title='DB RESET!', users=[])
Exemplo n.º 13
0
def reset_db():
    print(type(db))
    db.drop_all()
    #breakpoint() to be used to investigate
    db.create_all()
    return jsonify({"message": "DB RESET OK"})
Exemplo n.º 14
0
def reset_db():
    print(type(db))
    db.drop_all()
    db.create_all()
    return jsonify({"message": "DB RESET OK"})
Exemplo n.º 15
0
def reset_db():
    print(type(db))
    db.drop_all()
    db.create_all()
    return jsonify({'message': 'DB RESET OK'})
Exemplo n.º 16
0
def reset():
    db.drop_all()
    db.create_all()
    return jsonify({"message": "Database Reset OK"})
Exemplo n.º 17
0
def reset_db():
    db.drop_all()
    db.create_all()
    return jsonify({"message":"DB RESET OK"})
Exemplo n.º 18
0
def reset():
    db.drop_all()
    db.create_all()
    return render_template('homepage.html', title='Reset database!')
Exemplo n.º 19
0
def reset():
    db.drop_all()
    db.create_all()
    return jsonify({"message": "We have successfuly reset the database."})