ausecocloud / ecocloud

Issue tracker
6 stars 0 forks source link

Improve snippets so they work with different formats #33

Open hoylen opened 6 years ago

hoylen commented 6 years ago

The current snippet works with text files (e.g. CSV):

import urllib.request
url = 'http://www.nemweb.com.au/mms.GRAPHS/GRAPHS/GRAPH_5QLD1.csv'
data = urllib.request.urlopen(url).read().decode('utf-8')

But fails for other formats (e.g. XLSX, XLS), since it tries to interpret the binary data as UTF-8 encoded text and fails. That is, the above code produces an error.

This starts getting into the slippery slope of having different snippets for different types of files. Not to mention, what can a user do with an Excel file they have downloaded?

Perhaps an easy interim solution is to remove the .decode('utf-8') and let the user figure out what they need to do with the binary data they have downloaded. For example, if it is CSV they will have to realise they need to convert the Python binary string into a normal string. Not a great solution, but at least the code will download something and not immediately fail on them.

manhinli commented 6 years ago

Will remove the decoding stage from the Python snippet.