Skip to content

Instantly share code, notes, and snippets.

@quandyfactory
quandyfactory / parse_candidates.py
Created September 10, 2010 12:18
Turns a blob from the city of #HamOt's election page into a list of dictionaries.
def prepare(blob):
"""
Cleans up the City of Hamilton's blob of text from its candidates page and turns it into a list of dictionaries.
Here's the URL: http://www.hamilton.ca/CityDepartments/CorporateServices/Clerks/MunicipalElection/Nominated+Candidates.htm
"""
blobs = blob.split('\n# ')
wards = []
for blob in blobs:
title = blob.split('\n')[0]
@quandyfactory
quandyfactory / candidates.py
Created September 11, 2010 02:47
Turns the City of #HamOnt's election page blog into SQL insert queries.
#!/usr/bin/env python
def prepare(blob):
"""
Cleans up the City of Hamilton's blob of text from its candidates page and turns it into a list of dictionaries.
Here's the URL: http://www.hamilton.ca/CityDepartments/CorporateServices/Clerks/MunicipalElection/Nominated+Candidates.htm
We grabbed the source code for the candidates, minus the rest of the HTML boilerplate from the page, and added an octothorpe # before each ward heading to make the ward sections easier to parse.
"""
blobs = blob.split('\n# ')
@quandyfactory
quandyfactory / get_google_rank_for_candidates.py
Created October 5, 2010 14:38
Checks a list of names to determine whether they are in the top four Google search results.
import json
import urllib
import urllib2
candidates = ['David Sweet', 'James W. Byron', 'Brad Clark', 'Terry Anderson', 'Stephen E. Brotherston', 'Dave Braden', 'Annie Tennier', 'Michelle Stockwell', 'Marie Bountrogianni', 'Nancy MacBain', 'David Christopherson', 'Wayne Marston', 'Chris Charlton', 'Peter Ormond', 'Karen Burson', 'David Hart Dyke', 'Dean Allison', 'Stephen Henry Bieda', 'David Heatley', 'Bryan Jongbloed', 'Jim Enos', 'Michael James Baldasaro', 'Jamile Ghaddar', 'Anthony Giles', 'Lisa Nussey', 'Wendell Fields', 'Bob Green Innes', 'Bob Mann', 'Greg Pattinson', 'Henryk Adamiec', 'Sid Frere', 'Gord Hill']
url_template = 'http://ajax.googleapis.com/ajax/services/search/web?v=1.0&q={{q}}&key={{key}}&userip={{userip}}'
key = 'YOUR-GOOGLE-API-KEY'
referer = 'http://your.domain.com'
userip = '127.0.0.1'
@quandyfactory
quandyfactory / RTH_Elections_API_example.php
Created October 9, 2010 03:17
PHP example using the RTH Elections API.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>RTH Elections Site: Using JSON in PHP</title>
</head>
<body>
<h1>RTH Elections Site: Using JSON in PHP</h1>
<?php
$url = 'http://elections.raisethehammer.org/api/election/1';
@quandyfactory
quandyfactory / hamont_election_results.py
Created October 27, 2010 16:20
Nasty hack to get city of #HamOnt election data into a usable format.
#!/usr/bin/env python
"""
Grabs election data from the City of Hamilton's GEMS election data pages, converts it into a json object and an sql insert statement.
Yeah, I know: the code is seriously ugly-ass and inelegant. What the hell, it works.
Update: The City changed their election results pages and this script no longer works. I'm working on updating it.
Very Important Note: this code breaks on ward 14, where Rob Pasuta is acclaimed and there are no ward results on the web page.
Instead of fixing it in the code, for now I just fixed the SQL statement manually by removing the trustees from the results.
@quandyfactory
quandyfactory / Googlebeatbox.py
Created November 30, 2010 12:30
Google Beatbox UI.
#!/usr/bin/env python
__title__ = 'Google Beatbox GUI'
__version__ = 0.1
"""
This program provides a simple GUI interface to create Google Beatbox beats.
Original idea here: http://news.ycombinator.com/item?id=1952356
Drum Sounds defined: http://news.ycombinator.com/item?id=1952531
"""
@quandyfactory
quandyfactory / shorturl.py
Last active September 24, 2015 16:08
shorturl.py
import httplib2
try:
import json
except:
import simplejson as json
def short_url(long_url='http://raisethehammer.org')
"""
Takes a long URL and returns a short URL.
Uses the Google URL Shortener API: http://code.google.com/apis/urlshortener/
@quandyfactory
quandyfactory / crossing_guard_data.py
Created March 21, 2011 15:28
City Crossing Guard Data.
#!/usr/bin/env python
"""
This script contains functions that:
* convert tabular data from the City's crossing guards web page [1] into a nested list;
* use the Google Maps API to get geocoding data for each location; and
* convert the whole thing into an SQL insert statement.
[1] http://www.hamilton.ca/CityDepartments/PlanningEcDev/Divisions/ParkingBylawServices/SchoolCrossing/SchoolCrossingGuardLocations.htm
@quandyfactory
quandyfactory / gist:1154701
Created August 18, 2011 18:05
Sample JSON for Joey.
{"d":[
{"NameOfBeach":"Bayfront Beach","OpenClosed":"CLOSED","DateofSampling":"2011-08-17","Group":"Hamilton Harbour"},
{"NameOfBeach":"Pier 4 Beach","OpenClosed":"CLOSED","DateofSampling":"2011-08-17","Group":"Hamilton Harbour"},
{"NameOfBeach":"Binbrook Conservation","OpenClosed":"Open","DateofSampling":"2011-08-17","Region":"Conservation Authority Beaches"},
{"NameOfBeach":"Christie Conservation","OpenClosed":"Open","DateofSampling":"2011-08-17","Region":"Conservation Authority Beaches"},
{"NameOfBeach":"Valens Conservation","OpenClosed":"Open","DateofSampling":"2011-08-17","Region":"Conservation Authority Beaches"},
{"NameOfBeach":"Beach Boulevard","OpenClosed":"Open","DateofSampling":"2011-08-17","Region":"Lake Ontario"},
{"NameOfBeach":"Van Wagners","OpenClosed":"CLOSED","DateofSampling":"2011-08-17","Region":"Lake Ontario"},
{"NameOfBeach":"Confederation Park","OpenClosed":"Open","DateofSampling":"2011-08-17","Region":"Lake Ontario"}
]
@quandyfactory
quandyfactory / spark.py
Created November 16, 2011 01:06
My Python port of Zack Holman's spark shell script: https://github.com/holman/spark
# -*- coding: utf-8 -*-
"""My Python port of Zack Holman's spark shell script: https://github.com/holman/spark
This:
you@computer:~$ python spark.py 100 20 80 40 60
Should return this: