Skip to content

Commit

Permalink
bug-fix - schema changes to support storing ALL rates as semi-structu…
Browse files Browse the repository at this point in the history
…red data.
  • Loading branch information
gord-nuttall-adswerve committed Apr 21, 2023
1 parent 3f5500c commit ec945e5
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions tap_exchangeratesapi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,28 +18,26 @@

DATE_FORMAT='%Y-%m-%d'

def parse_response(r):
#flattened = r['rates']
flattened = {}
flattened['base'] = r['base']
flattened['rates'] = json.dumps(r['rates'])
flattened['date'] = time.strftime('%Y-%m-%dT%H:%M:%SZ', time.strptime(r['date'], DATE_FORMAT))
return flattened

schema = {'type': 'object',
SCHEMA = {'type': 'object',
'properties':
{'date': {'type': 'string',
'format': 'date-time'},
'rates': {'type': 'string'}
}
}

def parse_response(r):
#flattened = r['rates']
flattened = {}
flattened['base'] = r['base']
flattened['rates'] = json.dumps(r['rates'])
flattened['date'] = time.strftime('%Y-%m-%dT%H:%M:%SZ', time.strptime(r['date'], DATE_FORMAT))
return flattened
def giveup(error):
logger.error(error.response.text)
response = error.response
return not (response.status_code == 429 or
response.status_code >= 500)

@backoff.on_exception(backoff.constant,
(requests.exceptions.RequestException),
jitter=backoff.random_jitter,
Expand All @@ -55,6 +53,7 @@ def do_sync(base, start_date, apikey):
state = {'start_date': start_date}
next_date = start_date
# prev_schema = {}
singer.write_schema('exchange_rate', SCHEMA, 'date')

try:
while datetime.strptime(next_date, DATE_FORMAT) <= datetime.utcnow():
Expand Down

0 comments on commit ec945e5

Please sign in to comment.