Skip to main content

Unofficial Python API for SFPL

Project description

SFPL

Python Package for accessing account, book, and author data from the SFPL Website.

Status

travis pypi

Installation

From pip:

$ pip install sfpl

From source:

$ pip install git+git://github.com/kajchang/SFPL.git

Or clone / download this repository and $ python setup.py install or $ pip install .

Frameworks Used

requests - Used for getting data from the SFPL website and managing login cookies.

bs4 + lxml - Used for parsing information from HTML.

Features

  • Managing current checkouts and holds for your SFPL library account.

  • Searching for books by keyword, title, author, subject, and tag and searching for user-created book lists.

  • Following other library users and viewing their book lists.

  • Getting libary branch hours.

TODO

  • Better Book Status Messages

How to Use

Searching for books on Python:

>>> from sfpl import Search
>>> python_search = Search('Python')
>>> results = python_search.getResults(pages=2) # .getResults is a generator that yields / streams pages of results
>>> for page in results:
		print(page)
[Python by Donaldson, Toby, Python by Johansen, Andrew, Python! by Moses, Brian, Python by McGrath, Mike, Python by Vo. T. H, Phuong]
[Python by Romano, Fabrizio, Python by Phillips, Dusty, Python by Joshi, Prateek, Python by Lassoff, Mark, Python by Wayani, Rafiq]

Searching for books by J.K. Rowling:

>>> from sfpl import Search
>>> jk_search = Search('J.K. Rowling', _type='author')
>>> results = jk_search.getResults()
>>> first_page = next(results)
>>> first_page[0].title
"Harry Potter and the Sorcerer's Stone"
>>> first_page[0].getDescription()
"For the first time, J. K. Rowling's beloved Harry Potter ..."

Searching for book lists related to San Francisco:

>>> from sfpl import Search
>>> list_search = Search('San Francisco', _type='list')
>>> results = list_search.getResults()
>>> first_page = next(results)
>>> first_page[0].title
'Made in SF - San Francisco love for young readers'
>>> for book in first_page[0].getBooks():
		print(book)
Al Capone Does My Shirts by Choldenko, Gennifer
Book Scavenger by Bertman, Jennifer Chambliss
...

Getting all your books on hold:

>>> from sfpl import Account
>>> my_account = Account('barcode', 'pin') # Replace with your barcode and pin.
>>> my_holds = my_account.getHolds()
>>> for book in my_holds:
		print(book.title)
'Python for Data Analysis'
'Automate the Boring Stuff With Python'
>>> for book in my_holds:
		print(book.status)
'#4 on 6 copies'
'#7 on 3 copies'
>>> for book in my_holds:
		print(book.author)
'McKinney, Wes'
'Sweigart, Al'

Searching for books by J.K. Rowling but not about Harry Potter:

>>> from sfpl import AdvancedSearch
>>> search = AdvancedSearch(includeauthor='J.K. Rowling', excludekeyword='Harry Potter') # Search for books by J.K. Rowling but don't include 'Harry Potter'
>>> results = search.getResults()
>>> for book in results:
		print(book.title)
'Fantastic Beasts and Where to Find Them'
'Fantastic Beasts and Where to Find Them : The Original Screenplay'
'The Casual Vacancy'
'Very Good Lives'
'Una vacante imprevista'

Getting hours for a library branch:

>>> from sfpl import Branch
>>> branch = Branch('anza')
>>> branch.getHours()
{'Sun': '1 - 5', 'Mon': '12 - 6', 'Tue': '10 - 9', 'Wed': '1 - 9', 'Thu': '10 - 6', 'Fri': '1 - 6', 'Sat': '10 - 6'}

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

sfpl-1.5.7.tar.gz (14.0 kB view details)

Uploaded Source

Built Distribution

sfpl-1.5.7-py3-none-any.whl (11.6 kB view details)

Uploaded Python 3

File details

Details for the file sfpl-1.5.7.tar.gz.

File metadata

  • Download URL: sfpl-1.5.7.tar.gz
  • Upload date:
  • Size: 14.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.0 CPython/3.10.9

File hashes

Hashes for sfpl-1.5.7.tar.gz
Algorithm Hash digest
SHA256 c3303a7c1a62f369587d26ec2fee69cb6513c7600c74353fe0c17eb9ab273f51
MD5 b40dd640da153e7f5a262ca7ddd4c3e8
BLAKE2b-256 8d1f1205e155b62d17cdacf26ea043c3d75a4e9769d677915eae39ba4e168814

See more details on using hashes here.

File details

Details for the file sfpl-1.5.7-py3-none-any.whl.

File metadata

  • Download URL: sfpl-1.5.7-py3-none-any.whl
  • Upload date:
  • Size: 11.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.0 CPython/3.10.9

File hashes

Hashes for sfpl-1.5.7-py3-none-any.whl
Algorithm Hash digest
SHA256 1a30ed1127d1aeebf201b243e415d8efcfc6e77409a276e041faee5a7e5e59dd
MD5 a7bb710dd8f7d923d2b146328e63211a
BLAKE2b-256 e601ac761f19d2f6390f40d57860d7042e43498c8e076556043ccbb56a6befe7

See more details on using hashes here.

Supported by

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