Skip to content

Commit

Permalink
- Add convenience handler for importing data from http://archive.luft…
Browse files Browse the repository at this point in the history
…daten.info/

- Fix CSV import exception handling
  • Loading branch information
amotl committed Mar 28, 2017
1 parent 8e13806 commit 4925694
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
8 changes: 8 additions & 0 deletions CHANGES.rst
Expand Up @@ -7,6 +7,14 @@ in progress
===========


.. _kotori-0.15.0:

2017-03-29 0.15.0
=================
- Add convenience handler for importing data from http://archive.luftdaten.info/
- Fix CSV import exception handling


.. _kotori-0.14.3:

2017-03-22 0.14.3
Expand Down
13 changes: 10 additions & 3 deletions kotori/io/protocol/http.py
Expand Up @@ -340,7 +340,13 @@ def parse_header(channel_info, data_lines):
data_lines.pop(0)
options['rules'] = [{'type': 'fuse', 'source': ['Datum', 'Uhrzeit'], 'target': 'time', 'join': 'T', 'suffix': 'Z'}]

# Convenience hack to support import from http://archive.luftdaten.info/
elif first_line.startswith('sensor_id'):
header_line = first_line
data_lines.pop(0)

if header_line:
# Streamline various differences for even more convenience
header_line = header_line.replace(';', ',').replace('Date/Time', 'time').replace('Datum/Zeit', 'time').replace('timestamp', 'time')
header_fields = map(str.strip, header_line.split(','))
msg = u'CSV Header: fields={fields}, key={key}'.format(fields=header_fields, key=request.channel_identifier)
Expand Down Expand Up @@ -384,11 +390,12 @@ def parse_data(channel_info):

try:
channel_info = csv_header_store.find_one(filter={"channel": request.channel_identifier})
return parse_data(channel_info)
except Exception as ex:
log.failure('Could not process CSV data, database error: {0}'.format(ex))
log.failure('Could not process CSV data, unknown database error: {0}'.format(ex))
raise Error(http.INTERNAL_SERVER_ERROR,
response='Could not process CSV data, database error: {0}'.format(ex))
response='Could not process CSV data, unknown database error: {0}'.format(ex))

return parse_data(channel_info)

else:
msg = u"Unable to handle Content-Type '{content_type}'".format(content_type=content_type)
Expand Down

0 comments on commit 4925694

Please sign in to comment.