crypto-market-extractor: Failsafe API

Signed-off-by: Alexis Pentori <alexis@status.im>
This commit is contained in:
Alexis Pentori 2024-02-08 11:06:03 +01:00
parent 691a633300
commit 067652009e
No known key found for this signature in database
GPG Key ID: 65250D2801E47A10
4 changed files with 17 additions and 11 deletions

View File

@ -47,9 +47,9 @@ pip install -r requirements.txt
### Locally running the connector
```
python main.py spec
python main.py check --config sample_files/coin_list.json
python main.py discover --config sample_files/coin_list.json
python main.py read --config sample_files/coin_list.json --catalog sample_files/configured_catalog.json
python main.py check --config sample_files/config-example.json
python main.py discover --config sample_files/config-example.json
python main.py read --config sample_files/config-example.json --catalog sample_files/configured_catalog.json
```
### Locally running the connector docker image

View File

@ -10,7 +10,7 @@ data:
connectorSubtype: api
connectorType: source
definitionId: ce91e290-be98-4a34-b43b-28330afdc3c9
dockerImageTag: 0.0.3
dockerImageTag: 0.1.0
dockerRepository: harbor.status.im/status-im/airbyte/crypto-market-extractor
githubIssueLabel: source-crypto-market-extractor
icon: crypto-market-extractor.svg

View File

@ -44,13 +44,19 @@ class CoinPrice(HttpStream):
coin=stream_slice["coin"]
logger.info("Parsing Coin Gecko data for %s", coin)
market_chart = response.json()
yield {
"name": coin,
"date": datetime.today().strftime('%Y%m%d_%H%M'),
# The first value of the prices objects is weird
"price": market_chart['prices'][1][1],
}
logger.info("Response: %s", market_chart)
data={ "name": coin, "date": datetime.today().strftime('%Y%m%d_%H%M')}
try:
if len(market_chart) > 1:
data['price'] = market_chart['prices'][1][1]
elif len(market_chart) == 1:
data['price'] = market_chart['prices'][0][1]
else:
logger.error("Invalid response from API, %s", market_chart)
raise "No correct data return"
except err:
logger.error('An error happened : %s', err)
yield data
# Source
class SourceCryptoMarketExtractor(AbstractSource):
def check_connection(self, logger, config) -> Tuple[bool, any]: