Skip to main content

Find a book download URL from multiple online book sources

Project description

Install

$ pip install pybooks

Usage

Simple usage

from pybooks.pbook import Pbooks 

pbook = Pbooks( author='jerome',
                title='elements of statistic',
                weights=(9, 1)) 
         

pbook.main()

The weights argument is used to calculate the accuracy of all the items found and the final chosen url. For example, a weights of (9, 1) will place more important on the author accuracy than title's hence it is more likely that the result will have author's name more similar to the input. Default weights are (1, 1)

Optional arguments are show_result: Print the result at the end or not, threshold: Only print result with accuracy higher than threshold and log: Show process while running or not, etc. More arguments can be found in the documentation of the code.

You can modify or add additional sources by editing the file pybooks/sources.json and follow the existing format within the file.

Sources.json format, rules

Example: Library Genesis with elements of statistics as search term

The only components we need in the URL are: request: ?req=..., delimiter: + (elements+of+statistics) and pagination: page=... and term_concatenation: & (req=...&page=...)

INSIDE SOURCES.JSON

URL: main url without search terms
URL_RULES: dictionary contains keys and values as search rules.
HTML_RULES: Contains nested dictionary represent necessary components to conduct searches such as tags, attributes for titles, authors, rows and page body
.POSITION: The position of the that element in the row if there are other similar elements with similar tag and attributes, leave as null if it is unique
.TAG: The tag of the desired element
.ATTRIBUTE: Attributes of the tag, for exanple: {"class": "id", "...": "..", ...}. Leave the value of a key as true if an attribute has no value

COMMAND LINE USAGE

You can use the package directly from the command line Example: Searching a book with title: "Elements of statistical learning" and author: "Jerome Friedman" You can add pbook.exe to environment variables and use it from the command line by this command with %PATH% as your path to pybooks directory (folder), usually found in \Python{version}\Lib\pybooks.

setx PATH "%PATH%
pbook -a "jerome friedman" -t "elements of statistical learning"
OPTIONAL ARGUMENTS
-h, --help            show this help message and exit
  -a AUTHOR, --author AUTHOR
                        Author of the book you want to find
  -t TITLE, --title TITLE
                        Title of the book you want to find
  -w WEIGHTS, --weights WEIGHTS
                        Assign author and title weight to the final accuracy
                        calculation
  -th THRESHOLD, --threshold THRESHOLD
                        Only get results above the threshold amount
  -l LOG, --log LOG     Print out the process
  -s SHOW, --show SHOW  Show result at the end of running
  -br BREAK_AT, --break-at BREAK_AT
                        Stop when encounter a book with accuracy higher than
                        or equal to this number
  -m METHOD, --method METHOD
                        Choose a book evaluation method

LICENSE

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pybooks-1.4.3.tar.gz (8.0 MB view details)

Uploaded Source

File details

Details for the file pybooks-1.4.3.tar.gz.

File metadata

  • Download URL: pybooks-1.4.3.tar.gz
  • Upload date:
  • Size: 8.0 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.5.0.1 requests/2.20.0 setuptools/39.0.1 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.6.6

File hashes

Hashes for pybooks-1.4.3.tar.gz
Algorithm Hash digest
SHA256 119a72d3d89c35774c480696580f7310f0452c4fc3cdd510883da41895e5f267
MD5 37375ba965d4b877d6e50fe5b58233c1
BLAKE2b-256 1073516998643e751c542fde6fb90f78e8fae9fa3e333e3b103c024155e7f866

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page