Ejemplo n.º 1
0
    def stockProfiles(self, retry=3, pause=0.001):
        """
        获取上市公司基本情况
        Parameters
        --------
        retry : int, 默认 3
                     如遇网络等问题重复执行的次数 
        pause : int, 默认 0
                    重复请求数据过程中暂停的秒数,防止请求间隔时间太短出现的问题
                    
        Return
        --------
        DataFrame or List: [{'code':, 'name':, ...}, ...]
                   code,代码
                   name,名称
                   city,所在城市
                   staff,员工人数
                   date,上市日期
                   industry,行业分类
                   pro_type,产品类型
                   main,主营业务
        """
        self._data = pd.DataFrame()

        self._writeHead()

        date = '%s-12-31' % Utility.getYear()
        self._data = pd.DataFrame()

        self._data = self.__handleStockProfiles(self._data, date, 1, retry,
                                                pause)

        return self._result()
Ejemplo n.º 2
0
    def restrictedLift(self, year=None, month=None, retry=3, pause=0.001):
        """
        获取限售股解禁数据
        Parameters
        --------
        year:年份,默认为当前年
        month:解禁月份,默认为当前月
        retry : int, 默认 3
                     如遇网络等问题重复执行的次数 
        pause : int, 默认 0
                    重复请求数据过程中暂停的秒数,防止请求间隔时间太短出现的问题
        
        Return
        ------
        DataFrame or List: [{'code':, 'name':, ...}, ...]
        code:股票代码
        name:名称
        date:解禁日期
        count:解禁数量(万股)
        ratio:占总盘比率
        """
        self._data = pd.DataFrame()

        year = Utility.getYear() if year is None else year
        month = Utility.getMonth() if month is None else month

        for _ in range(retry):
            time.sleep(pause)

            try:
                # http://datainterface.eastmoney.com/EM_DataCenter/JS.aspx?type=FD&sty=BST&st=3&sr=true&fd=2019&stat=1
                request = self._session.get(cf.RL_URL % (year, month),
                                            timeout=10)
                if self._PY3:
                    request.encoding = 'utf-8'
                lines = request.text
            except Exception as e:
                print(e)
            else:
                da = lines[3:len(lines) - 3]
                list = []
                for row in da.split('","'):
                    list.append([data for data in row.split(',')])
                self._data = pd.DataFrame(list)
                self._data = self._data[[1, 3, 4, 5, 6]]
                for col in [5, 6]:
                    self._data[col] = self._data[col].astype(float)
                self._data[5] = self._data[5] / 10000
                self._data[6] = self._data[6] * 100
                self._data[5] = self._data[5].map(cf.FORMAT)
                self._data[6] = self._data[6].map(cf.FORMAT)
                self._data.columns = cf.RL_COLS

                return self._result()

        raise IOError(cf.NETWORK_URL_ERROR_MSG)
Ejemplo n.º 3
0
    def __parseExcel(self, year, datatype, lab, column):
        year = Utility.getYear() if year is None else year
        lab = lab.encode('utf-8') if self._PY3 else lab

        try:
            df = pd.read_excel(cf.SHIBOR_DATA_URL %
                               (datatype, year, lab, year),
                               skiprows=[0])
            df.columns = column
            df['date'] = df['date'].map(lambda x: x.date())
            df['date'] = df['date'].astype('datetime64[ns]')
        except Exception as e:
            print(e)
        else:
            return df