Example #1
0
def stat_by_month(userid, func_y_value):
    xs = list()
    ys = list()

    all_media = user_media(userid)
    first_media = MediaHolder(all_media[0])
    month = first_media.created_time().month
    year = first_media.created_time().year
    month_likes = [first_media.like_count()]
    del all_media[0]

    def period_switch(m, y, likes):
        xs.append(datetime.strptime(str(m) + '-' + str(y), '%m-%Y'))
        ys.append(func_y_value(likes))
        return mh.created_time().month, mh.created_time().year, [mh.like_count()]

    for media in all_media:
        mh = MediaHolder(media)
        if month == mh.created_time().month:
            month_likes.append(mh.like_count())
        else:
            month, year, month_likes = period_switch(month, year, month_likes)

    period_switch(month, year, month_likes)

    xs.sort()
    ys.reverse()

    return xs, ys
Example #2
0
def total_likes_and_media(userid):
    global dict_likes_and_media_count_by_user

    if userid in dict_likes_and_media_count_by_user.keys():
        return dict_likes_and_media_count_by_user[userid]

    likes = 0
    posts = 0
    all_media = user_media(userid)
    for media in all_media:
        mh = MediaHolder(media)
        likes += mh.like_count()
        posts += 1

    dict_likes_and_media_count_by_user[userid] = (likes, posts)

    return likes, posts
Example #3
0
    def __make_sorted_media_by(self, principle):
        if not self.is_defined():
            print "Sorted media not defined."
            return False

        all_media = user_media(self.user_id)
        if all_media is None:
            print "User media not collected"
            return False

        media_holders_list = list()

        for media in all_media:
            media_holders_list.append(MediaHolder(media))

        sorted_media = sorted(media_holders_list, key=lambda m: m.like_count(), reverse=True)

        self.principle_to_media_holder_dict[principle] = sorted_media

        return True