Example #1
0
def scrape():
    scraper = Scraper(**get_creds())

    #   Fetch usage info re: boosters.
    le = UsageDataPoint(
        time=datetime.datetime.utcnow(),
        **scraper.fetch_booster_usage()
    )

    db_session.add(le)
    yield le

    #   Fetch latest transactions and put these in the DB,
    #   but only if we don't already have them.
    for transaction in scraper.fetch_most_recent_transactions():
        existing = KoodoTransaction \
            .query \
            .filter_by(koodo_id=transaction['koodo_id']) \
            .first()
        if not existing:
            kt = KoodoTransaction(**transaction)
            db_session.add(kt)
            yield kt

    db_session.commit()