Skip to content

Instantly share code, notes, and snippets.

View mekarpeles's full-sized avatar
📚
Universal Access to All Knowledge

Mek mekarpeles

📚
Universal Access to All Knowledge
View GitHub Profile
@mekarpeles
mekarpeles / star_ratings_search.diff
Created August 15, 2024 17:47
Adding star ratings info to search page
diff --git a/openlibrary/plugins/worksearch/code.py b/openlibrary/plugins/worksearch/code.py
index be3f4cefe..40d613166 100644
--- a/openlibrary/plugins/worksearch/code.py
+++ b/openlibrary/plugins/worksearch/code.py
@@ -308,8 +308,10 @@ def do_search(
:param sort: csv sort ordering
:param spellcheck_count: Not really used; should probably drop
"""
+ # If you want work_search page html to extend default_fetched_fields:
+ extra_fields = {'editions', 'providers', 'ratings_average', 'ratings_count'}
@mekarpeles
mekarpeles / ol_api_header_example.py
Created May 22, 2024 15:59
python example of adding app identification headers to openlibrary.org API calls
import requests
url = "https://openlibrary.org/search.json?q=test"
headers = {
"User-Agent": "MyAppName/1.0 ([email protected])"
}
response = requests.get(url, headers=headers)
@mekarpeles
mekarpeles / ol_api_header_example.js
Created May 22, 2024 15:58
js example of adding app identification headers to openlibrary.org API calls
const url = "https://openlibrary.org/search.json?q=test";
const headers = new Headers({
"User-Agent": "MyAppName/1.0 ([email protected])"
});
const options = {
method: 'GET',
headers: headers
};
fetch(url, options)
.then(response => response.json())
@mekarpeles
mekarpeles / git-walkthrough.md
Last active April 22, 2024 17:40
Git aWalkthrough: The ins-and-outs of git

Git Walkthrough

This guide provides a walkthrough of a basic git workflow and attempts to describe what is happening under the hood as commands are run.

  1. We can create a new git repository using git init which creates a hidden directory called .git/
  • The init process fills .git/ with a special file called HEAD that contains the name of the branch or the commit we're on
  • If the contents of the HEAD file is the name of a branch, then we can look in .git/refs/heads/<branchname> e.g. .git/refs/heads/main to figure out the specific commit the branch is on: e.g. ba012fe642b796af4e5735a7e6c83e4e90f9e62b
  • When we first start out, HEAD is likely the main branch which maps to a nil (non-existant) commit
  1. We can stage files to be committed to a checkpoint by using the command: git add and then commit them using git commit -"message".
@mekarpeles
mekarpeles / gutenberg-api.md
Last active October 13, 2023 00:38
Project Gutenberg API
@dataclass
class ImportRecordSchema:
...
class ImportRecord:
def __init__(self, **data):
self.data = ImportRecordSchema(data)
self.validate() # include promise item check, or raise exceptions
self.edition_key = self.find_matching_edition()
self.edition = self.edition_key and web.ctx.site.get(self.edition_key)
@mekarpeles
mekarpeles / goodreads-rss-to-ol-query
Created January 23, 2023 22:29
goodreads rss to ol query
var isbnList = []
fetch("https://www.goodreads.com/review/list_rss/118293813?shelf=%23ALL%23")
.then(response => response.text())
.then(data => {
let parser = new DOMParser();
let xmlDoc = parser.parseFromString(data, "application/xml");
let isbnTags = xmlDoc.getElementsByTagName("isbn");
for (let i = 0; i < isbnTags.length; i++) {
if (isbnTags[i].innerHTML !== "") {
isbnList.push(isbnTags[i].innerHTML);
import requests
"""
- ✅ Show English editions of each
- ✅ Show IA editions of each
- ✅ Show most readable edition
- ❌ They should be in order of publication
- ✅ searching for "chambre des secrets" should
- ✅ Show HP2 somewhere
- ✅ Show French HP2 edition/title
function getBooks(container) {
const reISBN = /((978)?[0-9][0-9]{10}[0-9xX])|((978)?[0-9]{9}[0-9Xx])/;
const elements = document.getElementsByClassName(container);
let isbnElementMap = {};
for (let i=0; i<elements.length; i++) {
let e = elements.item(i);
let match = e.innerHTML.match(reISBN);
if (match) {
isbnElementMap[match[0]] = e;
}
@mekarpeles
mekarpeles / mostrecommendedbooks.js
Created July 20, 2021 23:38
Example of adding Open Library borrow buttons to mostrecommendedbooks.com
function getBooks(container) {
const reISBN = /((978)?[0-9][0-9]{10}[0-9xX])|((978)?[0-9]{9}[0-9Xx])/;
const elements = document.getElementsByClassName(container);
let isbnElementMap = {};
for (let i=0; i<elements.length; i++) {
let e = elements.item(i);
let match = e.innerHTML.match(reISBN);
if (match) {
isbnElementMap[match[0]] = e;
}