@@ -104,14 +104,18 @@ def purify(self, original_data):
104104
105105class TPEXFetcher (BaseFetcher ):
106106 REPORT_URL = urllib .parse .urljoin (
107- TPEX_BASE_URL , "web/stock/aftertrading/daily_trading_info/st43_result.php "
107+ TPEX_BASE_URL , "www/zh-tw/afterTrading/tradingStock "
108108 )
109109
110110 def __init__ (self ):
111111 pass
112112
113113 def fetch (self , year : int , month : int , sid : str , retry : int = 5 ):
114- params = {"d" : "%d/%d" % (year - 1911 , month ), "stkno" : sid }
114+ params = {
115+ "date" : "%d/%02d/01" % (year , month ),
116+ "code" : sid ,
117+ "response" : "json" ,
118+ }
115119 for retry_i in range (retry ):
116120 r = requests .get (self .REPORT_URL , params = params , proxies = get_proxies ())
117121 try :
@@ -124,9 +128,7 @@ def fetch(self, year: int, month: int, sid: str, retry: int = 5):
124128 # Fail in all retries
125129 data = {"aaData" : []}
126130
127- data ["data" ] = []
128- if data ["aaData" ]:
129- data ["data" ] = self .purify (data )
131+ data ["data" ] = self .purify (data )
130132 return data
131133
132134 def _convert_date (self , date ):
@@ -135,7 +137,7 @@ def _convert_date(self, date):
135137
136138 def _make_datatuple (self , data ):
137139 data [0 ] = datetime .datetime .strptime (
138- self ._convert_date (data [0 ].replace ("* " , "" )), "%Y/%m/%d"
140+ self ._convert_date (data [0 ].replace ("* " , "" )), "%Y/%m/%d"
139141 )
140142 data [1 ] = int (data [1 ].replace ("," , "" )) * 1000
141143 data [2 ] = int (data [2 ].replace ("," , "" )) * 1000
@@ -148,7 +150,7 @@ def _make_datatuple(self, data):
148150 return DATATUPLE (* data )
149151
150152 def purify (self , original_data ):
151- return [self ._make_datatuple (d ) for d in original_data ["aaData " ]]
153+ return [self ._make_datatuple (d ) for d in original_data ["tables" ][ 0 ][ "data " ]]
152154
153155
154156class Stock (analytics .Analytics ):
0 commit comments