예제 #1
0
    def up_richard(self, ep):

        host = pw.richard[ep.show.client.richard_id]
        endpoint = "http://{hostname}/api/v2".format(hostname=host["host"])

        v_id = get_video_id(ep.public_url)

        video_data = get_video(api_url=endpoint, auth_token=host["api_key"], video_id=v_id)

        if video_data["state"] == STATE_LIVE:
            print "Already STATE_LIVE, 403 coming."
        else:
            video_data["state"] = 1

        try:
            update_video(endpoint, auth_token=host["api_key"], video_id=v_id, video_data=video_data)
        except Http4xxException as exc:
            print exc
            print "told you this was coming."
        except MissingRequiredData as exc:
            print exc
            # this shouldn't happen, prolly debugging something.
            import code

            code.interact(local=locals())

        return True
예제 #2
0
    def up_richard(self, ep):

        host = pw.richard[ep.show.client.richard_id]
        endpoint = 'http://{hostname}/api/v2'.format(hostname=host['host'])

        v_id = get_video_id(ep.public_url)

        video_data = get_video(api_url=endpoint,
                               auth_token=host['api_key'],
                               video_id=v_id)

        if video_data['state'] == STATE_LIVE:
            print "Already STATE_LIVE, 403 coming."
        else:
            video_data['state'] = 1

        try:
            update_video(endpoint,
                         auth_token=host['api_key'],
                         video_id=v_id,
                         video_data=video_data)
        except Http4xxException as exc:
            print exc
            print "told you this was coming."
        except MissingRequiredData as exc:
            print exc
            # this shouldn't happen, prolly debugging something.
            import code
            code.interact(local=locals())

        return True
예제 #3
0
        def test_create_and_update_video(self):
            cat = category(save=True)
            lang = language(name=u'English 2', save=True)

            ret = richardapi.create_video(
                self.api_url,
                auth_token=self.token.key,
                video_data={
                    'title': 'Test video create and update',
                    'language': lang.name,
                    'category': cat.title,
                    'state': richardapi.STATE_DRAFT,
                    'speakers': ['Jimmy'],
                    'tags': ['foo'],
                })

            video = Video.objects.get(title='Test video create and update')

            eq_(video.title, ret['title'])
            eq_(video.state, ret['state'])
            eq_(video.id, ret['id'])

            ret['title'] = 'Video Test'
            ret = richardapi.update_video(
                self.api_url,
                auth_token=self.token.key,
                video_id=ret['id'],
                video_data=ret
            )

            video = Video.objects.get(title='Video Test')
            eq_(video.title, ret['title'])
        def test_create_and_update_video(self):
            cat = factories.CategoryFactory()
            lang = factories.LanguageFactory(name=u'English 2')

            ret = richardapi.create_video(
                self.api_url,
                auth_token=self.token.key,
                video_data={
                    'title': 'Test video create and update',
                    'language': lang.name,
                    'category': cat.title,
                    'state': richardapi.STATE_DRAFT,
                    'speakers': ['Jimmy'],
                    'tags': ['foo'],
                })

            video = Video.objects.get(title='Test video create and update')

            assert video.title == ret['title']
            assert video.state == ret['state']
            assert video.id == ret['id']

            ret['title'] = 'Video Test'
            ret = richardapi.update_video(
                self.api_url,
                auth_token=self.token.key,
                video_id=ret['id'],
                video_data=ret
            )

            video = Video.objects.get(title='Video Test')
            assert video.title == ret['title']
예제 #5
0
    def update_richard(self, v_id, new_data):
        """ updates a richard record
        :arg vid: video id for richard
        :arg new_data: dict of fields to update

        :returns: a dict from the updated video

        """
        # fetch current record
        video_data = get_video(
                api_url=self.richard_endpoint,
                auth_token=self.host['api_key'],
                video_id=v_id)

        # if self.options.verbose: pprint.pprint( video_data )

        if video_data['state'] == STATE_LIVE:
            print("Currently STATE_LIVE, 403 coming.")

        if self.options.test:
            print('test mode, not updating richard')
            print('veyepar:', pprint.pprint(new_data))
            print('ricard:', pprint.pprint(video_data))
            ret = False
        else:
            print('2. updating richard', v_id)
            if self.options.verbose: pprint.pprint( video_data )
            video_data.update(new_data)
            try:
                # update richard with new information
                ret = update_video(self.richard_endpoint,
                       self.host['api_key'], v_id, video_data)

                # above ret= isn't working.  returns None I think?
                # lets hope there wasn't a problem and blaze ahead.
                ret = True

            except MissingRequiredData as e:
                print('#2, Missing required fields', e.errors)
                import code
                code.interact(local=locals())
                raise e

            except Http4xxException as e:
                if video_data['state'] == STATE_LIVE:
                    if e.response.status_code == 403:
                        print("told you 403 was coming.")
                        print("maybe you can fix it with this:")
                        print("http://{host}/admin/videos/video/{id}/".format(host=self.host['host'],id=v_id))
                        print("don't forget to unlock veyepar too.")
                    else:
                        print("expected 403 due to STATE_LIVE, but now...")

                print(e.response.status_code)
                print(e.response.content)
                import code
                code.interact(local=locals())
                raise e

        return ret
