Code Monkey home page Code Monkey logo

bookstw's Introduction

English | 简体中文 | 繁體中文

bookstw

Powered by selenium, bookstw is a simple Python library to interact with Books.com.tw.

Installation

pip install bookstw

Quick Start

Let's get started with a simple example that logs in to Books.com.tw and takes the daily sign-in action:

Note

For now it is the only feature provided by bookstw.

from selenium.webdriver import Chrome
from selenium.webdriver.chrome.options import Options

from bookstw import BooksTWRunner
from bookstw.ocr.baidu import BaiduHandwritingOCR

if __name__ == "__main__":
    baidu_ocr = BaiduHandwritingOCR(
        proxy={"http": "", "https": ""},
        api_key="<YOUR_API_KEY>",
        secret_key="<YOUR_SECRET>"
    )
    options = Options()
    options.add_argument("--disable-gpu")
    options.add_argument("--disable-logging")
    options.add_argument("--log-level=3")
    options.add_argument("--headless")
    options.add_experimental_option("excludeSwitches", ["enable-logging"])
    chrome = Chrome(options)

    runner = BooksTWRunner(ocr=baidu_ocr, webdriver=chrome)
    runner.login("<YOUR_USERNAME>", "<YOUR_PASSWORD>")
    runner.daily_sign_in()

The above code snippet demonstrates how to sign in daily with bookstw.

The BaiduHandwritingOCR is used to solve the captcha. It calls the Baidu Handwriting OCR API to recognize the captcha image.

Currently, it is the only OCR provider supported by bookstw. However, you can implement your own OCR provider by inheriting the BaseOCR class.

Github Actions

Fork this repository and create the following secrets in your repository:

  • BAIDU_API_KEY
  • BAIDU_SECRET_KEY
  • BOOKS_TW_USERNAME
  • BOOKS_TW_PASSWORD

Change INSTALL_FROM environment variable to PyPI in .yml file if you want to install from PyPI, or keep it as Poetry to install from source.

API Reference

bookstw.BooksTWRunner

bookstw.BooksTWRunner.__init__(ocr: BaseOCR, webdriver: WebDriver)

Creates a new BooksTWRunner instance.

  • ocr: The OCR provider used to solve the captcha.
  • webdriver: The WebDriver used to interact with Books.com.tw.

bookstw.BooksTWRunner.login(self, username: str, password: str, allow_manual_retry: bool = True, ocr_retry: int = 3, retry_delay: int = 5) -> None

Login to books.com.tw.

Captcha is solved using OCR.

  • username: Username.
  • password: Password.
  • allow_manual_retry: Allow manual retry if OCR failed.
  • ocr_retry: Number of retries for OCR.
  • retry_delay: Delay between retries in seconds.

bookstw.BooksTWRunner.daily_sign_in(self) -> None

Daily sign in to get Read Mileage.

If already signed in, it will throw an exception.

Known Issues

  • The "You haven't changed your password for a long time" dialog box is currently not being processed, which may cause Github Actions to fail.

bookstw's People

Contributors

zyf722 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.