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


Python Collector.collect_stock_information方法代码示例

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


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

示例1: __init__

# 需要导入模块: from collector import Collector [as 别名]
# 或者: from collector.Collector import collect_stock_information [as 别名]
class DBInitializer:
    def __init__(self):
        conf_path = "%s/FDM/FDM.conf"%(os.getcwd())
        self.__conf = ConfigParser.ConfigParser()
        self.__conf.read(conf_path)

        self.__conn = None
        
        self.collector = Collector()

    def start(self):
        host = self.__conf.get("mysql", "host")
        user = self.__conf.get("mysql", "user")
        password = self.__conf.get("mysql", "password")
        charset = self.__conf.get("mysql", "charset")
        db = self.__conf.get("mysql", "db")

        self.__conn = ConnManager.get_conn()

        cursor = self.__conn.cursor()
        try:
            cursor.execute("use %s"%(db))
        except:
            cursor.execute("create database %s default character set utf8"%(db))
            cursor.execute("use %s"%(db))

        cursor.close()
        self.__do_init(self.__conn)
    
    def __do_init(self, conn):
        self.__maybe_init_stocks_table(conn)
        self.__maybe_init_bonus_table(conn)
        self.__maybe_init_finance_table(conn)
        self.__maybe_init_market_table(conn)

    def __maybe_init_stocks_table(self, conn):
        cursor = conn.cursor()
        if cursor.execute('show tables like "stock_information"') == 0:
            print "init stock information..."
            sql_path = "%s/FDM/sqls/create_stocks_table.sql"%(os.getcwd())
            sql_file = open(sql_path, "r")
            create_table_sql = sql_file.read()
            sql_file.close()
            cursor.execute(create_table_sql)

            self.collector.collect_stock_information()
        cursor.close()

    def __maybe_init_bonus_table(self, conn):
        cursor = conn.cursor()
        if cursor.execute('show tables like "bonus"') == 0:
            print "init bonus..."
            sql_path = "%s/FDM/sqls/create_bonus_table.sql"%(os.getcwd())
            sql_file = open(sql_path, "r")
            create_bonus_sql = sql_file.read()
            sql_file.close()
            cursor.execute(create_bonus_sql)

            self.collector.collect_bonus()
        cursor.close()

    def __maybe_init_finance_table(self, conn):
        cursor = conn.cursor()
        if cursor.execute('show tables like "finance"') == 0:
            print "init finance..."
            sql_path = "%s/FDM/sqls/create_finance_table.sql"%(os.getcwd())
            sql_file = open(sql_path, "r")
            create_finance_sql = sql_file.read()
            sql_file.close()
            cursor.execute(create_finance_sql)

            self.collector.collect_finance()
        cursor.close()

    def __maybe_init_market_table(self, conn):
        cursor = conn.cursor()
        if cursor.execute('show tables like "market"') == 0:
            print "init market..."
            sql_path = "%s/FDM/sqls/create_market_table.sql"%(os.getcwd())
            sql_file = open(sql_path, "r")
            create_table_sql = sql_file.read()
            sql_file.close()
            cursor.execute(create_table_sql)

            self.collector.collect_market(XUEQIU)
        cursor.close()
开发者ID:simpleL,项目名称:FDM,代码行数:88,代码来源:db_initializer.py


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