def update_video_views(gplus_id):
    logging.info('Updating Video Views')
    # build the service object of the yt api
    API_KEY = get_server_api_key()
    yt_service = build('youtube', 'v3', developerKey=API_KEY)
    # get the activities for the gde
    activities = ActivityRecord.query(ActivityRecord.gplus_id == gplus_id,
                                      ActivityRecord.metadata.type == '#video')
    for activity in activities:
        for meta in activity.metadata:
            if meta.link is not None:
                video_id = is_youtube_video(meta.link)
                if video_id is not False:
                    logging.info('linked YT video found %s', video_id)
                    # get the stats for the video
                    stats = yt_service.videos().list(
                        part="statistics", id=video_id).execute()
                    views = stats["items"][0]['statistics']['viewCount']
                    meta.impact = int(views)
                    logging.info('video meta stats updated: %s', views)
        activity.put()
Iterate through ActivityRecords and get video views
dataset/ETHPy150Open GoogleDeveloperExperts/experts-app-backend/services/update_gplus.py/update_video_views