def sz_lhb_get_one_date_data(dtime, where): if not common_api.date_is_workday(dtime): return "" file_name = "lhb/sz" + where + dtime.isoformat() print "try get " + file_name #if already exist. if os.path.isfile(file_name): rf = open(file_name, "r") data = rf.read() rf.close() if len(data) > 100: return data #get from web. user_agent = 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.125 Safari/537.36' if where == "zb": refstr = 'http://www.szse.cn/main/disclosure/news/scgkxx/' baseurl = 'http://www.szse.cn/szseWeb/common/szse/files/text/jy/jy' if where == "cyb": refstr = 'http://www.szse.cn/main/chinext/jygkxx/jygkxx/' baseurl = 'http://www.szse.cn/szseWeb/common/szse/files/text/nmTxt/gk/nm_jy' if where == "zxb": refstr = 'http://www.szse.cn/main/sme/jytj/jygkxx/' baseurl = 'http://www.szse.cn/szseWeb/common/szse/files/text/smeTxt/gk/sme_jy' headers = { 'User-Agent': user_agent, 'Referer': refstr, 'Connection': 'keep-alive', 'Content-Type': 'application/x-www-form-urlencoded; charset=utf-8', } http_body = None url = baseurl + dtime.strftime( "%y%m%d") + '.txt?randnum=0.44545467011630535' print url data = my_url_read_data(url, http_body, headers)[0] data = data.decode('gbk').encode("utf-8") #print data; wf = open(file_name, "w") wf.write(data) wf.close() return data
def lhb_sock_process_one_date_where(dtime, onwhere): if not common_api.date_is_workday(dtime): return "" file_name = "lhb2/" + onwhere + dtime.isoformat() print "try get " + file_name #if already exist. if os.path.isfile(file_name): rf = open(file_name, "r") data = rf.read() rf.close() if len(data) > 100: return lhb_sock_return_data_onwhere(onwhere, data) #socket read out data: print "socket get file content" data = __lhb_socket_read_onedate_form_where(dtime, onwhere) #print data; wf = open(file_name, "w") wf.write(data) wf.close() return lhb_sock_return_data_onwhere(onwhere, data)
def sz_lhb_get_one_date_data(dtime, where): if not common_api.date_is_workday(dtime): return ""; file_name="lhb/111"+where+dtime.isoformat(); print "try get "+file_name #get from web. user_agent='Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.125 Safari/537.36' if where == "zb": refstr='http://www.szse.cn/main/disclosure/news/scgkxx/' baseurl='http://www.szse.cn/szseWeb/common/szse/files/text/jy/jy' if where == "cyb": refstr='http://www.szse.cn/main/chinext/jygkxx/jygkxx/' baseurl='http://www.szse.cn/szseWeb/common/szse/files/text/nmTxt/gk/nm_jy' if where == "zxb": refstr='http://www.szse.cn/main/sme/jytj/jygkxx/' baseurl='http://www.szse.cn/szseWeb/common/szse/files/text/smeTxt/gk/sme_jy' headers = { 'User-Agent' : user_agent, 'Referer' : refstr, 'Connection' : 'keep-alive', 'Content-Type' : 'application/x-www-form-urlencoded; charset=utf-8', } http_body = None url=baseurl+dtime.strftime("%y%m%d")+'.txt?randnum=0.44545467011630535' print url; resp, content = h.request(url,headers=headers) data = content; print data data=data.decode('gbk').encode("utf-8"); #print data; wf=open(file_name, "w"); wf.write(data); wf.close(); return data;
def sh_lhb_get_one_date_data(dtime): if type(dtime) != datetime.date: print "##$$### error datetime input" return if not common_api.date_is_workday(dtime): return "" file_name = "lhb/sh" + dtime.isoformat() print "try get " + file_name #if already exist. if os.path.isfile(file_name): rf = open(file_name, "r") data = rf.read() if len(data) > 100: return sh_pre_process_lhb_data(data) #not exist user_agent = 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.125 Safari/537.36' refstr = 'http://www.sse.com.cn/disclosure/diclosure/public/' headers = { 'User-Agent': user_agent, 'Referer': refstr, 'Connection': 'keep-alive', } http_body = None url = 'http://query.sse.com.cn/infodisplay/showTradePublicFile.do?jsonCallBack=jQuery172007153944508172572_1449041339236&dateTx=' + dtime.isoformat( ) + '&random=0.983882803004235&_=1449041354010' print url data = my_url_read_data(url, http_body, headers)[0] wf = open(file_name, "w") wf.write(data) wf.close() return sh_pre_process_lhb_data(data)