Ejemplo n.º 1
0
 def __polling_request(cls, query):
     response = CalilService.__request_sub(query)
     # 2回目以降のレスポンスはJSONP固定になるため
     json_string = response.text[9:-2]
     json_data = json.loads(json_string)
     Log.info(json.dumps(json_data, sort_keys=True, indent=4))
     return json_data
Ejemplo n.º 2
0
 def __load_dotenv(self):
     dotenv_path = os.path.join(self.root_dir, ".env")
     if os.path.exists(dotenv_path):
         Log.info(">>>>>>>>>>>>>> find .env : {0}".format(dotenv_path))
         load_dotenv(dotenv_path)
     else:
         Log.info(">>>>>>>>>>>>>> not find .env : {0}".format(dotenv_path))
Ejemplo n.º 3
0
    def __get_table(cls, soup, id_string):
        table = soup.select("form[name='" + id_string +
                            "'] > div > table[border]")

        if len(table) <= 0:
            Log.info("table not found.")
            return None

        return table
Ejemplo n.º 4
0
    def __init__(self, status, order, title, kind, yoyaku_date, torioki_date,
                 receive_lib):
        self.status = status
        self.order = order
        self.order_num = self.__get_order_num(order)
        self.title = title
        self.kind = kind
        self.yoyaku_date = yoyaku_date
        self.torioki_date = torioki_date
        self.receive_lib = receive_lib
        self.is_prepared = ReservedBook.__is_prepared(status)
        self.is_dereverd = ReservedBook.__is_dereverd(status)

        Log.info(self.to_string())
Ejemplo n.º 5
0
    def get_books(cls, html, books):
        soup = HtmlParser.__get_soup(html)
        table = HtmlParser.__get_books_table(soup, books)
        if table is None:
            return books

        tds_list = HtmlParser.__get_target_tds_list(table)
        for tds in tds_list:
            books.create_and_append(tds)

        Log.info("number of {0}:{1}".format(books.__class__.__name__,
                                            books.len))

        return books
Ejemplo n.º 6
0
    def __init__(
        self,
        name: str,
        expire_date_text: str,
        can_extend_period: bool,
        extend_period_button_name: str,
    ) -> None:
        self.name: str = name
        self.expire_date: date = parse(expire_date_text).date()
        self.expire_date_text: str = expire_date_text
        self.can_extend_period: bool = can_extend_period
        self.extend_period_button_name: str = extend_period_button_name

        Log.info(self.to_string())
Ejemplo n.º 7
0
    def __get_target_tds_list(cls, table):
        trs = table[0].find_all("tr")

        target_tds_list = []
        for tr in trs:
            tds = tr.find_all(["td", "th"])
            no = tds[0].string.strip()
            if no.isnumeric() is False:
                continue
            target_tds_list.append(tds)

        Log.info("number of target tr tag:{0}".format(len(target_tds_list)))

        return target_tds_list
Ejemplo n.º 8
0
    def __check_books(self, book_filters):
        html_page = HtmlPage()

        first_book_filter = book_filters[0]
        print("-------------> first_book_filter.users:" +
              first_book_filter.users)
        target_users = self.users.filter(first_book_filter.users)
        for user in target_users.list:
            Log.info(user.name)

            html = html_page.fetch_login_page(Library.LIBRALY_HOME_URL, user)

            for book_filter in book_filters:
                empty_books = Library.__create_empty_books(
                    book_filter.books_class_name)
                books = HtmlParser.get_books(html, empty_books)
                books.apply_filter(book_filter)
                user.set_books(book_filter.books_class_name, books)

        html_page.release_resource()

        return target_users
Ejemplo n.º 9
0
 def __init__(self) -> None:
     Log.info("driver.create/start")
     options = ChromeOptions()
     # 必須
     options.add_argument("--headless")
     options.add_argument("--disable-gpu")
     # エラーの許容
     options.add_argument("--ignore-certificate-errors")
     options.add_argument("--allow-running-insecure-content")
     options.add_argument("--disable-web-security")
     # headlessでは不要そうな機能
     options.add_argument("--disable-desktop-notifications")
     options.add_argument("--disable-extensions")
     # UA
     user_agent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.102 Safari/537.36"  # noqa
     options.add_argument("--user-agent=" + user_agent)
     # 言語
     options.add_argument("--lang=ja")
     # 画像を読み込まないで軽くする
     options.add_argument("--blink-settings=imagesEnabled=false")
     self.driver = Chrome(options=options)
     Log.info("driver.create/end")
Ejemplo n.º 10
0
 def release_resource(self) -> None:
     Log.info("driver.quit/start")
     self.driver.quit()
     Log.info("driver.quit/end")
Ejemplo n.º 11
0
 def test_log(self):
     Log.info("test")
Ejemplo n.º 12
0
 def test_log_exception(self):
     Log.logging_exception(Exception("test"))
Ejemplo n.º 13
0
 def log(self):
     Log.info("isbn : " + self.isbn)
     Log.info("title : " + self.title)
     Log.info("author : " + self.author)
     Log.info("caption : " + self.caption)
     Log.info("price : " + str(self.price))
     Log.info("url : " + self.url)
     Log.info("image_url : " + self.image_url)
     Log.info("sales_date : " + self.sales_date)
Ejemplo n.º 14
0
 def log(self):
     Log.info("isbn : " + self.isbn)
     Log.info("reserveurl : " + self.reserveurl)
     Log.info("libkey : " + str(self.libkey))
     Log.info("id : " + self.id)
     Log.info("kbot_reserve_url : " + self.kbot_reserve_url)
Ejemplo n.º 15
0
 def fetch_login_page(self, login_url: str, user: User) -> str:
     self.__login(login_url, user)
     Log.info("driver.page_source.encode/start")
     html = self.driver.page_source.encode("utf-8")
     Log.info("driver.page_source.encode/end")
     return html
Ejemplo n.º 16
0
    def __login(self, login_url: str, user: User) -> None:
        Log.info("login..... : user.name={0}, url={1}".format(user.name, login_url))

        self.driver.get(login_url)
        Log.info("----------- 1: [end] driver.get(url)")

        self.__wait()
        Log.info("----------- 2: [end] wait")

        # ログインボタン押下
        uid = self.__wait_element((By.NAME, "usercardno"))
        password = self.__wait_element((By.NAME, "userpasswd"))
        uid.send_keys(user.id)
        password.send_keys(user.password)
        Log.info("----------- 3: [end] sended_keys")
        button = self.__wait_element((By.NAME, "Login"))
        Log.info("----------- 4: [end] button wait")
        button.click()
        Log.info("----------- 5: [end] button.click()")

        # ロードされたかを確認
        self.__wait_element((By.NAME, "FormLEND"))
        Log.info("----------- 6: [end] wait")
Ejemplo n.º 17
0
 def __request(cls, query):
     response = CalilService.__request_sub(query)
     json_data = response.json()  # TODO:nullチェック
     Log.info(json.dumps(json_data, sort_keys=True, indent=4))
     return json_data