def import_hw_metrics(metrics_type='daily', from_date=None, to_date=None): "import metrics from Highwire between the two given dates or from inception" assert metrics_type in ['daily', 'monthly'], 'metrics type must be either "daily" or "monthly"' if not from_date: # HW metrics go back further than GA metrics from_date = hw_metrics.INCEPTION if not to_date: to_date = datetime.now() def create_hw_row(data): "wrangles the data into something that can be inserted directly" data['digest'] = 0 data['source'] = models.HW return insert_row(data) # not going to be delicate about this. just import all we can find. results = hw_metrics.metrics_between(from_date, to_date, metrics_type) for dt, items in results.items(): map(create_hw_row, items)
def test_metrics_between(self): start_date = datetime(year=2014, month=1, day=1) end_date = datetime(year=2014, month=1, day=1) results = core.metrics_between(start_date, end_date, 'daily') # same day expected_results = OrderedDict([]) # we have no daily metrics for this time range self.assertEqual(results, expected_results)