def update_currencies(): """ Downloads all available currencies and prepares the database. """ response = get("http://apilayer.net/api/live?access_key=%s" % (Config.APILAYER_KEY)).json() for currency_code in response["quotes"].keys(): currency = get_currency(short_code=currency_code[3:]).first() if not currency: currency = Currency(short_code=currency_code[3:]) session.add(currency) session.commit() currency.value = response["quotes"][ currency_code] / Config.CURRENCY_DIVIDER currency.last_update = get_current_date() session.commit()