Skip to content

Instantly share code, notes, and snippets.

View garrettdashnelson's full-sized avatar
💭
Oh, you know, just typing on the computer

Garrett Dash Nelson garrettdashnelson

💭
Oh, you know, just typing on the computer
View GitHub Profile
@garrettdashnelson
garrettdashnelson / gist:98bbf055b2e0f0756605
Created July 16, 2015 17:09
Scrape call numbers for charged items from UW library account management page
from bs4 import BeautifulSoup
charged = open("charged.html","r")
soup = BeautifulSoup(charged, 'html.parser')
results = soup.find_all(class_="callnum")
n = []
@garrettdashnelson
garrettdashnelson / puller.html
Last active February 23, 2016 18:27
Neotoma API pulls using jQuery
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<script>
var ajaxOpts = {
dataType:"jsonp",
url:"http://api.neotomadb.org/v1/data/sites",
data:{"loc":"-93.0546875,44.36209301204985,-89.0546875,48.36209301204985"},
success: logger
}
'''
This is operating on a SQLite file which was generated using the following command to filter out entries with the same origin and destination
ogr2ogr -f SQLite -sql "SELECT * FROM usa_ttw_master WHERE NOT (O_STATEFP = D_STATEFP AND O_COUNTYFP = D_COUNTYFP AND O_TRACTCE = D_TRACTCE)" commutes_without_sameorigins.sqlite *.shp
The result of that command is a database with 4080575 entries. The original Shapefile had 4156426 entries, so 75851 same-origin entries were filtered out.
'''
from __future__ import print_function
@garrettdashnelson
garrettdashnelson / bib-titlecase.py
Last active April 25, 2024 13:35
Convert titles in bibtex citation library to title case
# Original by Daniel L. Greenwald
# http://dlgreenwald.weebly.com/blog/capitalizing-titles-in-bibtex
# Modified by Garrett Dash Nelson
import re
from titlecase import titlecase
# Input and output files
my_file = 'library.bibtex'
new_file = 'library-capitalized.bibtex' # in case you don't want to overwrite
@garrettdashnelson
garrettdashnelson / scraper.py
Created September 8, 2017 14:42
Scraper for VGSI-style property tax database
from bs4 import BeautifulSoup
import urllib2
import re
from string import ascii_uppercase, replace
with open('results.tsv','w') as outfile:
for letter in ascii_uppercase:
geoid town state <25000 25000-49999 50000-99999 100000-199999 200000>
3300933860 Hanover 33 366 229 694 821 759
3300941300 Lebanon 33 1183 1539 2120 1170 313
5002752900 Norwich 50 145 183 274 450 275
3300924340 Enfield 33 154 590 551 484 257
5002732275 Hartford 50 787 905 1588 868 192
3300944260 Lyme 33 36 98 153 203 184
5002785975 Woodstock 50 147 271 521 256 181
3301931220 Grantham 33 39 186 349 423 132
3301352100 New London 33 266 287 450 558 117
{"nodes": [{"name": "Inner Hanover NH"}, {"name": "Groton-Ryegate-Peacham VT"}, {"name": "Rockingham VT"}, {"name": "Enfield NH"}, {"name": "Haverhill NH"}, {"name": "Danbury-Wilmot-Hill NH"}, {"name": "Hartford North of the White River VT"}, {"name": "Lebanon North of Route 4 NH"}, {"name": "Windsor VT"}, {"name": "Lebanon South of Route 4 NH"}, {"name": "Royalton VT"}, {"name": "Springfield Northeast VT"}, {"name": "Outer Hanover NH"}, {"name": "Norwich VT"}, {"name": "Piermont-Orford-Wentworth NH"}, {"name": "Weathersfield VT"}, {"name": "New London NH"}, {"name": "Hartland VT"}, {"name": "Randolph VT"}, {"name": "Newbury VT"}, {"name": "Chelsea-Vershire-Tunbridge-Strafford VT"}, {"name": "Walpole NH"}, {"name": "Bradford VT"}, {"name": "Unity-Acworth-Langdon NH"}, {"name": "Bellows Falls VT"}, {"name": "Charlestown NH"}, {"name": "Claremont Southwest NH"}, {"name": "Claremont Southeast NH"}, {"name": "Plainfield-Cornish NH"}, {"name": "Grantham-Croydon-Springfield NH"}, {"name": "Orange-Washington VT"}, {
@garrettdashnelson
garrettdashnelson / bending-lines.json
Created August 23, 2019 19:15
bending-lines.json
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
<!DOCTYPE html>
<meta charset="utf-8">
<style>
body {
background: #fcfcfa;
height: 500px;
position: relative;
width: 960px;
}
import requests
from bs4 import BeautifulSoup
barcode = "39999059010775"
r = requests.get('https://collections.leventhalmap.org/search?page=1&per_page=100&q={}'.format(barcode))
htmlSource = BeautifulSoup(r.text, "html.parser")
for d in htmlSource.find_all("div", class_="document"):