Exemplo n.º 1
0
    def get_content(self,
                    reporthook=None,
                    path_to_download=None,
                    proxies=None,
                    chunksize=1024 * 50,
                    *args,
                    **kwargs):
        if 'filename' in kwargs:
            filename = kwargs['filename']
        else:
            raise Exception("Param filename is not set")

        if "filesize" in kwargs:
            filesize = kwargs["filesize"]
        else:
            filesize = 0

        from pytdx.hq import TdxHq_API
        api = TdxHq_API()
        api.need_setup = False
        # calc.tdx.com.cn, calc2.tdx.com.cn
        with api.connect(ip="120.76.152.87"):
            content = api.get_report_file_by_size("tdxfin/" + filename,
                                                  filesize=filesize,
                                                  reporthook=reporthook)
            if path_to_download is None:
                download_file = tempfile.NamedTemporaryFile(delete=True)
            else:
                download_file = open(path_to_download, 'wb')
            download_file.write(content)
            download_file.seek(0)
            return download_file
Exemplo n.º 2
0
    def content(self,
                reporthook=None,
                downdir=None,
                proxies=None,
                chunksize=1024 * 50,
                *args,
                **kwargs):
        '''
        解析财务文件

        :param reporthook: 钩子回调函数
        :param downdir: 要解析的文件夹
        :param proxies:
        :param chunksize:
        :param args:
        :param kwargs:
        :return:
        '''
        from pytdx.hq import TdxHq_API

        api = TdxHq_API()
        api.need_setup = False

        with api.connect(ip=GP_HOSTS[0]):
            content = api.get_report_file_by_size("tdxfin/gpcw.txt")

            if downdir is None:
                download_file = tempfile.NamedTemporaryFile(delete=True)
            else:
                download_file = open(downdir, 'wb')

            download_file.write(content)
            download_file.seek(0)

            return download_file
Exemplo n.º 3
0
    def content(self,
                reporthook=None,
                downdir=None,
                proxies=None,
                chunksize=1024 * 50,
                *args,
                **kwargs):
        '''
        解析财务文件

        :param reporthook: 钩子回调函数
        :param downdir: 要解析的文件夹
        :param proxies:
        :param chunksize:
        :param args:
        :param kwargs:
        :return:
        '''
        filename = kwargs.get('filename')
        filesize = kwargs.get("filesize") if kwargs.get("filesize") else 0

        if not filename:
            raise Exception("Param filename is not set")

        from pytdx.hq import TdxHq_API

        api = TdxHq_API()
        api.need_setup = False

        try:
            config = json.loads('config.josn')
            bestip = config.get('hosts').get('gp')
        except ValueError as e:
            raise e

        with api.connect(*bestip):
            content = api.get_report_file_by_size("tdxfin/" + filename,
                                                  filesize=filesize,
                                                  reporthook=reporthook)
            download_file = open(
                downdir, 'wb') if downdir else tempfile.NamedTemporaryFile(
                    delete=True)
            download_file.write(content)
            download_file.seek(0)

            return download_file
    def content(self,
                reporthook=None,
                downdir=None,
                proxies=None,
                chunksize=1024 * 50,
                *args,
                **kwargs):
        '''
        解析财务文件

        :param reporthook: 钩子回调函数
        :param downdir: 要解析的文件夹
        :param proxies:
        :param chunksize:
        :param args:
        :param kwargs:
        :return:
        '''
        filename = kwargs.get('filename')
        filesize = kwargs.get("filesize") if kwargs.get("filesize") else 0

        if not filename:
            raise Exception("Param filename is not set")

        from pytdx.hq import TdxHq_API

        api = TdxHq_API()
        api.need_setup = False

        try:
            default = settings.get('SERVER').get('GP')[0][1:]
            bestip = config.get('BESTIP').get('GP', default)
        except ValueError:
            bestip = ("106.14.95.149", 7727)

        with api.connect(*bestip):
            content = api.get_report_file_by_size(f"tdxfin/{filename}",
                                                  filesize=filesize,
                                                  reporthook=reporthook)
            download_file = open(
                downdir, 'wb') if downdir else tempfile.NamedTemporaryFile(
                    delete=True)
            download_file.write(content)
            download_file.seek(0)

            return download_file
Exemplo n.º 5
0
 def get_content(self,
                 reporthook=None,
                 path_to_download=None,
                 proxies=None,
                 chunksize=1024 * 50,
                 *args,
                 **kwargs):
     from pytdx.hq import TdxHq_API
     api = TdxHq_API()
     api.need_setup = False
     # calc.tdx.com.cn, calc2.tdx.com.cn
     with api.connect(ip="120.76.152.87"):
         content = api.get_report_file_by_size("tdxfin/gpcw.txt")
         if path_to_download is None:
             download_file = tempfile.NamedTemporaryFile(delete=True)
         else:
             download_file = open(path_to_download, 'wb')
         download_file.write(content)
         download_file.seek(0)
         return download_file
    def content(self,
                reporthook=None,
                downdir=None,
                proxies=None,
                chunksize=1024 * 50,
                *args,
                **kwargs):
        '''
        解析财务文件

        :param reporthook: 钩子回调函数
        :param downdir: 要解析的文件夹
        :param proxies:
        :param chunksize:
        :param args:
        :param kwargs:
        :return:
        '''
        from pytdx.hq import TdxHq_API

        api = TdxHq_API(**kwargs)
        api.need_setup = False

        try:
            default = settings.get('SERVER').get('GP')[0][1:]
            bestip = config.get('BESTIP').get('GP', default)
        except ValueError:
            bestip = ("106.14.95.149", 7727)

        with api.connect(*bestip):
            content = api.get_report_file_by_size("tdxfin/gpcw.txt")

            if downdir is None:
                download_file = tempfile.NamedTemporaryFile(delete=True)
            else:
                download_file = open(downdir, 'wb')

            download_file.write(content)
            download_file.seek(0)

            return download_file
Exemplo n.º 7
0
        pkg = bytearray.fromhex(u'0C 12 34 00 00 00')
        # Fom DTGear request.py file
        node_size = 0x7530
        raw_data = struct.pack(r"<H2I100s", 0x06B9, offset, node_size,
                               filename.encode("utf-8"))
        raw_data_len = struct.calcsize(r"<H2I100s")
        pkg.extend(
            struct.pack(u"<HH{}s".format(raw_data_len), raw_data_len,
                        raw_data_len, raw_data))
        self.send_pkg = pkg

    def parseResponse(self, body_buf):
        (chunksize, ) = struct.unpack("<I", body_buf[:4])

        if chunksize > 0:
            return {"chunksize": chunksize, "chunkdata": body_buf[4:]}
        else:
            return {"chunksize": 0}


if __name__ == "__main__":
    from pytdx.hq import TdxHq_API
    api = TdxHq_API()
    api.need_setup = False
    # calc.tdx.com.cn, calc2.tdx.com.cn
    with api.connect(ip="120.76.152.87"):
        # response = api.get_report_file(r"tdxfin/gpcw19980630.zip", 386003)
        content = api.get_report_file_by_size("tdxfin/gpcw.txt")
        # content = api.get_report_file_by_size("tdxfin/gpcw19980630.zip", 386073)
        print(content)