Skip to content

Instantly share code, notes, and snippets.

View hornc's full-sized avatar
👾

Charles Horn hornc

👾
  • Wellington, New Zealand
View GitHub Profile
@hornc
hornc / servicename
Last active September 27, 2016 03:33
basic sysv service statup script for init.d
#!/bin/bash
#
# /etc/rc.d/init.d/<servicename>
servicename="<servicename"
script="/home/root/servicename.sh"
case "$1" in
start)
echo -n "Starting $servicename service: "
works to merge:
https://openlibrary.org/authors/OL6028427A/Akademii%CD%A1a_nauk_SSSR._Arkheograficheskai%CD%A1a_komissii%CD%A1a
https://openlibrary.org/works/OL16107163W/Sochineniia%EF%B8%A0_%EF%B8%A1
This seems to be the main work: https://openlibrary.org/works/OL623490W/Sochinenii%EF%B8%A0a%EF%B8%A1
@hornc
hornc / update_author.py
Last active April 19, 2017 07:26
Update single author test
from olclient.openlibrary import OpenLibrary
import json
import csv
import re
ol = OpenLibrary(base_url = 'https://dev.openlibrary.org')
def wikidata_id(url):
return re.search(r'[^/]*$', url).group(0)
from olclient.openlibrary import OpenLibrary
import json
ol = OpenLibrary()
DEBUG=True
def get_editions_from_work(olid):
if DEBUG:
print olid
editions = [e.olid for e in ol.Work.get(olid).editions]
from unicodedata import normalize
def norm(s):
return normalize('NFC', s)
def is_nfc(s):
norm = normalize('NFC', s)
print "%s => %s" % (s, norm)
return s == norm
@hornc
hornc / authors.sparql
Created July 28, 2017 11:10
Wikidata SPARQL: People with VIAFs and notable works, without OLIDs
#People with VIAFs and notable works, without OLIDs
SELECT ?author (SAMPLE(?authorLabel) AS ?authorLabel)
(SAMPLE(?dob) AS ?dob) (SAMPLE(?dod) AS ?dod)
(SAMPLE(?viaf) AS ?viaf) (COUNT(?notable) AS ?works) WHERE {
?author wdt:P31 wd:Q5;
wdt:P800 ?notable;
rdfs:label ?authorLabel;
wdt:P214 ?viaf;
wdt:P569 ?dob;
@hornc
hornc / duped_OLIDs.sparql
Created August 2, 2017 06:45
Duplicate OLIDs on Wikidata
#People with more than one OLID
#https://query.wikidata.org/#%23People%20with%20more%20than%20one%20OLID%0ASELECT%20%3Fitem%20%3FitemLabel%20%3Fcount%0AWHERE%0A%7B%0A%20%20%7B%0A%20%20%20%20SELECT%20%3Fitem%20%28COUNT%28DISTINCT%20%3Folid%29%20AS%20%3Fcount%29%20WHERE%20%7B%0A%20%20%20%20%20%20%3Fitem%20wdt%3AP31%20wd%3AQ5%20.%0A%20%20%20%20%20%20%3Fitem%20wdt%3AP648%20%3Folid%20.%0A%0A%20%20%20%20%7D%0A%20%20%20%20GROUP%20BY%20%3Fitem%0A%20%20%7D%0A%20%20FILTER%20%28%20%3Fcount%20%3E%201%20%29%0A%20%20SERVICE%20wikibase%3Alabel%20%7B%20bd%3AserviceParam%20wikibase%3Alanguage%20%22en%22%20.%20%7D%0A%7D%0AORDER%20BY%20DESC%28%3Fcount%29%20%3FitemL
SELECT ?item ?itemLabel ?count
WHERE
{
{
SELECT ?item (COUNT(DISTINCT ?olid) AS ?count) WHERE {
?item wdt:P31 wd:Q5 .
?item wdt:P648 ?olid .
@hornc
hornc / hello_world.bf
Created September 12, 2017 03:57
Hello World in Brainfuck, stores ascii as 2-byte pairs of hex
>
++ > + >
+++++ + > ++++ >
+++++ + > +++++ +++++ ++ >
+++++ ++ > ++ >
+++++ + > +++++ +++++ +++++ >
+++++ ++ > +++++ ++ >
++ > >
++ > +++++ +++++ ++ >
+++++ + > +++++ +++++ +++++ >
@hornc
hornc / kite_runner_merge.py
Last active September 21, 2017 12:21
Example semi-automated bot merge
# Steps to merge a number of Kite Runner editions and works:
from catharbot import catharbot
bot = catharbot.CatharBot()
def merge_unique_lists(lists, hash_fn=None):
"""
Combine unique lists into a new unique list. Preserves ordering.
"""
result = []
from catharbot import catharbot
bot = catharbot.CatharBot()
# Work In Progress
# uses the 'merging' branch of Catharbot, https://github.com/hornc/catharbot/tree/merging
def extract_olid(olid):
"""Convert a string like '/authors/OL1412764A' to just 'OL1412764A'"""
return olid.split('/')[-1]
def remove_editions(duplicates, docs):