Ejemplo n.º 1
0
    def handle(self, *args, **kwargs):
        VIDEOS_PER_PAGE = 500
        count = 0
        offset = 1
        retries_left = 5
        embed_codes_found = set()
        while True:
            req = OoyalaQuery(page_id=offset)
            ooyala_response = req.process()

            if not isinstance(ooyala_response, basestring):
                items = ooyala_response.getElementsByTagName('item')
                if items:
                    sys.stdout.write('Found items %d - %d\n' % (offset, offset+len(items)-1))
                else:
                    #No more items
                    break
                for item in items:
                    [ooyala_item, created] = OoyalaItem.from_xml(item)
                    try:
                        if created:
                            count += 1
                            sys.stdout.write('Added %s (%s)\n' % (str(ooyala_item.title), ooyala_item.content_type))
                        else:
                            sys.stdout.write("Updating %s\n" % str(ooyala_item.title))
                            pass
                        embed_codes_found.add(ooyala_item.embed_code)
                    except UnicodeEncodeError:
                        sys.stdout.write('Decode error for title\n')
                if len(items) < VIDEOS_PER_PAGE:
                    #This was the last page of items
                    break
            else:
                sys.stdout.write('Problem getting the data from ooyala, retrying...\n')
                retries_left -= 1
                if retries_left <= 0:
                    sys.stdout.write('TOO MANY RETRIES GIVING UP!\n')
                    break
                continue # keep same offset

            offset += VIDEOS_PER_PAGE
        
        # we've now gone through ALL ooyala embed codes... hopefully
        # so we can delete any ooyalaitems with other (old) emed_codes
        old_items = OoyalaItem.objects.exclude(embed_code__in=embed_codes_found)
        print
        print 'Deleting %s items: %s' % (old_items.count(), old_items)
        old_items.delete()


        sys.stdout.write('\nCOMPLETE: All items imported - %s in total\n\n' % count)
Ejemplo n.º 2
0
def backlot_query(request):

    req = OoyalaQuery(page_id=500)

    ooyala_response = req.process()
    print ooyala_response

    print req.url
    if type(ooyala_response)!=str:
        items = ooyala_response.getElementsByTagName('item')
        return HttpResponse(ooyala_response.toprettyxml(), mimetype="text/xml")
    else:
        print "got an error back"

    return HttpResponse("tada")
Ejemplo n.º 3
0
    def handle(self, *args, **kwargs):
        req = OoyalaQuery()
        ooyala_response = req.process()
        count = 0

        if type(ooyala_response)!=str:
            items = ooyala_response.getElementsByTagName('item')
            for item in items:
                [ooyala_item, created] = OoyalaItem.from_xml(item)
                if created:
                    count += 1
                    sys.stdout.write('Added %s (%s)\n' % (str(ooyala_item.title), ooyala_item.content_type))
        else:
            sys.stdout.write('Problem getting the data from ooyala, retrying...\n')
            self.handle(self, *args, **kwargs)

        sys.stdout.write('\nCOMPLETE: All items imported - %d in total\n\n' % count)
Ejemplo n.º 4
0
    def handle(self, *args, **kwargs):
        VIDEOS_PER_PAGE = 500
        count = 0
        offset = 1
        retries_left = 5
        while True:
            req = OoyalaQuery(page_id=offset)
            ooyala_response = req.process()

            if not isinstance(ooyala_response, basestring):
                items = ooyala_response.getElementsByTagName('item')
                if items:
                    sys.stdout.write('Found items %d - %d\n' % (offset, offset+len(items)-1))
                else:
                    #No more items
                    break
                for item in items:
                    [ooyala_item, created] = OoyalaItem.from_xml(item)
                    try:
                        if created:
                            count += 1
                            sys.stdout.write('Added %s (%s)\n' % (str(ooyala_item.title), ooyala_item.content_type))
                        else:
                            sys.stdout.write("Skipping %s\n" % str(ooyala_item.title))
                            pass
                    except UnicodeEncodeError:
                        sys.stdout.write('Decode error for title\n')
                if len(items) < VIDEOS_PER_PAGE:
                    #This was the last page of items
                    break
            else:
                sys.stdout.write('Problem getting the data from ooyala, retrying...\n')
                retries_left -= 1
                if retries_left <= 0:
                    sys.stdout.write('TOO MANY RETRIES GIVING UP!\n')
                    break
                continue # keep same offset

            offset += VIDEOS_PER_PAGE


        sys.stdout.write('\nCOMPLETE: All items imported - %s in total\n\n' % count)