

def post(self):
    '.'
    logging.info('tasks/new_gplus')
    gplus_id = self.request.get('gplus_id')
    logging.info(gplus_id)
    API_KEY = get_server_api_key()
    gplus_service = build('plus', 'v1', developerKey=API_KEY)
    activities = ActivityPost.query((ActivityPost.gplus_id == gplus_id)).order((- ActivityPost.date)).fetch(1)
    if (len(activities) == 0):
        last_activity_date = date(1990, 1, 1).strftime('%Y-%m-%d %H:%M:%S')
    else:
        last_activity_date = activities[0].date
    logging.info(('Last activity date : % s' % last_activity_date))
    try:
        result = gplus_service.activities().list(userId=gplus_id, collection='public', maxResults=100).execute()
    except:
        logging.info('trying to get gplus activities again')
        try:
            result = gplus_service.activities().list(userId=gplus_id, collection='public', maxResults=100).execute()
        except:
            logging.info('failed again, giving up')
    else:
        gplus_act = result.get('items', [])
        gplus_activities = sorted(gplus_act, key=(lambda k: k['updated']))
        for gplus_activity in gplus_activities:
            if (gplus_activity['updated'] > last_activity_date):
                if (is_gde_post(gplus_activity) and is_valid_post(gplus_activity)):
                    new_activity = ActivityPost(id=gplus_activity['id'])
                    new_activity.create_from_gplus_post(gplus_activity)
                    new_activity.put()
                    logging.info(('new activity recorded: %s' % new_activity.url))
                    activity_record = find_or_create_ar(gplus_activity, new_activity)
                    activity_record.add_post(new_activity)
                else:
                    logging.info('Non Valid Post')
                    logging.info(gplus_activity)

dataset/ETHPy150Open GoogleDeveloperExperts/experts-app-backend/services/update_gplus.py TaskNewGplus.post/original