Skip to content

Commit

Permalink
Source Exchange Rates: add ignore_weekends boolean option (#7936)
Browse files Browse the repository at this point in the history
* Source Exchange Rates: add ignore_weekends boolean option

* unformat

* backward compatibility for ignore_weekends option

Co-authored-by: Marcos Marx <marcosmarxm@users.noreply.github.com>

* Add changelog

Co-authored-by: Marcos Marx <marcosmarxm@users.noreply.github.com>
  • Loading branch information
lizdeika and marcosmarxm committed Nov 18, 2021
1 parent 0d51742 commit ebc8b76
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ RUN pip install .
ENV AIRBYTE_ENTRYPOINT "python /airbyte/integration_code/main.py"
ENTRYPOINT ["python", "/airbyte/integration_code/main.py"]

LABEL io.airbyte.version=0.2.4
LABEL io.airbyte.version=0.2.5
LABEL io.airbyte.name=airbyte/source-exchange-rates
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,12 @@ class ExchangeRates(HttpStream):
cursor_field = date_field_name
primary_key = ""

def __init__(self, base: Optional[str], start_date: DateTime, access_key: str):
def __init__(self, base: Optional[str], start_date: DateTime, access_key: str, ignore_weekends: Optional[bool]):
super().__init__()
self._base = base
self._start_date = start_date
self.access_key = access_key
self.ignore_weekends = ignore_weekends

def path(
self, stream_state: Mapping[str, Any] = None, stream_slice: Mapping[str, Any] = None, next_page_token: Mapping[str, Any] = None
Expand All @@ -52,7 +53,7 @@ def parse_response(self, response: requests.Response, **kwargs) -> Iterable[Mapp
def stream_slices(self, stream_state: Mapping[str, Any] = None, **kwargs) -> Iterable[Optional[Mapping[str, Any]]]:
stream_state = stream_state or {}
start_date = pendulum.parse(stream_state.get(self.date_field_name, self._start_date))
return chunk_date_range(start_date)
return chunk_date_range(start_date, self.ignore_weekends)

def get_updated_state(self, current_stream_state: MutableMapping[str, Any], latest_record: Mapping[str, Any]):
current_stream_state = current_stream_state or {}
Expand All @@ -62,7 +63,7 @@ def get_updated_state(self, current_stream_state: MutableMapping[str, Any], late
return current_stream_state


def chunk_date_range(start_date: DateTime) -> Iterable[Mapping[str, Any]]:
def chunk_date_range(start_date: DateTime, ignore_weekends: bool) -> Iterable[Mapping[str, Any]]:
"""
Returns a list of each day between the start date and now. Ignore weekends since exchanges don't run on weekends.
The return value is a list of dicts {'date': date_string}.
Expand All @@ -71,7 +72,7 @@ def chunk_date_range(start_date: DateTime) -> Iterable[Mapping[str, Any]]:
now = pendulum.now()
while start_date < now:
day_of_week = start_date.day_of_week
if day_of_week != pendulum.SATURDAY and day_of_week != pendulum.SUNDAY:
if day_of_week != pendulum.SATURDAY and day_of_week != pendulum.SUNDAY or not ignore_weekends:
days.append({"date": start_date.to_date_string()})
start_date = start_date.add(days=1)

Expand Down Expand Up @@ -106,4 +107,4 @@ def check_connection(self, logger: AirbyteLogger, config: Mapping[str, Any]) ->
return False, e

def streams(self, config: Mapping[str, Any]) -> List[Stream]:
return [ExchangeRates(config.get("base"), config["start_date"], config["access_key"])]
return [ExchangeRates(config.get("base"), config["start_date"], config["access_key"], config.get("ignore_weekends", True))]
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@
"type": "string",
"description": "ISO reference currency. See <a href=\"https://www.ecb.europa.eu/stats/policy_and_exchange_rates/euro_reference_exchange_rates/html/index.en.html\">here</a>. Free plan doesn't support Source Currency Switching, default base currency is EUR",
"examples": ["EUR", "USD"]
},
"ignore_weekends": {
"type": "boolean",
"description": "Ignore weekends? (Exchanges don't run on weekends)",
"default": true
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions docs/integrations/sources/exchangeratesapi.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ If you have `free` subscription plan \(you may check it [here](https://manage.ex

| Version | Date | Pull Request | Subject |
| :--- | :--- | :--- | :--- |
| 0.2.5 | 2021-11-12 | [7936](https://github.com/airbytehq/airbyte/pull/7936) | Add ignore_weekends boolean option |
| 0.2.3 | 2021-11-08 | [7499](https://github.com/airbytehq/airbyte/pull/7499) | Remove base-python dependencies |
| 0.2.2 | 2021-05-28 | [3677](https://github.com/airbytehq/airbyte/pull/3677) | Adding clearer error message when a currency isn't supported. access_key field in spec.json was marked as sensitive
| 0.2.2 | 2021-05-28 | [3677](https://github.com/airbytehq/airbyte/pull/3677) | Adding clearer error message when a currency isn't supported. access_key field in spec.json was marked as sensitive |
| 0.2.0 | 2021-05-26 | [3566](https://github.com/airbytehq/airbyte/pull/3566) | Move from `api.ratesapi.io/` to `api.exchangeratesapi.io/`. Add required field `access_key` to `config.json`. |
| 0.1.0 | 2021-04-19 | [2942](https://github.com/airbytehq/airbyte/pull/2942) | Implement Exchange API using the CDK |

0 comments on commit ebc8b76

Please sign in to comment.