Пример #1
0
        def prepare_data(data):
            """because sina does not return a standard data,
            we need to extract the real data part
            """
            regroup = re.match(r'^var.*="(.*)"', data)

            if regroup:
                return regroup.group(1)
            else:
                raise ParserException("Unable to extact json from %s" % data)
Пример #2
0
        def prepare_data(data):
            """because hexun does not return a standard json,
            we need to extract the real json part
            """
            regroup = re.match(r'^_ntes_quote_callback\((.*)\)', data)

            if regroup:
                return regroup.group(1)
            else:
                raise ParserException("Unable to extact json from %s" % data)
    def get_url(self, stock_id, date=None):
        """ override of :meth:`Engine.get_url`
        """
        if date is None:
            raise ParserException("Yahoo Engine require date")

        start_date = date[0].split('-')
        end_date = date[1].split('-')

        engine_id = self.get_engine_id(stock_id)

        # month value is 0 - 11
        return self._url % (
            engine_id, int(start_date[1]) - 1, int(start_date[2]),
            start_date[0], int(end_date[1]) - 1, int(end_date[2]), end_date[0])
    def get_engine_id(self, stock_id):
        """
        transform raw stock_id into service stock id
        we regard stock/fund starting with 0 or 3 belongs to shenzhen

        :param stock_id:
            raw stock id
        :type stock_id:
            ``str``
        :returns:
            service stock id
        :rtype:
            ``str``
        """
        if stock_id.startswith('0') or stock_id.startswith('3'):
            return self.shenzhen_transform(stock_id)
        
        if stock_id.startswith('6'):
            return self.shanghai_transform(stock_id)
        
        raise ParserException("Unknow stock id %s" % stock_id)
Пример #5
0
    def get_url(self, stock_id, date=None):
        if date is not None:
            raise ParserException("Sina Engie does not accept date")

        return super(SinaEngine, self).get_url(stock_id)