Skip to content

Instantly share code, notes, and snippets.

View cjwinchester's full-sized avatar
💭
🤌

Cody Winchester cjwinchester

💭
🤌
View GitHub Profile
@cjwinchester
cjwinchester / county_adjacency.py
Last active November 24, 2021 18:22
Two Python functions -- one to return a dictionary of U.S. county FIPS codes, another to return a JSON array of objects of county adjacency data.
import requests
import csv
import json
def getCounties():
"Function to return a dict of FIPS codes (keys) of U.S. counties (values)"
d = {}
r = requests.get("http://www2.census.gov/geo/docs/reference/codes/files/national_county.txt")
reader = csv.reader(r.text.splitlines(), delimiter=',')
for line in reader:
@cjwinchester
cjwinchester / goat-giffer.sh
Created November 29, 2015 04:42
Use ffmpeg and imagemagick to convert a (sideways) mp4 video into a gif.
mkdir -p goat && ffmpeg -i goat.mp4 -vf "transpose=1" -r 10 goat/goat%03d.png && convert -resize 50% -delay 5 -loop 0 goat/goat*.png goat.gif
"""
Unpacking a list of tuples to test for multiple replacement values. (Borrowed from a code snippet in "Mining the Social Web": http://shop.oreilly.com/product/0636920030195.do)
"""
REPLACE_LIST = [
(', Incorporated',', Inc.'),
(' Incorporated',' Inc.'),
(', LLC',''),
@cjwinchester
cjwinchester / domains.py
Last active November 4, 2015 04:55
A Python script to fetch a current list of top-level domains from IANA.
import requests
import json
def getDomainList():
url = "http://data.iana.org/TLD/tlds-alpha-by-domain.txt"
r = requests.get(url)
s = r.text.split("\n")
date = s[0].split("Last Updated ")[1]
js = {}
@cjwinchester
cjwinchester / ne-babies.sh
Created October 7, 2015 05:06
Fetch Nebraska baby name data file from the Social Security Administration (1910-present), convert to JSON.
#!/bin/bash
wget http://www.ssa.gov/oact/babynames/state/namesbystate.zip -O baby_names_by_state.zip
unzip baby_names_by_state.zip NE.TXT
sed -e '1i\state,sex,year,name,count' NE.TXT | csvcut -c sex,year,name,count | csvjson > ne-babies.json
rm NE.TXT baby_names_by_state.zip
@cjwinchester
cjwinchester / place_getter.sh
Created September 6, 2015 08:46
Download, unzip and parse Census TIGER files for U.S. places, return a pipe-delimited text file with lat/lng.
#!/bin/bash
wget -O fips_ref.txt http://www2.census.gov/geo/docs/reference/state.txt
wget --mirror --continue --no-directories ftp://ftp2.census.gov/geo/tiger/TIGER2015/PLACE/
for f in *.zip
do
unzip $f
done
@cjwinchester
cjwinchester / ne-auditor-budget-dump.py
Last active August 29, 2015 14:27
Programatic-ish access to budget summary data for every Nebraska political subdivision, transposed or jsonified into something a human can use.
"""
Pings the Nebraska Auditor of Public Accounts' budget database -- http://www.nebraska.gov/auditor/reports/index.cgi?budget=1 -- and returns a cleaner, transposed csv (or JSON) of summary budget data for every political subdivision in Nebraska.
~~ ARGUMENTS ~~
outfile: name of file to write to
delimit: delimiter for outfile, or pass "json" to return JSON
budget_year_list: list of budget years you want to grab data for, in the form ["2013-2014", "2014-2015"]
"""
@cjwinchester
cjwinchester / dougwarrants.py
Created August 10, 2015 21:25
Douglas County Sheriff warrant scraper
import requests
from bs4 import *
from time import *
import re
from string import ascii_lowercase
f = open('dougwarrants.txt', 'wb')
baseurl = "http://omahasheriff.com/services/warrants/criminal?searchterm="
for letter in ascii_lowercase:
@cjwinchester
cjwinchester / cia-flag-gif-scraper.py
Last active August 29, 2015 14:26
Scrape/download CIA "flags of the world," plus JSON to convert b/t ISO 3166-1 alpha-two and alpha-three country codes
import requests
from bs4 import *
import time
import json
import os
import glob
# download flag gifs from CIA website
def getFlags():
base = "https://www.cia.gov/library/publications/the-world-factbook/docs/flagsoftheworld.html"
@cjwinchester
cjwinchester / gis.py
Created July 20, 2015 03:14
gis depository thinger
import os
import json
import re
import collections
def sub(text):
return re.sub("ia-|ne-|us-|-topojson|-geojson|.json|.zip", "", text)
def getType(x):
if "topojson" in x: