예제 #1
0
    def get_videos_most_seen(self, moments, limit=5):
        registry = getUtility(IRegistry)
        records = registry.forInterface(IAPISettings)

        url_base = self.get_multimedia_url()
        video_api = records.video_api

        base_url = "%s%s" % (url_base, video_api)

        limit_param = records.limit
        details_param = records.details
        video_order = records.video_order

        params = {limit_param: limit,
                  details_param: 'basico',
                  video_order: 'popularidad'}

        params = urllib.urlencode(params)
        base_url += params

        widgets = []

        if 'today' in moments:
            result = urllib.urlopen(base_url).read()
            result = json.loads(result)

            widget = {'title': _(u"Most seen today"),
                      'videos': result,
                      }
            widgets.append(widget)

        if 'week' in moments:
            result = urllib.urlopen(base_url).read()
            result = json.loads(result)

            widget = {'title': _(u"Most seen this week"),
                      'videos': result,
                      }
            widgets.append(widget)

        if 'month' in moments:
            result = urllib.urlopen(base_url).read()
            result = json.loads(result)

            widget = {'title': _(u"Most seen this month"),
                      'videos': result,
                      }
            widgets.append(widget)

        if 'year' in moments:
            result = urllib.urlopen(base_url).read()
            result = json.loads(result)

            widget = {'title': _(u"Most seen this year"),
                      'videos': result,
                      }
            widgets.append(widget)

        return json.dumps(widgets)
예제 #2
0
    def get_videos_most_seen_widgets(self, moments):
        registry = getUtility(IRegistry)
        records = registry.forInterface(IAPISettings)
        most_seen_widget = records.most_seen_widget
        time_filter_day = records.time_filter_day
        time_filter_week = records.time_filter_week
        time_filter_month = records.time_filter_month
        time_filter_year = records.time_filter_year

        widgets = []

        #XXX: This should be done with urlencode
        if 'today' in moments:
            widget = {'title': _(u"Most seen today"),
                      'url': "%s&%s" % (most_seen_widget,
                                            time_filter_day),
                      }
            widgets.append(widget)

        #XXX: This should be done with urlencode
        if 'week' in moments:
            widget = {'title': _(u"Most seen this week"),
                      'url': "%s&%s" % (most_seen_widget,
                                            time_filter_week),
                      }
            widgets.append(widget)

        #XXX: This should be done with urlencode
        if 'month' in moments:
            widget = {'title': _(u"Most seen this month"),
                      'url': "%s&%s" % (most_seen_widget,
                                            time_filter_month),
                      }
            widgets.append(widget)

        #XXX: This should be done with urlencode
        if 'year' in moments:
            widget = {'title': _(u"Most seen this year"),
                      'url': "%s&%s" % (most_seen_widget,
                                            time_filter_year),
                      }
            widgets.append(widget)

        return widgets