Exemplo n.º 1
0
    def post(self):
        """."""
        logging.info('tasks/harvest_so')

        # get the gde Account entity
        safe_key = self.request.get('key')
        gde = ndb.Key(urlsafe=safe_key).get()
        logging.info(gde)

        url = SP_ROOT + SP_ID + SP_FORMAT

        req = Request(url)
        res = urlopen(req).read()
        rows = json.loads(res)["rows"]
        logging.info(rows)

		# get the activities for the gde
        activities = ActivityRecord.query(ActivityRecord.gplus_id == gde.gplus_id)
        for activity in activities:
        	logging.info(activity.activity_link)
        	for row in rows:
        		count = row[1]
        		logging.info(count)
        		url = row[0]
        		logging.info(url)
        		url_parts = url.split("/")
        		logging.info(url_parts[1])
        		if url_parts[1] == gde.gplus_id:
        			logging.info('we have a match')
        			logging.info(url_parts[len(url_parts) - 1])
        			if url_parts[len(url_parts) - 1] in activity.activity_link:
        				logging.info('WINNER WINNER CHICKEN DINNER')
    def get(self):
        """."""
        logging.info("tasks/calc_impact")

        activity_records = ActivityRecord.query()
        ar_count = 0
        for ar in activity_records:
            if ar.deleted is None:
                ar.deleted = False
            ar.put()
            ar_count += 1

        logging.info("tasks/calc_impact calculated %s ar" % ar_count)
Exemplo n.º 3
0
def find_or_create_ar(gplus_activity, activity_post):
    # is this a reshare find the first AR that references the post
    # if the post is shared query for the original post id
    # if there are none the create a new activity record and return it
    if gplus_activity["verb"] == 'post':
        original_post_id = gplus_activity['id']
    elif gplus_activity["verb"] == 'share':
        original_post_id = gplus_activity['object']['id']

    if original_post_id is not None:
        records = ActivityRecord.query(ActivityRecord.gplus_posts ==
                                       original_post_id).fetch(20)
        if (len(records) == 0):
            return ar.create_activity_record(activity_post)
        else:
            return records[0]

    return ar.create_activity_record(activity_post)
Exemplo n.º 4
0
def update_video_views(gplus_id):
    """Iterate through ActivityRecords and get video views"""
    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()