def top10_holders(code=None, year=None, quarter=None, gdtype='0', retry_count=3, pause=0.001): if code is None: return None else: code = ct._code_to_symbol(code) gdtype = 'LT' if gdtype == '1' else '' qdate = '' if (year is not None) & (quarter is not None): qdate = du.get_q_date(year, quarter) for _ in range(retry_count): time.sleep(pause) try: request = Request( rv.TOP10_HOLDERS_URL % (ct.P_TYPE['http'], ct.DOMAINS['gw'], gdtype, code.upper())) lines = urlopen(request, timeout=10).read() lines = lines.decode('utf8') if ct.PY3 else lines reg = re.compile(r'= \'\[(.*?)\]\';') lines = reg.findall(lines)[0] jss = json.loads('[%s]' % lines) summ = [] data = pd.DataFrame() for row in jss: qt = row['jzrq'] # note value process hold = row['ljcy'] if 'ljcy' in row else 0 change = row['ljbh'] if 'ljbh' in row else 0 props = row['ljzb'] if 'ljzb' in row else 0 arow = [qt, hold, change, props] summ.append(arow) ls = row['sdgdList'] dlist = [] for inrow in ls: # note value process sharetype = inrow['gbxz'] if 'gbxz' in inrow else '' name = inrow['gdmc'] hold = inrow['cgs'] h_pro = inrow['zzgs'] status = inrow['zjqk'] dlist.append([qt, name, hold, h_pro, sharetype, status]) ddata = pd.DataFrame(dlist, columns=rv.TOP10_PER_COLS) data = data.append(ddata, ignore_index=True) df = pd.DataFrame(summ, columns=rv.TOP10_SUMM_COLS) if qdate != '': df = df[df.quarter == qdate] data = data[data.quarter == qdate] except Exception as e: # print(e) raise e else: return df, data raise IOError(ct.NETWORK_URL_ERROR_MSG)
def top10_holders(code=None, year=None, quarter=None, gdtype='0', retry_count=3, pause=0.001): if code is None: return None else: code = ct._code_to_symbol(code) gdtype = 'LT' if gdtype == '1' else '' qdate = '' if (year is not None) & (quarter is not None): qdate = du.get_q_date(year, quarter) for _ in range(retry_count): time.sleep(pause) try: request = Request(rv.TOP10_HOLDERS_URL%(ct.P_TYPE['http'], ct.DOMAINS['gw'], gdtype, code.upper())) lines = urlopen(request, timeout = 10).read() lines = lines.decode('utf8') if ct.PY3 else lines reg = re.compile(r'= \'\[(.*?)\]\';') lines = reg.findall(lines)[0] jss = json.loads('[%s]' %lines) summ = [] data = pd.DataFrame() for row in jss: qt = row['jzrq'] hold = row['ljcy'] change = row['ljbh'] props = row['ljzb'] arow = [qt, hold, change ,props] summ.append(arow) ls = row['sdgdList'] dlist = [] for inrow in ls: sharetype = inrow['gbxz'] name = inrow['gdmc'] hold = inrow['cgs'] h_pro = inrow['zzgs'] status = inrow['zjqk'] dlist.append([qt, name, hold, h_pro, sharetype, status]) ddata = pd.DataFrame(dlist, columns=rv.TOP10_PER_COLS) data = data.append(ddata, ignore_index=True) df = pd.DataFrame(summ, columns=rv.TOP10_SUMM_COLS) if qdate != '': df = df[df.quarter == qdate] data = data[data.quarter == qdate] except Exception as e: print(e) else: return df, data raise IOError(ct.NETWORK_URL_ERROR_MSG)