@pypi_packages.route('/sync')
def sync():
    if redis.exists(POLL_SIMPLE_THROTTLE):
        flash.warning('Already sycned once within the past hour. Not syncing until lock expires.')
        return redirect(url_for('.index'))

    # Schedule the task.
    task = update_package_list.delay()  # Schedule the task to execute ASAP.

    # Attempt to obtain the results.
    for _ in range(int(WAIT_UP_TO / SLEEP_FOR)):
        time.sleep(SLEEP_FOR)
        if not task.ready():
            continue  # Task is still running.
        results = task.get(propagate=False)

        if isinstance(results, Exception):
            # The task crashed probably because of a bug in the code.
            if str(results) == 'Failed to acquire lock.':
                # Never mind, no bug. The task was probably running from Celery Beat when the user tried to run a second
                # instance of the same task.
                # Since the user is expecting this task to update the database, we'll tell them that results should be
                # updated within the minute, since the previously-running task should finish shortly.
                flash.info('Task scheduled, any new packages will appear within 1 minute.')
                return redirect(url_for('.index'))
            raise results  # HTTP 500.

        if not results:
            flash.info('No new packages found.')
            return redirect(url_for('.index'))

        if len(results) < 5:
            flash.info('New packages: {}'.format(', '.join(results)))
        else:
            flash.modal('New packages found:\n{}'.format(', '.join(results)))
        return redirect(url_for('.index'))

    # If we get here, the timeout has expired and the task is still running.
    flash.info('Task scheduled, any new packages will appear within 15 minutes.')
    return redirect(url_for('.index'))
Take a sqlite filled database of results and return a csv file
dataset/ETHPy150Open Robpol86/Flask-Large-Application-Example/pypi_portal/views/pypi/packages.py/sync--crossover with--dataset/ETHPy150Open TheGhouls/oct/oct/tools/results_to_csv.py/to_csv