def _download(self, sdate, edate): print("Exchange ZZ--->") # Start downloading given period dates_li = gen_proc_params(self.__exc_name, sdate, edate) ans = pd.DataFrame() with requests.Session() as s: # Open request session for dates in dates_li: print(dates) URL_TEMPL = self._get_URL_TEMP(int(dates[0])) url = URL_TEMPL.format(dates[0], dates[1]) try: page = s.get(url).text df = self._read_html_format(int(dates[0]), page) except: continue df.columns = [i for i in range(14)] df["Dates"] = dates[1] df = df[["Dates", 0, 2, 3, 4, 5, 10, 9]] df.columns = self.__col_names df = df.dropna() # Delete some non ASCII rows scrpped df = df[df["Code"].str.len() <= 10] ans = ans.append(df) self.__datas = ans
def _download(self, sdate, edate): # Download market information from exchange print("Exchange SH inv downloading...") date_list = gen_proc_params(self.__exc_name, sdate, edate) datas = [] for date_str in date_list: print(date_str) URL_TEMP = self._get_URL_TEMP() url = URL_TEMP.format(date_str[1]) resp = requests.get(url) if resp.status_code == 404: continue elif resp.status_code != 200: print("the resp status code of date({}) is {}".format( date_str[0:2], resp.status_code)) jsonObj = json.loads(resp.content.decode('utf-8')) datas = self._read_html_format(jsonObj, date_str, datas) df = pd.DataFrame(datas) try: df.columns = self.__col_names except: df = pd.DataFrame(columns=self.__col_names) # Over write to english product name df = df.replace({"Product": self.__contract_code}) self.__datas = df
def _download(self, sdate, edate): print("Exchange ZJ--->") # Start downloading given period df = pd.DataFrame(columns=self.__headers) dates_li = gen_proc_params(self.__exc_name, sdate, edate) with requests.Session() as s: for dates in dates_li: print(dates) url = self.__URL_TEMPL.format(dates[0], dates[1]) page = s.get(url).text try: df = self._read_html_format(page, df) except: continue self.__datas = df
def _download(self,sdate,edate): print("Exchange DL--->") # Start downloading given period dates_li = gen_proc_params(self.__exc_name,sdate,edate) ans = pd.DataFrame() with requests.Session() as s: # Open request session for dates in dates_li: print(dates) self.__payload['year'] = dates[0] self.__payload['month'] = dates[1] self.__payload['day'] = dates[2] page = s.post( self.__URL_TEMPL, data=self.__payload, headers=self.__headers).text try: df = self._read_html_format(page,dates) except: continue ans = ans.append(df) self.__datas = ans
def _download(self, sdate, edate): # Download market information from exchange print("Exchange ZZ downloading...") date_list = gen_proc_params(self.__exc_name, sdate, edate) datas = [] for date_str in date_list: print(date_str) url_temp = self._get_URL_TEMP(int(date_str[0])) url = url_temp.format(date_str[0], date_str[1]) resp = requests.get(url) if resp.status_code == 404: continue elif resp.status_code != 200: print("the resp status code of date({}) is {}".format( date_str, resp.status_code)) page = resp.content.decode('utf-8') self._read_html_format(int(date_str[0]), page, datas, date_str[1]) df = pd.DataFrame(datas) self.__datas = df