@cronjobs.register
def update_visitors_metric():
 if settings.STAGE:
  return
 latest_metric = _get_latest_metric(VISITORS_METRIC_CODE)
 if (latest_metric is not None):
  latest_metric_date = latest_metric.start
 else:
  latest_metric_date = date(2011, 1, 1)
 start = (latest_metric_date + timedelta(days=1))
 end = (date.today() - timedelta(days=1))
 visitors = googleanalytics.visitors(start, end)
 metric_kind = MetricKind.objects.get(code=VISITORS_METRIC_CODE)
 for (date_str, visits) in visitors.items():
  day = datetime.strptime(date_str, '%Y-%m-%d').date()
  Metric.objects.create(kind=metric_kind, start=day, end=(day + timedelta(days=1)), value=visits)

@ cronjobs . register def update_visitors_metric ( ) : if settings . STAGE : return latest_metric = _get_latest_metric ( VISITORS_METRIC_CODE ) if ( latest_metric is not None ) : latest_metric_date = latest_metric . start else : latest_metric_date = date ( 2011 , 1 , 1 ) start = ( latest_metric_date + timedelta ( days = 1 ) ) end = ( date . today ( ) - timedelta ( days = 1 ) ) visitors = googleanalytics . visitors ( start , end ) metric_kind = MetricKind . objects . get ( code = VISITORS_METRIC_CODE ) for ( date_str , visits ) in visitors . items ( ) : day = datetime . strptime ( date_str , '%Y-%m-%d' ) . date ( ) Metric . objects . create ( kind = metric_kind , start = day , end = ( day + timedelta ( days = 1 ) ) , value = visits )
get new visitor data from google analytics and save .