Skip to content

Commit c313804

Browse files
committed
refactor: make retry attribute part of the interface
This way we don't have to use hasattr to access the retry attribute as previously done
1 parent 1cbfb5c commit c313804

1 file changed

Lines changed: 7 additions & 11 deletions

File tree

scripts/data_collector/yahoo/collector.py

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@
4444

4545

4646
class YahooCollector(BaseCollector):
47+
retry = 5 # Configuration attribute. How many times will it try to re-request the data if the network fails.
48+
4749
def __init__(
4850
self,
4951
save_dir: [str, Path],
@@ -148,13 +150,7 @@ def _show_logging_func():
148150
def get_data(
149151
self, symbol: str, interval: str, start_datetime: pd.Timestamp, end_datetime: pd.Timestamp
150152
) -> pd.DataFrame:
151-
if hasattr(self, 'retry'):
152-
retry = self.retry
153-
else:
154-
# Default value
155-
retry = 5
156-
157-
@deco_retry(retry_sleep=self.delay, retry=retry)
153+
@deco_retry(retry_sleep=self.delay, retry=self.retry)
158154
def _get_simple(start_, end_):
159155
self.sleep()
160156
_remote_interval = "1m" if interval == self.INTERVAL_1min else interval
@@ -323,18 +319,18 @@ class YahooCollectorBR(YahooCollector, ABC):
323319
def retry(cls):
324320
""""
325321
The reason to use retry=2 is due to the fact that
326-
Yahoo Finance unfortunately does not keep track of the majority
327-
of Brazilian stocks.
322+
Yahoo Finance unfortunately does not keep track of some
323+
Brazilian stocks.
328324
329325
Therefore, the decorator deco_retry with retry argument
330-
set to 5 will keep trying to get the stock data 5 times,
326+
set to 5 will keep trying to get the stock data up to 5 times,
331327
which makes the code to download Brazilians stocks very slow.
332328
333329
In future, this may change, but for now
334330
I suggest to leave retry argument to 1 or 2 in
335331
order to improve download speed.
336332
337-
In order to achieve this code logic an argument called retry_config
333+
To achieve this goal an abstract attribute (retry)
338334
was added into YahooCollectorBR base class
339335
"""
340336
raise NotImplementedError

0 commit comments

Comments
 (0)