Skip to content

Instantly share code, notes, and snippets.

@bsmithgall
bsmithgall / qgis_add_features.py
Last active September 4, 2015 04:32
Updating Feature Attributes in QGIS
# To avoid 'QVariant' is not defined error
from PyQt4.QtCore import *
import json
# Get all layers on the map's canvas
canvas = qgis.utils.iface.mapCanvas()
all_layers = canvas.layers()
# Make dictionary of election district features (individual
# districts) for inserting into spatial index
@bsmithgall
bsmithgall / get_members.py
Created February 5, 2014 05:42
Neighboring Districts with Metadata
# get congress members from govtrack api, parse for use in d3 topojson map
import requests
import json
GOVTRACK_MEMBER_LIST_URL = 'https://www.govtrack.us/api/v2/role?current=true&limit=541'
raw_data = requests.get(GOVTRACK_MEMBER_LIST_URL).json()
STATELOOKUP = {'AL': 1,'AK': 2,'AZ': 4,'AR': 5,'CA': 6,'CO': 8,'CT': 9,'DE': 10,'DC': 11,'FL': 12,'GA': 13,'HI': 15,'ID': 16,'IL': 17,'IN': 18,'IA': 19,'KS': 20,'KY': 21,'LA': 22,'ME': 23,'MD': 24,'MA': 25,'MI': 26,'MN': 27,'MS': 28,'MO': 29,'MT': 30,'NE': 31,'NV': 32,'NH': 33,'NJ': 34,'NM': 35,'NY': 36,'NC': 37,'ND': 38,'OH': 39,'OK': 40,'OR': 41,'PA': 42,'RI': 44,'SC': 45,'SD': 46,'TN': 47,'TX': 48,'UT': 49,'VT': 50,'VA': 51,'WA': 53,'WV': 54,'WI': 55,'WY': 56,'AS': 60,'FM': 64,'GU': 66,'MH': 68,'MP': 69,'PW': 70,'PR': 72,'UM': 74,'VI': 78}
import datetime
import requests
import json
BASE_URL = 'http://charts.spotify.com/api/charts/most_streamed/global/%s'
first_date = datetime.date(2013,04,28)
data = {}
for i in xrange(50):
@bsmithgall
bsmithgall / top_stations.R
Created November 22, 2013 05:47
Original version of top_stations.py from github.com/bsmithgall/citibike
library('RCurl')
library('RJSONIO')
library('igraph')
stations.url <- getURL('http://citibikenyc.com/stations/json')
dist.url <- getURL('appservices.citibikenyc.com/data2/stations.php')
# prep stations for kmeans clustering
stations.prep <- function(url) {
stations.json2 <- fromJSON(url, method='C')
@bsmithgall
bsmithgall / README.md
Created October 17, 2013 23:13
Congress