Skip to content

Instantly share code, notes, and snippets.

@hughlilly
hughlilly / 100.txt
Last active October 10, 2017 01:33
Tweets each line from a text file, 40s apart.
Rifleman George Abbott (service number 41461), killed in action. View his record on #OnlineCenotaph: https://aucklandmuseum.com/war-memorial/online-cenotaph/record/C4
Private Francis Joseph Aisher (service number 40098), killed in action aged 21. View his record on #OnlineCenotaph: https://aucklandmuseum.com/war-memorial/online-cenotaph/record/C85
Private William Allan (service number 38925), killed in action aged 33. View his record on #OnlineCenotaph: https://aucklandmuseum.com/war-memorial/online-cenotaph/record/C164
Gunner George Robert Allard (service number 12893), killed in action aged 21. View his record on #OnlineCenotaph: https://aucklandmuseum.com/war-memorial/online-cenotaph/record/C165
Private Edward John Allen (service number 32494), killed in action aged 23. View his record on #OnlineCenotaph: https://aucklandmuseum.com/war-memorial/online-cenotaph/record/C176
Private Eric Charles Allison (service number 27431), killed in action. View his record on #OnlineCenotaph: https://aucklandmuseum.com/wa
@hughlilly
hughlilly / DNZ_Auckland.py
Last active August 29, 2018 00:35
Get Digital NZ data and write to out.csv
from pprint import pprint as pp
import settings, json, csv, codecs, cStringIO, requests
# Get API key from local file settings.py
key = settings.DNZ_API_KEY
# Define content partner names as variables
# This is to get around encoding of macron in AAG name
AAG = 'Auckland Art Gallery Toi o T'+unichr(257)+'maki'
AM = 'Auckland War Memorial Museum Tamaki Paenga Hira'
{
"message": "success",
"ships" : [
{
"name": "Limerick",
"horses": 348,
"men": 495
},
{
"name": "Arawa",
@hughlilly
hughlilly / 2019-62.sparql
Last active October 31, 2022 02:00
Queries made against the AM SPARQL endpoint at <http://api.aucklandmuseum.com/sparql>. When using the interface at https://yasgui.triply.cc, add an "Accept" header of "application/sparql-results+json" under Header Arguments in the cog menu. e.g. https://api.triplydb.com/s/3TDjGQmls
PREFIX am: <http://collections.aucklandmuseum.com/ontology/core/>
#SELECT (COUNT(?num) AS ?count) WHERE {
SELECT ?record WHERE {
?record am:accessionNumber ?num.
FILTER strstarts(?num,'2019.62')
}
@hughlilly
hughlilly / split_csv.py
Created February 27, 2020 20:27
Use Pandas to split a csv
import pandas as pd
count = 0
# Load csv as Pandas dataframe, set number of rows in each file to 9000
df = pd.read_csv('bigfile.csv', iterator=True, chunksize=9000)
# Iterate over each chunk
for chunk in df:
# Set output file name, appending count variable
@hughlilly
hughlilly / image-size-checker.py
Last active February 27, 2020 20:36
Check image file sizes to determine how many "not yet created" placeholders exist
# Auckland Museum Vernon AV file-size checker
# February 2020
# Expects a list of Vernon AV IDs in a .csv. Checks image file sizes,
# outputting a .csv that identifies images as either:
# (a) a "not yet created" placeholder, or
# (b) a "not available" placeholder, or
# (c) a correctly processed image (with a note of its size)
import csv
@hughlilly
hughlilly / linkcheck.py
Created April 1, 2020 23:22
Check AM API IDs to see if they exist
import csv
import requests
import pandas
import time
from collections import namedtuple
from tqdm import tqdm
# Takes a .csv of API IDs, which are manipulated to URLs below
# Outputs a .csv
infile = "IDs.csv"
@hughlilly
hughlilly / OpenRefine_FlickrGREL_extract_record_ID
Created April 15, 2020 10:24
Extract record IDs from Flickr exports using GREL in OpenRefine
substring(value, lastIndexOf(value, "record/")+7, lastIndexOf(value, "\" "))
@hughlilly
hughlilly / flickrapi_get.py
Created April 15, 2020 10:50
Get Flickr content and dump to JSON
import yaml
import requests
import json
import flickrapi
import webbrowser
from pprint import pprint as pp
config_file = 'auth.yaml'
with open(config_file, 'r') as config_file:
config = yaml.safe_load(config_file)
@hughlilly
hughlilly / AMChromeExtension.json
Last active April 19, 2020 08:33
Payload for Auckland Museum Google Chrome extension; data from Flickr
This file has been truncated, but you can view the full file.
{
"photos" : [
{
"title" : "Kari Mako [Korimako] Mahurangi N.Z.",
"img_url" : "https://live.staticflickr.com/65535/48753450128_7f7090bcbd_k.jpg",
"flickr_url" : "https://flickr.com/photos/182826961%40N04/48753450128",
"record_url" : "https://www.aucklandmuseum.com/collections-research/collections/record/am_library-paintinganddrawings-202",
"width" : 4000,
"height" : 6000,
"darkmode" : false