def print_crawls(age=datetime.timedelta(hours=2), sleep=15, limit=None):
    """Script for displaying latest crawls and their details."""

    header = [
        '-----------------------------------------------------------',
        'Time           | mins  | avail | down  | objs  | missing % ',
        '-----------------------------------------------------------',
    ]
    while True:
        crawls = Crawl.objects.filter(start_time__gt=now() - age
            ).order_by('start_time')
        if limit:
            crawls = crawls[:limit]

        to_print = list(header)

        lencrawls = len(crawls)
        for i, c in enumerate(crawls):
            dev = 'error'
            disp = 'error'
            if (c.groups_available > 0 and c.groups_downloaded is not None):
                dev = float(c.groups_downloaded) / c.groups_available
                th = settings.INCOMPLETE_CRAWL_WARNING_THRESHOLD
                disp = int((1 - dev) * 100)
                if c.groups_available == c.groups_downloaded:
                    if i != lencrawls - 1:
                        # if it's not the latest it can't be running
                        disp = 'crashed'
                    else:
                        disp = 'running'
                else:
                    disp = '{0}%'.format(disp) + (' err' if dev < th else '')
            if c.end_time == c.start_time:
                end_time = now()
            else:
                end_time = c.end_time
            elapsed = round(
                float((end_time - c.start_time).total_seconds()) / 60, 1)
            to_display = [
                c.start_time.strftime('%y-%m-%d %H:%M'),
                pad_string(elapsed, 5),
                pad_string(c.groups_available, 5),
                pad_string(c.groups_downloaded, 5),
                pad_string(c.hitgroupstatus_set.count(), 5),
                disp,
            ]
            to_print.append(' | '.join(map(str, to_display)))
        for r in to_print:
            print r
        time.sleep(sleep)
dataset/ETHPy150Open ipeirotis/Mturk-Tracker/app/mturk/main/monitoring.py/print_crawls/original