예제 #6
0
        def test_create_and_update_video(self):
            cat = category(save=True)
            lang = language(name=u'English', save=True)

            ret = richardapi.create_video(
                self.api_url,
                auth_token=self.token.key,
                video_data={
                    'title': 'Test video',
                    'language': lang.name,
                    'category': cat.title,
                    'state': 2,  # Has to be draft so update works
                    'speakers': ['Jimmy'],
                    'tags': ['foo'],
                })

            video = Video.objects.get(title='Test video')

            eq_(video.title, ret['title'])
            eq_(video.state, ret['state'])
            eq_(video.id, ret['id'])

            ret['title'] = 'Video Test'
            ret = richardapi.update_video(self.api_url,
                                          auth_token=self.token.key,
                                          video_id=ret['id'],
                                          video_data=ret)

            video = Video.objects.get(title='Video Test')
            eq_(video.title, ret['title'])
예제 #7
0
    def update_richard(self, v_id, new_data):
        """ updates a richard record
        :arg vid: video id for richard
        :arg new_data: dict of fields to update

        :returns: a dict from the updated video

        """
        # fetch current record
        video_data = get_video(
                api_url=self.richard_endpoint, 
                auth_token=self.host['api_key'], 
                video_id=v_id)

        # if self.options.verbose: pprint.pprint( video_data )
     
        if video_data['state'] == STATE_LIVE:
            print("Currently STATE_LIVE, 403 coming.")

        if self.options.test:
            print('test mode, not updating richard') 
            print('veyepar:', pprint.pprint(new_data))
            print('ricard:', pprint.pprint(video_data))
            ret = False
        else: 
            print('2. updating richard', v_id)
            if self.options.verbose: pprint.pprint( video_data )
            video_data.update(new_data)
            try:
                # update richard with new information
                ret = update_video(self.richard_endpoint, 
                       self.host['api_key'], v_id, video_data)
 
                # above ret= isn't working.  returns None I think?
                # lets hope there wasn't a problem and blaze ahead.
                ret = True

            except MissingRequiredData as e:
                print('#2, Missing required fields', e.errors)
                import code
                code.interact(local=locals())
                raise e

            except Http4xxException as e:
                if video_data['state'] == STATE_LIVE:
                    if e.response.status_code == 403:
                        print("told you 403 was coming.")
                        print("maybe you can fix it with this:")
                        print("http://{host}/admin/videos/video/{id}/".format(host=self.host['host'],id=v_id)) 
                        print("don't forget to unlock veyepar too.")
                    else:
                        print("expected 403 due to STATE_LIVE, but now...")

                print(e.response.status_code)
                print(e.response.content)
                import code
                code.interact(local=locals())
                raise e

        return ret
예제 #8
0
    def up_richard(self, ep):

        host = pw.richard[ep.show.client.richard_id]
        endpoint = "http://{hostname}/api/v1".format(hostname=host["host"])
        api = API(endpoint)

        vid = ep.public_url.split("/video/")[1].split("/")[0]

        response = api.video(vid).get(username=host["user"], api_key=host["api_key"])

        video_data = get_content(response)
        video_data["state"] = 1

        try:
            update_video(endpoint, host["user"], host["api_key"], vid, video_data)
        except MissingRequiredData, e:
            # this shouldn't happen, prolly debugging something.
            import code

            code.interact(local=locals())
예제 #9
0
파일: mk_public.py 프로젝트: kamni/veyepar
    def up_richard(self, ep):

        host = pw.richard[ep.show.client.richard_id]
        endpoint = 'http://{hostname}/api/v1'.format(hostname=host['host'])
        api = API(endpoint)

        # vid = ep.public_url.split('/video/')[1].split('/')[0]
        vid = get_video_id(ep.public_url)

        response = api.video(vid).get(
                username=host['user'], api_key=host['api_key'])

        video_data = get_content(response)
        video_data['state'] = 1

        try: 
            update_video(endpoint, host['user'], host['api_key'], 
                    vid, video_data)
        except MissingRequiredData, e:
            # this shouldn't happen, prolly debugging something.
            import code
            code.interact(local=locals())
예제 #10
0
    def update_pyvideo(self, vid, new_data):
        """ updates a pyvideo record
        :arg vid: video id for pyvideo
        :arg new_data: dict of fields to update

        :returns: a dict from the updated video

        """
        try:
            # fetch current record
            response = self.api.video(vid).get(username=self.host['user'], api_key=self.host['api_key'])
            video_data = get_content(response)
            if self.options.verbose: pprint.pprint( video_data )
            # update dict with new information
            video_data.update(new_data)
            if self.options.verbose: pprint.pprint( video_data )
            # update in pyvideo
            return update_video(self.pyvideo_endpoint, self.host['user'], self.host['api_key'], vid, video_data)
        except MissingRequiredData as e:
            print 'Missing required fields', e.errors
            raise e