Skip to content

Instantly share code, notes, and snippets.

@wardi
Created May 10, 2017 18:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wardi/37e1d9922113a3252071665cda19b0b6 to your computer and use it in GitHub Desktop.
Save wardi/37e1d9922113a3252071665cda19b0b6 to your computer and use it in GitHub Desktop.
Download and strip newlines and double quotes from OD inventory dataset
#!/usr/bin/env python2
import requests
import csv
URL = 'http://open.canada.ca/data/dataset/4ed351cf-95d8-4c10-97ac-6b3511f359b7/resource/d0df95a8-31a9-46c9-853b-6952819ec7b4/download/inventory.csv'
OUTPUT = 'inventory-stripped.csv'
r = requests.get(URL, stream=True)
out = csv.writer(open(OUTPUT, 'wb'))
for row in csv.reader(r.raw):
out.writerow([
c.replace('\n', '').replace('\r', '').replace('"', '')
for c in row])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment