-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Coding Recipes
Mek edited this page Jan 19, 2025
·
3 revisions
Any time you want to import and test open library code that needs access to web.ctx, you'll need to run a magic incantation 🧙.
First, you need to exec into the docker container and launch python:
docker compose exec -it web python
Next, use the following incantation to load Open Library and launch a minimal headless app:
import web
import infogami
import os
from openlibrary.config import load_config
path = '/olsystem/etc/openlibrary.yml' # prod
if not os.path.exists('/olsystem/etc/openlibrary.yml'):
path = 'config/openlibrary.yml' # fallback to dev
load_config(path)
infogami._setup()
from infogami import config
Most privileges actions/requests Open Library takes on behalf of a patron will require their s3 keys:
from openlibrary import accounts
from openlibrary.accounts.model import OpenLibraryAccount
logged_in_user = accounts.get_current_user()
username = logged_in_user and logged_in_user.key.split('/')[-1]
account = username and OpenLibraryAccount.get(username=username)
s3_keys = web.ctx.site.store.get(account._key).get('s3_keys')
keys = ["/works/OL5285479W", "/works/OL257943W", "/works/OL27448W"]
docs = web.ctx.site.get_many(keys)
How to determine, given a set of patron usernames, which have public reading logs / can be followed?
usernames = ['mekBot', 'ScarTissue', 'seabelis', 'brewster', 'jachamp']
user_prefs = web.ctx.site.get_many([f'/people/{username}/preferences' for username in usernames])
followable = dict((user.key.split('/')[2], user.notifications.public_readlog == 'yes') for user in user_prefs)
Getting Started & Contributing
- Setting up your developer environment
- Using
git
in Open Library - Finding good
First Issues
- Code Recipes
- Testing Your Code, Debugging & Performance Profiling
- Loading Production Site Data ↦ Dev Instance
- Submitting good Pull Requests
- Asking Questions on Gitter Chat
- Joining the Community Slack
- Attending Weekly Community Calls @ 9a PT
- Applying to Google Summer of Code & Fellowship Opportunities
Developer Resources
- FAQs: Frequently Asked Questions
- Front-end Guide: JS, CSS, HTML
- Internationalization
- Infogami & Data Model
- Solr Search Engine Manual
- Imports
- BookWorm / Affiliate Server
- Writing Bots
Developer Guides
- Developing the My Books & Reading Log
- Developing the Books page
- Understanding the "Read" Button
- Using cache
- Creating and Logging into New Users
- Feature Flagging
Other Portals
- Design
- Librarianship
- Communications
- Staff (internal)
Legacy
Old Getting Started
Orphaned Editions Planning
Canonical Books Page