当前位置: 首页>>代码示例>>Python>>正文


Python TdxHq_API.disconnect方法代码示例

本文整理汇总了Python中pytdx.hq.TdxHq_API.disconnect方法的典型用法代码示例。如果您正苦于以下问题:Python TdxHq_API.disconnect方法的具体用法?Python TdxHq_API.disconnect怎么用?Python TdxHq_API.disconnect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pytdx.hq.TdxHq_API的用法示例。


在下文中一共展示了TdxHq_API.disconnect方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __call__

# 需要导入模块: from pytdx.hq import TdxHq_API [as 别名]
# 或者: from pytdx.hq.TdxHq_API import disconnect [as 别名]
    def __call__(self):
        total_count = 0
        try:
            connect = sqlite3.connect(self.sqlitefile)
        except Exception as e:
            #self.queue.put([self.msg_name, str(e), -1, 0, total_count])
            self.queue.put([self.msg_name, 'INFO', str(e), 0, 0])
            self.queue.put([self.msg_name, '', 0, None, total_count])
            return

        try:
            download_dir = self.dest_dir + "/downloads"
            if not os.path.lexists(download_dir):
                os.makedirs(download_dir)
            
            self.queue.put([self.msg_name, '正在下载钱龙权息信息...', 0, 0, 0])
            net_file = urllib.request.urlopen('http://www.qianlong.com.cn/download/history/weight.rar', timeout=60)
            buffer = net_file.read()

            self.queue.put([self.msg_name, '钱龙权息信息下载完成,正在校验是否存在更新...', 0, 0, 0])
            new_md5 = hashlib.md5(buffer).hexdigest()

            dest_filename = download_dir + '/weight.rar'
            old_md5 = None
            if os.path.exists(dest_filename):
                with open(dest_filename, 'rb') as oldfile:
                    old_md5 = hashlib.md5(oldfile.read()).hexdigest()

            #如果没变化不需要解压导入
            if new_md5 != old_md5:
                with open(dest_filename, 'wb') as file:
                    file.write(buffer)

                self.queue.put([self.msg_name, '正在解压钱龙权息信息...', 0, 0, 0])
                x = os.system('unrar x -o+ -inul {} {}'.format(dest_filename, download_dir))
                if x != 0:
                    raise Exception("无法找到unrar命令!")

                self.queue.put([self.msg_name, '正在导入钱龙权息数据...', 0, 0, 0])
                total_count = qianlong_import_weight(connect, download_dir + '/weight', 'SH')
                total_count += qianlong_import_weight(connect, download_dir + '/weight', 'SZ')
                self.queue.put([self.msg_name, '导入钱龙权息数据完毕!', 0, 0, total_count])

            else:
                self.queue.put([self.msg_name, '钱龙权息数据无变化', 0, 0, 0])

            hosts = search_best_tdx()
            api = TdxHq_API()
            api.connect(hosts[0][2], hosts[0][3])

            self.queue.put([self.msg_name, '下载通达信权息信息(上证)...', 0, 0, 0])
            x = pytdx_import_finance(connect, api, "SH")

            self.queue.put([self.msg_name, '下载通达信权息信息(深证)...', 0, 0, 0])
            x += pytdx_import_finance(connect, api, "SZ")
            self.queue.put([self.msg_name, '导入通达信权息信息完毕!', 0, 0, x])

            api.disconnect()

        except Exception as e:
            #self.queue.put([self.msg_name, str(e), -1, 0, total_count])
            self.queue.put([self.msg_name, 'INFO', str(e), 0, 0])
        finally:
            connect.commit()
            connect.close()

        self.queue.put([self.msg_name, '', 0, None, total_count])
开发者ID:fasiondog,项目名称:hikyuu,代码行数:69,代码来源:ImportWeightToSqliteTask.py

示例2: open

# 需要导入模块: from pytdx.hq import TdxHq_API [as 别名]
# 或者: from pytdx.hq.TdxHq_API import disconnect [as 别名]
    net_file = urllib.request.urlopen('http://www.qianlong.com.cn/download/history/weight.rar', timeout=60)
    dest_filename = dest_dir + '/weight.rar'
    with open(dest_filename, 'wb') as file:
        file.write(net_file.read())

    print("下载完成,正在解压...")
    os.system('unrar x -o+ -inul {} {}'.format(dest_filename, dest_dir))

    print("解压完成,正在导入...")
    add_count = qianlong_import_weight(connect, dest_dir + '/weight', 'SH')
    add_count += qianlong_import_weight(connect, dest_dir + '/weight', 'SZ')
    print("导入数量:", add_count)

    print("\n导入上证分笔数据")
    #add_count = import_trans(connect, 'SH', quotations, api, dest_dir, max_days=2, progress=ProgressBar)
    print("\n导入数量:", add_count)


    print("\n导入上证分时数据")
    add_count = import_time(connect, 'SZ', quotations, api, dest_dir, max_days=3, progress=ProgressBar)
    print("\n导入数量:", add_count)
    """

    api.disconnect()
    connect.close()

    endtime = time.time()
    print("\nTotal time:")
    print("%.2fs" % (endtime - starttime))
    print("%.2fm" % ((endtime - starttime) / 60))
开发者ID:fasiondog,项目名称:hikyuu,代码行数:32,代码来源:pytdx_to_h5.py


注:本文中的pytdx.hq.TdxHq_API.disconnect方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。