Sunday, 7 December 2014

Creating and appending csv files



I am working on my first python project and am in over my head. I am trying to collect bike share data from an xml feed.


I want to capture this data every n minutes, lets say 5 for now, then create a csv file of that data. Additionally I want to create a second file that appends the first file so I have a historical database. The headers in the csv are: [ "id", "name", "terminalName", "lastCommWithServer", "lat", "long", "installed", "locked", "installDate", "removalDate", "temporary", "public", "nbBikes", "nbEmptyDocks", "latestUpdateTime" ] I made a start but I'm not going no where slowly! Any help would be appreciated.


This is what I have but the csv writing is a mess.



import urllib
import csv

url = 'http://ift.tt/13zT9Qg'
connection = urllib.urlopen(url)
data = connection.read()

with open('statuslog.csv', 'wb') as myfile:
wr = csv.writer(myfile, quoting=csv.QUOTE_ALL)
wr.writerow(data)

No comments:

Post a Comment