Skip to content

Instantly share code, notes, and snippets.

View bschoenfeld's full-sized avatar

Ben Schoenfeld bschoenfeld

  • Port Solution Integrators
  • Portsmouth, VA
View GitHub Profile
@bschoenfeld
bschoenfeld / BusCheckin.cs
Created April 3, 2012 14:30
A C# program that writes HRT FTP Data to CouchDB
using System;
namespace FTP_To_Couch
{
class BusDateTime
{
public int Year {get;set;}
public int Mon {get;set;}
public int Day {get;set;}
public int Hour {get;set;}
@bschoenfeld
bschoenfeld / GTFS.cs
Created November 18, 2012 02:59
HRT GTFS Processor
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
namespace gtfs
{
class MainClass
{
public static void Main (string[] args)
@bschoenfeld
bschoenfeld / gist:4405271
Created December 29, 2012 07:43
HRT Bus FTP Processor
from ftplib import FTP
from datetime import datetime, date, time, timedelta
from pymongo import Connection
class BusCheckin:
def __init__(self, data, year):
parts = data.split(',')
# checkin time
self.time = datetime.strptime(parts[0] + ' ' + parts[1] + '/' + year, "%H:%M:%S %m/%d/%Y")
from datetime import datetime, timedelta
from pymongo import Connection, GEO2D
class HRTDatabase:
def __init__(self, uri):
self.client = Connection(uri)
self.database = self.client.hrt
def insertStops(self, data, date):
collectionName = self.genCollectionName('stops_', date)
--- C:/Users/BSCHOE~1/AppData/Local/Temp/underscore.js-revBASE.svn000.tmp.js Tue Mar 5 11:30:16 2013
+++ C:/bschoenfeld/OPs_Service_Bus/VIT.NIT.OPS.HatchChecker/WebServer/Scripts/underscore.js Tue Mar 5 11:48:58 2013
@@ -238,7 +238,7 @@
// Convenience version of a common use case of `filter`: selecting only objects
// containing specific `key:value` pairs.
_.where = function(obj, attrs, first) {
- if (_.isEmpty(attrs)) return first ? void 0 : [];
+ if (_.isEmpty(attrs)) return first ? null : [];
return _[first ? 'find' : 'filter'](obj, function(value) {
for (var key in attrs) {
@bschoenfeld
bschoenfeld / data.json
Created November 14, 2014 17:39
Health Inspection Data for Heatmap
This file has been truncated, but you can view the full file.
[{"lat": 36.77721, "count": 100, "lng": -77.87301}, {"lat": 36.80509, "count": 99, "lng": -78.94802}, {"lat": 36.99772, "count": 100, "lng": -79.04197}, {"lat": 36.67743, "count": 97, "lng": -78.9196}, {"lat": 36.735, "count": 86, "lng": -78.91515}, {"lat": 36.76143, "count": 100, "lng": -78.76973}, {"lat": 36.69857, "count": 100, "lng": -78.92031}, {"lat": 36.70611, "count": 95, "lng": -78.94777}, {"lat": 36.67466, "count": 90, "lng": -78.92763}, {"lat": 36.735, "count": 95, "lng": -78.91515}, {"lat": 36.70478, "count": 94, "lng": -78.89878}, {"lat": 36.56512, "count": 100, "lng": -79.1404}, {"lat": 36.68801, "count": 100, "lng": -78.8965}, {"lat": 36.73745, "count": 98, "lng": -78.91978}, {"lat": 36.69708, "count": 91, "lng": -78.90118}, {"lat": 36.94173, "count": 94, "lng": -78.75275}, {"lat": 36.72836, "count": 96, "lng": -79.13531}, {"lat": 36.73383, "count": 100, "lng": -78.88802}, {"lat": 36.71382, "count": 100, "lng": -78.91707}, {"lat": 37.03008, "count": 78, "lng": -78.95301}, {"lat": 36.70086, "cou
@bschoenfeld
bschoenfeld / courts.py
Created November 14, 2014 20:37
VA Circuit Court Search
from bs4 import BeautifulSoup
import scraperwiki
import cookielib, urllib, urllib2
import sys
def getNames(html, name):
for row in html.find(class_="nameList").find_all('tr'):
cols = row.find_all('td')
if len(cols) > 4:
if name not in cols[1].string:
import urllib2
from bs4 import BeautifulSoup
# get the web page
url = "http://healthspace.com/Clients/VDH/NewRiver/web.nsf/module_facilities.xsp?module=Food"
web_page = urllib2.urlopen(url)
web_page_html = web_page.read()
# write the web page to a file
# google "python write to file"
def load_traffic_data():
traffic = {}
with open('data/traffic_daily_vehicle_miles_traveled_2015.csv') as f:
reader = csv.DictReader(f)
for row in reader:
if row['District Court FIPS Codes'] == '':
continue
if row['District Court FIPS Codes'] not in traffic:
# Some district courts are represented in the traffic data
# by mulitple localities. So instead of just loading the traffic
[
{
"locality": ["Newport News"],
"fips": [701, 702, 703],
"all": 4365476,
"chargeCount": 100000
},
...
]