This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import argparse | |
import internetarchive as ia | |
import biblionames | |
#from isbn_hyphenate import hyphenate | |
from isbnlib import mask as hyphenate | |
OCLC_TAG = 'urn:oclc:record:' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Install reqs | |
sudo apt install rename | |
# Test rename command: | |
rename -n 's/(\d+)(?=.*\.)/sprintf("%03d",$1)/eg' *.jpg | |
# Bash commands to 0 pad (to 3 digits) numbers in .jpg filenames | |
rename 's/(\d+)(?=.*\.)/sprintf("%03d",$1)/eg' *.jpg |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Validate and format ISSNs | |
def validISSN(issn): | |
issn = issn.upper().replace('X', 'A').replace('-', '') | |
return len(issn) == 8 and sum((8 - i) * int(n, 16) for i, n in enumerate(issn)) % 11 == 0 | |
def formatISSN(issn): | |
issn = issn.upper().replace('-', '') | |
return f'{issn[:4]}-{issn[4:]}' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from baseconv import base58 | |
from isbnlib import is_isbn13, check_digit13 | |
def compress_isbn(isbn): | |
# compresses a valid checkdigit ISBN13 | |
isbn = isbn.replace('-', '') | |
assert is_isbn13(isbn) | |
prefix = isbn[:3] | |
body = isbn[3:-1] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
[copied from https://github.com/internetarchive/openlibrary/pull/6841#issuecomment-1207507062] | |
I'm recording this here because there is very little information currently about ISNI check digits online. | |
ISNI uses a checkdigit {0-9, X} calculation system which is called something like "MOD 11-2" and is | |
defined in the standard [ISO 7064](https://en.wikipedia.org/wiki/ISO/IEC_7064), but you have to pay to read it.... | |
The same "MOD 11-2" system is used by the | |
Chinese [Resident Identity Card](https://en.wikipedia.org/wiki/Resident_Identity_Card), | |
which has its own specs and more publicly available code examples. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
""" | |
Esoteric programming language interpreter for | |
G_arD^EN CorUtY@rD | |
https://esolangs.org/wiki/G_arD%5EEN_CorUtY@rD | |
Interpreter by Salpynx, 2022. | |
""" | |
import sys |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Python Portable Minsky Machine | |
Implements a Python version of | |
https://esolangs.org/wiki/Portable_Minsky_Machine_Notation | |
""" | |
counters = {} | |
def inc(counter): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Takes an input file argument (a sorted list of ISBN13s) | |
# and counts how many ISBNs are present belonging to each | |
# regional agency as listed in the official | |
# ISBN export_rangemessage.xml data. | |
wget -nc https://www.isbn-international.org/export_rangemessage.xml | |
while read prefix agency; do |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
# Based on Google Drive v3 API Quickstart example | |
# https://developers.google.com/drive/api/v3/quickstart/python | |
import os.path | |
import io | |
import sys | |
from googleapiclient.discovery import build | |
from googleapiclient.http import MediaIoBaseDownload |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Library codabar (14 digit barcode) check digit validator | |
# (1 digit):material type + (4 digits):library code + (8 digits):item code + (1 digit): checksum | |
# source: http://www.makebarcode.com/specs/codabar.html | |
# - GOOD! | |
def vcodabar(n): | |
"""Validate the checkdigit of a 14 digit library barcode.""" | |
check = int(n[-1]) | |
data = n[:-1] | |
total = 0 | |
for i, c in enumerate(data): |
NewerOlder