Skip to content

Instantly share code, notes, and snippets.

View delawaredata's full-sized avatar

The News Journal delawaredata

View GitHub Profile
@delawaredata
delawaredata / pools.py
Last active June 11, 2016 20:24
Altering mechanize to handle an ugly form.
import mechanize
import cookielib
from BeautifulSoup import BeautifulSoup
uri = "http://b3.caspio.com/dp.asp?appSession=718251683844642"
class PrettifyHandler(mechanize.BaseHandler):
"""
Shamelessly stolen from this stackoverflow answer:
http://stackoverflow.com/questions/1782368/is-it-possible-to-hook-up-a-more-robust-html-parser-to-python-mechanize/5039584#5039584
@delawaredata
delawaredata / DocumentCloudEmbed.js
Last active December 13, 2015 21:39
A script that turns DocumentCloud notes into popups on a website. It requires the jQuery and the qTip plugin, along with the DocumentCloud js script.
/*
To use, include jQuery, qTip plugin and DocumentCloud embed javascript.
The script looks for anchor tags with hrefs to DocumentCloud notes.
*/
$(document).ready(function(){
$('a[href^="https://www.documentcloud.org/"]').each(function(){
var myRE = /https:\/\/www\.documentcloud\.org\/documents\/(\d+).+\/a(\d+)/;
var embedIDs = myRE.exec($(this).attr('href'));
if (embedIDs.length === 3) {
$(this).click(function(event){
@delawaredata
delawaredata / LegislativeVotingRecords.py
Last active December 12, 2015 04:38
Script to convert tables of legislative votes in several MS Word documents into pipe-delimited documents.
import win32com.client as win32
from glob import glob
import re
# Grab all the .Doc files from these two
# directories so we can open them with win32.
house_files = glob("House/*.Doc")
senate_files = glob("Senate/*.Doc")
# File where we'll dump all of the output.
oFile = open("legVoting.txt", "w+")