Thank you all so very much!
I would never have found a solution without your help.
The following does what I wanted, almost. Instead of printing the rows, I need the data in an array. But maybe reader is an array of strings that I can parse.
More difficult to solve, the sparkfun website is very overloaded and often returns a 503 error and fails. It would be nice to have the software display a message, wait a little, then try again. But maybe the easiest fix is to just run my own server that isn't so busy.
# Download and display csv data from rain gauge from contextlib import closing import csv, io, requests, urllib.request, codecs from contextlib import closing url = 'http://data.sparkfun.com/output/YGa69ObX6WFj9mYa4EmW.csv?page=1' with closing(requests.get(url, stream=True)) as r: reader = csv.reader(codecs.iterdecode(r.iter_lines(), 'utf-8')) for row in reader: print (row) ```
Trying a different variation
import csv, io, requests, urllib.request url = 'http://data.sparkfun.com/output/YGa69ObX6WFj9mYa4EmW.csv?page=1' in_file=urllib.request.urlopen(url, data=None) for row in csv.reader(in_file): print(', '.join(row))
I got the error:
line 9, in <module>
for row in csv.reader(in_file):
_csv.Error: iterator should return strings, not bytes (did you open the file in text mode?)
I still am not getting the URL connected to the file properly. In the following, I get the error urlopen not defined, though request.py illustrates it explicitly, and changing requests to request doesn't help: (I don't have a zip file to deal with, so can't follow the linked example directly):
import csv, io, requests url = 'http://data.sparkfun.com/output/YGa69ObX6WFj9mYa4EmW.csv?page=1' with urlopen(url, data=None) as in_file: for row in csv.reader(in_file): print(', '.join(row))
(Noob) I have a URL for an internet of things data log of my rainfall. If I open it in a browser, it displays like a 3-column spreadsheet.
I'd like to get the data into an array so I can process a summary into another array, which I would then plot.
The URL examples I've found so far don't seem to relate to reading data.
Can someone point me in a useful direction? Perhaps there's an example that does something similar?