def get(self, bank_id): bank = banks.get_bank(bank_id) if not bank: abort(404, message="Not found. Supported banks = %s" % ",".join(banks.get_bank_ids())) data = bank.quote() quote_date = datetime.datetime.fromtimestamp(data["date"]) if "date" in data else None ancestor_key = ndb.Key("Bank", bank.name()) # sanity check if quotes are already stored if quote_date: qry = XchgRecord.query(XchgRecord.quote_date == quote_date, ancestor=ancestor_key) if qry.get(keys_only=True): return "", 204 for c, r in data["data"].iteritems(): rec = XchgRecord(parent=ancestor_key) rec.base_currency = c rec.to_currency = "TWD" rec.cash_buy = r[0] rec.cash_sell = r[1] rec.spot_buy = r[2] rec.spot_sell = r[3] if quote_date: rec.quote_date = quote_date # TODO: put quote records at once rec.put() return "", 201