Ejemplo n.º 1
0
    def create_db(self, user_name: str) -> bool:
        """ DB生成
        """
        try:
            # 接続
            self.__connect_db()
            # テーブル生成
            # 未生成時のみ生成を行う
            #self.__user_info_tbl_cursor.execute("drop table if exists %s" % USER_INFO)
            # ユーザ情報テーブル
            self.__user_info_tbl_cursor.execute(
                "create table if not exists %s (user_name text primary key, table_name text)"
                % USER_INFO)
            #
            self.__book_info_tbl_name = user_name + BOOK_INFO
            #self.__book_info_tbl_cursor.execute("drop table if exists %s" % (table_name))
            self.__book_info_tbl_cursor.execute(
                "create table if not exists %s (author_name text primary key, date text)"
                % (self.__book_info_tbl_name))

            # 検索情報テーブルを追加
            query_str = "insert into " + USER_INFO + " values (?, ?)"
            # 現データ数取得
            #self.__user_info_tbl_cursor.execute("select count(*) from %s " % self.__user_info_tbl_name)
            #data_max = self.__user_info_tbl_cursor.fetchall()
            self.__user_info_tbl_cursor.execute(
                query_str, (user_name, self.__book_info_tbl_name))

        except sqlite3.Error as e:
            # 検索対象情報テーブル名保持
            self.__book_info_tbl_name = user_name + BOOK_INFO
            Debug.dprint(e.args[0])
            return False

        # output
        for row in self.__user_info_tbl_cursor.execute("select * from %s" %
                                                       USER_INFO):
            Debug.tmpprint(row)
            for row_sub in self.__book_info_tbl_cursor.execute(
                    "select * from %s" % row[1]):
                Debug.tmpprint(row_sub)

        # 接続解除
        self.__disconnect_db()
        return True
Ejemplo n.º 2
0
 def add_book_info(self, author: str, date: str):
     """ 検索対象情報追加  
     [I] author : 著者名 [I] date 出力対象日閾値
     """
     # 接続
     self.__connect_db()
     # 追加
     try:
         query_str = "insert into " + self.__book_info_tbl_name + " values (?, ?)"
         self.__book_info_tbl_cursor.execute(query_str, (author, date))
     except sqlite3.Error as e:
         Debug.dprint(e.args[0])
     # output
     for row in self.__book_info_tbl_cursor.execute(
             "select * from %s" % self.__book_info_tbl_name):
         Debug.tmpprint(row)
     # 接続解除
     self.__disconnect_db()
Ejemplo n.º 3
0
 def set_user_info_key(self, user_name: str) -> bool:
     """ ユーザ情報テーブル主キー設定  
     [I] username ユーザ名  
     [O] 結果
     """
     result = False
     try:
         # DB接続
         self.__connect_db()
         # 検索
         query_str = "select * from " + USER_INFO + " where user_name=?"
         self.__user_info_tbl_cursor.execute(query_str, (user_name, ))
         if self.__user_info_tbl_cursor.fetchone is not None:
             # 検索対象情報テーブル名保持
             self.__book_info_tbl_name = user_name + BOOK_INFO
             result = True
     except sqlite3.Error as e:
         Debug.dprint(e.args[0])
     # 未登録情報
     self.__disconnect_db()
     return result
Ejemplo n.º 4
0
 def get_db_search_list(self) -> list:
     """ 著者名リスト取得  
     [O] 著者リスト(DBAuthorInfo型)
     """
     search_list = []
     try:
         # DB接続
         self.__connect_db()
         # 全データ取得
         query_str = "select * from " + self.__book_info_tbl_name
         self.__book_info_tbl_cursor.execute(query_str)
         # 1データずつリストに保持
         for row in self.__book_info_tbl_cursor.fetchall():
             book_info = DBAuthorInfo()
             book_info.author_name = row[0]
             book_info.search_date = row[1]
             search_list.append(book_info)
     except sqlite3.Error as e:
         Debug.dprint(e.args[0])
     # 接続解除
     self.__disconnect_db()
     return search_list
 def exec_search(self, url:str) -> List[webdriver.remote.webelement.WebElement]:
     """ 検索実行
     渡されたURLから検索処理を実行する  
     [I] url : 検索実行URL  
     [O] 検索結果
     """
     Debug.tmpprint("func : exec_search")
     self.__driver.get(url)
     body = self.__driver.find_element_by_tag_name("body")
     body.send_keys(Keys.CONTROL + 't')
     divs = self.__driver.find_elements_by_class_name('s-result-item')
     # 失敗時は一定時間待ってから再度取得を試みる
     if len(divs) == 0:
         is_ok = False
         for retry in range(0,REQUEST_RETRY_NUM,1):
             time.sleep(REQUEST_WAIT_TIME *( retry+1))
             # 再度実行
             divs = self.__driver.find_elements_by_class_name('s-result-item')
             if len(divs) != 0:
                 is_ok = True
                 break
             else:
                 if retry == REQUEST_RETRY_NUM:
                     # リトライ上限に達した
                     Debug.dprint("request err -> " + self.__author_list[self.__search_cnt])
         if is_ok == False:
             # 最後まで成功しなかった場合該当データ削除
             self.__search_infos.pop(self.__author_list[self.__search_cnt])
             self.__author_list.pop(self.__search_cnt)
             # 結果なし
             divs = []
     # 検索ログ出力
     Debug.dprint("search author(" +  str(self.__search_cnt + 1) + "/" + str(self.get_author_list_num()) + ") -> " + self.__author_list[self.__search_cnt])
     # 検索数を進める
     self.__search_cnt += 1
     # 結果を返す
     return divs