當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。