Skip to content

Commit

Permalink
Merge pull request #7 from danielrichman/master
Browse files Browse the repository at this point in the history
Use immortal changes and take time from time_created if not specified
  • Loading branch information
adamgreig committed Aug 21, 2012
2 parents 7b7846a + c8f1a0a commit 6de7fc4
Showing 1 changed file with 18 additions and 11 deletions.
29 changes: 18 additions & 11 deletions habitat_transition/spacenearus.py
Expand Up @@ -28,6 +28,8 @@
import Queue
import copy
import json
import time
from habitat.utils import rfc3339, immortal_changes

__all__ = ["SpaceNearUs"]
logger = logging.getLogger("habitat_transition.spacenearus")
Expand Down Expand Up @@ -62,7 +64,7 @@ def run(self):

update_seq = self.db.info()["update_seq"]

consumer = couchdbkit.Consumer(self.db)
consumer = immortal_changes.Consumer(self.db)
consumer.wait(self.couch_callback, filter="habitat/spacenear",
since=update_seq, heartbeat=1000, include_docs=True)

Expand Down Expand Up @@ -185,7 +187,7 @@ def listener_telemetry(self, doc):
params = {}

self._copy_fields(fields, data, params)
self._handle_time(data, params)
self._handle_time(data, params, doc["time_created"])

params["pass"] = "aurora"
self.upload_queue.put(params)
Expand Down Expand Up @@ -217,15 +219,20 @@ def _copy_fields(self, fields, data, params):
except KeyError:
continue

def _handle_time(self, data, params):
try:
if isinstance(data["time"], dict):
timestr = "{hour:02d}{minute:02d}{second:02d}"
params["time"] = timestr.format(**data["time"])
else:
params["time"] = data["time"].replace(":", "")
except KeyError:
pass
def _handle_time(self, data, params, time_created=None):
if "time" not in data and time_created is None:
logger.warning("No time on doc")
return

if "time" not in data:
created = rfc3339.rfc3339_to_timestamp(time_created)
timestr = time.strftime("%H%M%S", time.gmtime(created))
params["time"] = timestr
elif isinstance(data["time"], dict):
timestr = "{hour:02d}{minute:02d}{second:02d}"
params["time"] = timestr.format(**data["time"])
else:
params["time"] = data["time"].replace(":", "")

def _post_to_track(self, params):
qs = urlencode(params, True)
Expand Down

0 comments on commit 6de7fc4

Please sign in to comment.