Skip to content

Commit

Permalink
Merge pull request #19 from burakyilmaz321/other-fund-types
Browse files Browse the repository at this point in the history
Added `kind` parameter to fetch other fund types
  • Loading branch information
burakyilmaz321 committed Jan 12, 2024
2 parents c133d2c + 57c4579 commit 38375d8
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,15 @@ tefas = Crawler()

## API

### `fetch(start, end, name, columns)`
### `fetch(start, end, name, columns, kind)`

|Argument|Type|Description|Required|
|--|--|--|--|
|**start**|`string` or `datetime.datetime`|The date that fund information is crawled for.|Yes|
|**end**|`string` or `datetime.datetime`|End of the period that fund information is crawled for.|No|
|**name**|`string`|Name of the fund. If not given, all funds will be returned.|No|
|**columns[]**|`list` of `string`|List of columns to be returned.|No|
|**kind**|`string`|Type of the fund. One of `YAT`, `EMK`, or `BYF`. Defaults to `YAT`.|No|

### Examples

Expand Down
16 changes: 13 additions & 3 deletions tefas/crawler.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ def fetch(
end: Optional[Union[str, datetime]] = None,
name: Optional[str] = None,
columns: Optional[List[str]] = None,
kind: Optional[str] = "YAT",
) -> pd.DataFrame:
"""Main entry point of the public API. Get fund information.
Expand All @@ -73,17 +74,26 @@ def fetch(
end: End of the period that fund information is crawled for. (optional)
name: Name of the fund. If not given, all funds will be returned. (optional)
columns: List of columns to be returned. (optional)
kind: Type of the fund. One of `YAT`, `EMK`, or `BYF`. Defaults to `YAT`. (optional)
- `YAT`: Securities Mutual Funds
- `EMK`: Pension Funds
- `BYF`: Exchange Traded Funds
Returns:
A pandas DataFrame where each row is the information for a fund.
Raises:
ValueError if date format is wrong.
"""
""" # noqa
assert kind in [
"YAT",
"EMK",
"BYF",
], "`kind` should be one of `YAT`, `EMK`, or `BYF`"
start_date = _parse_date(start)
end_date = _parse_date(end or start)
data = {
"fontip": "YAT",
"fontip": kind,
"bastarih": start_date,
"bittarih": end_date,
"fonkod": name.upper() if name else "",
Expand Down Expand Up @@ -128,7 +138,7 @@ def _parse_date(date: Union[str, datetime]) -> str:
parsed = datetime.strptime(date, "%Y-%m-%d")
except ValueError as exc:
raise ValueError(
"Date string format is incorrect. " "It should be `YYYY-MM-DD`"
"Date string format is incorrect. It should be `YYYY-MM-DD`"
) from exc
else:
formatted = datetime.strftime(parsed, "%d.%m.%Y")
Expand Down
1 change: 1 addition & 0 deletions tests/test_crawler.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ def test_crawler():
crawler = Crawler()
assert crawler


def test_empty_result():
"""Test the client when POST to tefas returns empty list"""
Crawler._do_post = MagicMock(return_value=[])
Expand Down

0 comments on commit 38375d8

Please sign in to comment.