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
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
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
def test_create_and_get_video(self): cat = factories.CategoryFactory() lang = factories.LanguageFactory(name=u'English 1') ret = richardapi.create_video(self.api_url, auth_token=self.token.key, video_data={ 'title': 'Test video create and get', 'language': lang.name, 'category': cat.title, 'state': richardapi.STATE_DRAFT, 'speakers': ['Jimmy'], 'tags': ['foo'], }) vid = richardapi.get_video(self.api_url, auth_token=self.token.key, video_id=ret['id']) assert vid['id'] == ret['id'] assert vid['title'] == ret['title']
def test_create_and_get_video(self): cat = category(save=True) lang = language(name=u'English 1', save=True) ret = richardapi.create_video(self.api_url, auth_token=self.token.key, video_data={ 'title': 'Test video create and get', 'language': lang.name, 'category': cat.title, 'state': richardapi.STATE_DRAFT, 'speakers': ['Jimmy'], 'tags': ['foo'], }) vid = richardapi.get_video(self.api_url, auth_token=self.token.key, video_id=ret['id']) eq_(vid['id'], ret['id']) eq_(vid['title'], ret['title'])
def test_create_and_get_video(self): cat = category(save=True) lang = language(name=u'English 1', save=True) ret = richardapi.create_video( self.api_url, auth_token=self.token.key, video_data={ 'title': 'Test video create and get', 'language': lang.name, 'category': cat.title, 'state': richardapi.STATE_DRAFT, 'speakers': ['Jimmy'], 'tags': ['foo'], }) vid = richardapi.get_video( self.api_url, auth_token=self.token.key, video_id=ret['id']) eq_(vid['id'], ret['id']) eq_(vid['title'], ret['title'])
def test_create_and_get_video(self): cat = factories.CategoryFactory() lang = factories.LanguageFactory(name=u'English 1') ret = richardapi.create_video( self.api_url, auth_token=self.token.key, video_data={ 'title': 'Test video create and get', 'language': lang.name, 'category': cat.title, 'state': richardapi.STATE_DRAFT, 'speakers': ['Jimmy'], 'tags': ['foo'], }) vid = richardapi.get_video( self.api_url, auth_token=self.token.key, video_id=ret['id']) assert vid['id'] == ret['id'] assert vid['title'] == ret['title']
def main(args): categories = richardapi.get_all_categories(API_URL) data_path = os.path.join(os.getcwd(), 'data') try: os.mkdir(data_path) except OSError: pass for cat in categories: print('Working on %s...' % cat['title']) # make the category directory path = os.path.join(data_path, cat['slug']) try: os.mkdir(path) except OSError: pass # save category data with open(os.path.join(path, 'category.json'), 'w') as fp: cat_data = OrderedDict(( ('title', cat['title']), ('description', cat['description']), ('url', cat['url']), ('slug', cat['slug']), ('start_date', cat['start_date']), )) json.dump(cat_data, fp, sort_keys=False, indent=2) videos_path = os.path.join(path, 'videos') try: os.mkdir(videos_path) except OSError: pass # pull down the video data for video_url in cat['videos']: print(' %s' % video_url) video_id = get_video_id(video_url) try: video = richardapi.get_video( api_url=API_URL, auth_token=None, video_id=video_id ) except restapi.Http4xxException: # If we get this, then the video is in draft. Let's just skip # it. print(' 404') continue # if this video is a "draft", then skip it if video['state'] == 2: print(' ... skipping: draft') continue # ditch embed because that's gross del video['embed'] # if the language is None, then set it to English which is # probably right. if not video['language']: video['language'] = 'English' # delete added and updated since we don't need those anymore. del video['added'] del video['updated'] # ditch state del video['state'] videos = [] for fmt in ['mp4', 'webm', 'flv', 'ogv']: if not video.get(('video_%s_url' % fmt)): continue videos.append({ 'length': video.get(('video_%s_length' % fmt), 0), 'url': video['video_%s_url' % fmt], 'type': fmt }) for key in [key for key in video.keys() if key.startswith('video_%s' % fmt)]: del video[key] if video['source_url'] and 'youtu' in video['source_url']: videos.append({ 'length': 0, 'url': video['source_url'], 'type': 'youtube' }) video['videos'] = videos video_fn = os.path.join(videos_path, video['slug']) + '.json' with open(video_fn, 'w') as fp: json.dump(reorder_dict(video), fp, sort_keys=False, indent=2) return
def main(args): categories = richardapi.get_all_categories(API_URL) data_path = os.path.join(os.getcwd(), 'data') try: os.mkdir(data_path) except OSError: pass for cat in categories: print('Working on %s...' % cat['title']) # make the category directory path = os.path.join(data_path, cat['slug']) try: os.mkdir(path) except OSError: pass # save category data with open(os.path.join(path, 'category.json'), 'w') as fp: cat_data = OrderedDict(( ('title', cat['title']), ('description', cat['description']), ('url', cat['url']), ('slug', cat['slug']), ('start_date', cat['start_date']), )) json.dump(cat_data, fp, sort_keys=False, indent=2) videos_path = os.path.join(path, 'videos') try: os.mkdir(videos_path) except OSError: pass # pull down the video data for video_url in cat['videos']: print(' %s' % video_url) video_id = get_video_id(video_url) try: video = richardapi.get_video(api_url=API_URL, auth_token=None, video_id=video_id) except restapi.Http4xxException: # If we get this, then the video is in draft. Let's just skip # it. print(' 404') continue # if this video is a "draft", then skip it if video['state'] == 2: print(' ... skipping: draft') continue # ditch embed because that's gross del video['embed'] # if the language is None, then set it to English which is # probably right. if not video['language']: video['language'] = 'English' # delete added and updated since we don't need those anymore. del video['added'] del video['updated'] # ditch state del video['state'] videos = [] for fmt in ['mp4', 'webm', 'flv', 'ogv']: if not video.get(('video_%s_url' % fmt)): continue videos.append({ 'length': video.get(('video_%s_length' % fmt), 0), 'url': video['video_%s_url' % fmt], 'type': fmt }) for key in [ key for key in video.keys() if key.startswith('video_%s' % fmt) ]: del video[key] if video['source_url'] and 'youtu' in video['source_url']: videos.append({ 'length': 0, 'url': video['source_url'], 'type': 'youtube' }) video['videos'] = videos video_fn = os.path.join(videos_path, video['slug']) + '.json' with open(video_fn, 'w') as fp: json.dump(reorder_dict(video), fp, sort_keys=False, indent=2) return
def main(args): categories = richardapi.get_all_categories(API_URL) data_path = os.path.join(os.getcwd(), 'data') try: os.mkdir(data_path) except OSError: pass for cat in categories: print('Working on %s...' % cat['title']) # make the category directory path = os.path.join(data_path, cat['slug']) try: os.mkdir(path) except OSError: pass # save category data with open(os.path.join(path, 'category.json'), 'w') as fp: fp.write( json.dumps({ 'title': cat['title'], 'description': cat['description'], 'url': cat['url'], 'slug': cat['slug'], 'start_date': cat['start_date'] })) videos_path = os.path.join(path, 'videos') try: os.mkdir(videos_path) except OSError: pass # pull down the video data for video_url in cat['videos']: print(' %s' % video_url) video_id = get_video_id(video_url) try: video = richardapi.get_video(api_url=API_URL, auth_token=None, video_id=video_id) except restapi.Http4xxException: # If we get this, then the video is in draft. Let's just skip # it. print(' 404') continue # if this video is a "draft", then skip it if video['state'] == 2: print ' ... skipping: draft' continue # ditch embed because that's gross del video['embed'] # if the language is None, then set it to English which is # probably right. if not video['language']: video['language'] = 'English' # ditch the slug because we don't need those anymore. slug = video['slug'] del video['slug'] # ditch the id because we don't need that anymore, either. del video['id'] # delete added and updated since we don't need those anymore. del video['added'] del video['updated'] # ditch state del video['state'] video_fn = os.path.join(videos_path, slug) + '.json' with open(video_fn, 'w') as fp: fp.write(json.dumps(video)) return