Exemple #1
0
def refresh_online_stats():
    for vid in Video.objects.all():
        yt_entry = get_youtube_entry(vid.youtubeID)
        if yt_entry:
            online_stats = get_online_stats(yt_entry)
            vid.onlineViews = online_stats['views']
            vid.onlineLikes = int(online_stats['likes']) + VideoLike.objects.filter(video=vid.uid).count()
            vid.save()
Exemple #2
0
def refresh_online_stats():
    url = 'https://www.googleapis.com/youtube/v3/videos?part=statistics&id='
    for vid in Video.objects.all():
        yt_entry = get_youtube_entry(vid.youtubeID, url)
        if yt_entry:
            online_stats = get_online_stats(yt_entry)
            vid.onlineViews = online_stats['views']
            vid.onlineLikes = int(online_stats['likes']) + VideoLike.objects.filter(video=vid.uid).count()
            vid.save()
Exemple #3
0
def update_website_video(vid):
    yt_entry = get_youtube_entry(cleanup_youtubeid(vid.youtubeid))
    if yt_entry:
        try:
            partner = Partner.objects.get(coco_id=str(vid.partner.id))
        except Partner.DoesNotExist:
            return
        language  = vid.language.language_name
        country = vid.village.block.district.state.country.country_name
        state = vid.village.block.district.state.state_name
        date = vid.production_date
        offline_stats = get_offline_stats(vid.id)
        online_stats = get_online_stats(yt_entry)
        temp = vid.duration if vid.duration is not None else datetime.time(0,0,0)
        duration = datetime.datetime.combine(datetime.date.today(), temp) - datetime.datetime.combine(datetime.date.today(), datetime.time(0,0,0))
        duration = int(duration.total_seconds())
        if vid.related_practice is not None:
            sector = vid.related_practice.practice_sector.name if vid.related_practice.practice_sector else ''
            subsector = vid.related_practice.practice_subsector.name if vid.related_practice.practice_subsector else ''
            topic = vid.related_practice.practice_topic.name if vid.related_practice.practice_topic else ''
            subtopic = vid.related_practice.practice_subtopic.name if vid.related_practice.practice_subtopic else ''
            subject = vid.related_practice.practice_subject.name if vid.related_practice.practice_subject else ''
        else:
            sector = subsector = topic = subtopic = subject = ''
        thumbnailURL = S3_VIDEO_BUCKET + str(vid.id) + '.jpg'
        try :
            website_vid = Video.objects.get(coco_id = str(vid.id))
            # There is just one result for a filter, but we want to use update here.
            website_vid = Video.objects.filter(coco_id = str(vid.id))
            website_vid.update(title = vid.title, description = vid.benefit, youtubeID = vid.youtubeid, date = vid.production_date,
                                category = sector, subcategory = subsector, topic = topic, subtopic = subtopic, subject = subject,
                                language = language, partner = partner, state = state, country = country,
                                offlineViews = offline_stats['views__sum'], adoptions = offline_stats['adopted__sum'], 
                                onlineLikes = online_stats['likes'], duration = duration, onlineViews = online_stats['views'],
                                thumbnailURL = "http://s3.amazonaws.com/digitalgreen/video_thumbnail/raw/%s.jpg" % str(vid.id),
                                thumbnailURL16by9 = "http://s3.amazonaws.com/digitalgreen/video_thumbnail/16by9/%s.jpg" % str(vid.id))
        except Video.DoesNotExist:
            website_vid = Video(coco_id = str(vid.id), title = vid.title, description = vid.benefit, youtubeID = vid.youtubeid, date = vid.production_date,
                                category = sector, subcategory = subsector, topic = topic, subtopic = subtopic, subject = subject,
                                language = language, partner = partner, state = state, country = country,
                                offlineViews = offline_stats['views__sum'], adoptions = offline_stats['adopted__sum'], 
                                onlineLikes = online_stats['likes'], duration = duration, onlineViews = online_stats['views'],
                                thumbnailURL = "http://s3.amazonaws.com/digitalgreen/video_thumbnail/raw/%s.jpg" % str(vid.id),
                                thumbnailURL16by9 = "http://s3.amazonaws.com/digitalgreen/video_thumbnail/16by9/%s.jpg" % str(vid.id))
            website_vid.save()