def post(self):
        logging.info('tasks/new_gplus')

        gplus_id = self.request.get('gplus_id')
        logging.info(gplus_id)

        # build the service object for the gplus api
        API_KEY = get_server_api_key()
        gplus_service = build('plus', 'v1', developerKey=API_KEY)
        # find out what the last activity date recorded is for the expert
        activities = ActivityPost.query(
            ActivityPost.gplus_id == gplus_id).order(-ActivityPost.date).fetch(1)
        # if this is the first time we are getting activities for a new user
        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)
        # get the last 100 activities from gplus
        # eventually we can also query using the date so we don't
        # have to compare each post with the date we just got
        try:
            result = gplus_service.activities().list(userId=gplus_id,
                                                     collection='public',
                                                     maxResults=100).execute()
        except:
            # try againg
            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:
            # patt0 25102014 sort the items in reverse update date order
            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:
                    # ensure this is a gde post
                    if is_gde_post(gplus_activity) and is_valid_post(gplus_activity):

                        # create a new 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