Skip to content

Commit 64f1faf

Browse files
committed
Getting started with Naver reader
1 parent 48a538c commit 64f1faf

File tree

2 files changed

+69
-0
lines changed

2 files changed

+69
-0
lines changed

pandas_datareader/data.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@
3939
from pandas_datareader.yahoo.options import Options as YahooOptions
4040
from pandas_datareader.yahoo.quotes import YahooQuotesReader
4141

42+
from pandas_datareader.naver import NaverDailyReader
43+
4244
__all__ = [
4345
"get_components_yahoo",
4446
"get_data_enigma",
@@ -369,6 +371,7 @@ def DataReader(
369371
"av-monthly-adjusted",
370372
"av-intraday",
371373
"econdb",
374+
"naver",
372375
]
373376

374377
if data_source not in expected_source:
@@ -661,6 +664,16 @@ def DataReader(
661664
session=session,
662665
).read()
663666

667+
elif data_source == "naver":
668+
return NaverDailyReader(
669+
symbols=name,
670+
start=start,
671+
end=end,
672+
retry_count=retry_count,
673+
pause=pause,
674+
session=session,
675+
).read()
676+
664677
else:
665678
msg = "data_source=%r is not implemented" % data_source
666679
raise NotImplementedError(msg)

pandas_datareader/naver.py

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
from pandas_datareader.base import _DailyBaseReader
2+
3+
class NaverDailyReader(_DailyBaseReader):
4+
5+
def __init__(
6+
self,
7+
symbols=None,
8+
start=None,
9+
end=None,
10+
retry_count=3,
11+
pause=0.1,
12+
session=None,
13+
adjust_price=False,
14+
ret_index=False,
15+
chunksize=1,
16+
interval="d",
17+
get_actions=False,
18+
adjust_dividends=True,
19+
):
20+
super(NaverDailyReader, self).__init__(
21+
symbols=symbols,
22+
start=start,
23+
end=end,
24+
retry_count=retry_count,
25+
pause=pause,
26+
session=session,
27+
chunksize=chunksize,
28+
)
29+
30+
self.headers = {
31+
"Sec-Fetch-Mode": "no-cors",
32+
"Referer": "https://finance.naver.com/item/fchart.nhn?code={}".format(symbols),
33+
"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.100 Safari/537.36",
34+
}
35+
36+
@property
37+
def get_actions(self):
38+
return self._get_actions
39+
40+
@property
41+
def url(self):
42+
return "https://fchart.stock.naver.com/sise.nhn"
43+
44+
def _get_params(self, symbol):
45+
params = {
46+
"symbol": symbol,
47+
"timeframe": "day",
48+
"count": 500,
49+
"requestType": 0,
50+
}
51+
return params
52+
53+
def _read_one_data(self, url, params):
54+
"""Read one data from specified symbol"""
55+
resp = self._get_response(url, params=params)
56+
return resp

0 commit comments

Comments
 (0)