def main(): parser = argparse.ArgumentParser() parser.add_argument("--output", "-o") args = parser.parse_args() delivery = TestDelivery() logger = get_logger(args.output) my_print = logger.info created_times = TimeTrial.objects.filter(created_time__gte=datetime.date(2016, 2, 19)) created_times = created_times.values_list("created_time", flat=True) created_times = sorted(created_times) created_times = [min(t) for _, t in itertools.groupby(created_times, key=lambda dt: dt.date())] my_print("%s", created_times) sec = datetime.timedelta(seconds=1) state = None for t in created_times: stop = t + datetime.timedelta(days=1) stop = stop.replace(hour=0, minute=0, second=0) t = t - 7 * sec while t < stop: qs = PastTimeTrialQuerySet(t) delivery.now = t try: events = get_current_events(qs, t) state = update_report(delivery, state, events, logger) except TryAgainShortly as e: my_print("%s: %s", t, e) t += datetime.timedelta(seconds=e.suggested_wait + 1) continue t += 15 * sec
def main(): qs = TimeTrial.objects.all() delivery = FacebookDelivery() events = get_current_events(qs) state = None state = update_report(delivery, state, events, logger) while True: try: events = get_current_events(qs.all()) state = update_report(delivery, state, events, logger) except TryAgainShortly as e: logger.debug("Try again in %s", e.suggested_wait) time.sleep(e.suggested_wait) continue time.sleep(15)
def main(): ensure_valid_api_version() qs = TimeTrial.objects.all() delivery = FacebookDelivery() events = get_current_events(qs) state = None state = update_report(delivery, state, events, logger) while True: try: events = get_current_events(qs.all()) state = update_report(delivery, state, events, logger) except TryAgainShortly as e: logger.debug("Try again in %s", e.suggested_wait) time.sleep(e.suggested_wait) continue # Close connection before sleeping # https://code.djangoproject.com/ticket/21597#comment:29 django.db.connection.close() time.sleep(15)
def main(): parser = argparse.ArgumentParser() parser.add_argument('--output', '-o') args = parser.parse_args() delivery = TestDelivery() logger = get_logger(args.output) my_print = logger.info created_times = TimeTrial.objects.filter( created_time__gte=datetime.date(2016, 2, 19)) created_times = created_times.values_list('created_time', flat=True) created_times = sorted(created_times) created_times = [ min(t) for _, t in itertools.groupby(created_times, key=lambda dt: dt.date()) ] my_print("%s", created_times) sec = datetime.timedelta(seconds=1) state = None for t in created_times: stop = t + datetime.timedelta(days=1) stop = stop.replace(hour=0, minute=0, second=0) t = t - 7 * sec while t < stop: qs = PastTimeTrialQuerySet(t) delivery.now = t try: events = get_current_events(qs, t) state = update_report(delivery, state, events, logger) except TryAgainShortly as e: my_print("%s: %s", t, e) t += datetime.timedelta(seconds=e.suggested_wait + 1) continue t += 15 * sec