Beispiel #1
0
def update_bike_data_if_old(time_limit=app.config['BIKE_DATA_TIMEOUT']):
    """
    If the bike point data is out of date by more than time_limit,
    then update it from the TfL API
    """
    last_edited = Meta.get_last_edited()
    now = datetime.datetime.now()

    # if the database is due an update
    if not last_edited or now - last_edited > time_limit:
        update_bike_data()

        # update the last edited timestamp
        Meta.update_last_edited()
Beispiel #2
0
    def test_set_last_edited(self):
        # test it once
        now = Meta.update_last_edited()

        all_meta = db.session.query(Meta).all()
        assert len(all_meta) == 1

        l = Meta.get_last_edited()
        assert l == now

        # test it twice
        now2 = Meta.update_last_edited()

        all_meta = db.session.query(Meta).all()
        assert len(all_meta) == 1

        l2 = Meta.get_last_edited()
        assert l2 == now2
Beispiel #3
0
 def test_initial_last_edited_no_data(self):
     all_meta = db.session.query(Meta).all()
     assert len(all_meta) == 0
     assert Meta.get_last_edited() == None