Snippets

Patrick Kaeding How to get a low-numbered username for your kid in the SF public library online system: http://kaed.in/GH5mn

Created by Patrick Kaeding
import requests

def check_username(color, animal):
  url = "https://sfpl.bibliocommons.com/user/generate_username.json?color={}&animal={}".format(color, animal)
  req = requests.get(url)
  resp = req.json()
  name = resp.get('user_name')
  if name:
    return int(name.replace('{}_{}_'.format(color, animal), ''))
  else:
    print "No username from url: ", url
    return None

colors = ["red", "green", "blue", "yellow", "taupe", "mauve", "burgundy", "violet", "maroon", "orange", "indigo", "navy", "olive", "brown", "black", "white"]
animals = ["alligator","ant","antelope","ape","baboon","badger","bat","bear","beaver","bee","beetle","bird","bison","buffalo","butterfly","buzzard","camel","cat","cattle","chamois","cheetah","chicken","cobra","cockroach","cormorant","coyote","crab","crane","crocodile","crow","deer","dog","dogfish","dolphin","donkey","dove","duck","eagle","eel","elephant","elk","falcon","ferret","finch","fish","flamingo","fox","frog","gazelle","gerbil","giraffe","goat","goldfinch","goose","gorilla","guanaco","gull","hamster","hare","hawk","heron","hippo","hog","hornet","horse","human","hummingbird","hyena","jackal","jaguar","jay","jellyfish","kangaroo","ladybug","lark","leopard","lion","llama","lobster","louse","magpie","mallard","manatee","mink","mole","monkey","moose","mosquito","mouse","mule","nightingale","ostrich","otter","owl","ox","oyster","panda","panther","parrot","partridge","peafowl","pelican","penguin","pheasant","pig","pigeon","polecat","pony","porcupine","quail","rabbit","raccoon","rail","ram","rat","raven","reindeer","rhino","rook","seastar","pineped","shark","sheep","skunk","snake","snipe","sparrow","spider","squirrel","swallow","swan","tiger","toad","turkey","turtle","weasel","whale","wildfowl","wolf","wombat","worm","wren","yak","zebra","zebu"]


for c in colors:
  for a in animals:
    num = check_username(c, a)
    if num is not None and num < 3:
      print c, a, num

Comments (0)