mod9-py3fstasks/main.py
def fetch_visits(limit):
    'get most recent visits & add task to delete older visits'
    visits_ref = fs_client.collection('Visit')
    visits = list(v.to_dict() for v in visits_ref.order_by('timestamp',
            direction=firestore.Query.DESCENDING).limit(limit).stream())
    oldest = time.mktime(visits[-1]['timestamp'].timetuple())
    oldest_str = time.ctime(oldest)
    print('Delete entities older than %s' % oldest_str)
    task = {
        'app_engine_http_request': {
            'relative_uri': '/trim',
            'body': json.dumps({'oldest': oldest}).encode(),
            'headers': {
                'Content-Type': 'application/json',
            },
        }
    }
    if _create_queue_if():
        ts_client.create_task(parent=QUEUE_PATH, task=task)
    return visits, oldest_str
get most recent visits & add task to delete older visits
get most recent visits & add task to delete older visits
get most recent visits & add task to delete older visits
def fetch_visits(limit):
    visits_ref = fs_client.collection('Visit')
    visits = list(v.to_dict() for v in visits_ref.order_by('timestamp',
            direction=firestore.Query.DESCENDING).limit(limit).stream())
    oldest = time.mktime(visits[-1]['timestamp'].timetuple())
    oldest_str = time.ctime(oldest)
    print('Delete entities older than %s' % oldest_str)
    task = {
        'app_engine_http_request': {
            'relative_uri': '/trim',
            'body': json.dumps({'oldest': oldest}).encode(),
            'headers': {
                'Content-Type': 'application/json',
            },
        }
    }
    if _create_queue_if():
        ts_client.create_task(parent=QUEUE_PATH, task=task)
    return visits, oldest_str
def fetch_visits ( limit ) : visits_ref = fs_client . collection ( 'Visit' ) visits = list ( v . to_dict ( ) for v in visits_ref . order_by ( 'timestamp' , direction = firestore . Query . DESCENDING ) . limit ( limit ) . stream ( ) ) oldest = time . mktime ( visits [ - 1 ] [ 'timestamp' ] . timetuple ( ) ) oldest_str = time . ctime ( oldest ) print ( 'Delete entities older than %s' % oldest_str ) task = { 'app_engine_http_request' : { 'relative_uri' : '/trim' , 'body' : json . dumps ( { 'oldest' : oldest } ) . encode ( ) , 'headers' : { 'Content-Type' : 'application/json' , } , } } if _create_queue_if ( ) : ts_client . create_task ( parent = QUEUE_PATH , task = task ) return visits , oldest_str
get most recent visits & add task to delete older visits
get most recent visits & add task to delete older visits
'get most recent visits & add task to delete older visits'
limit