def test_get_categories(self): cat = category(save=True) cats = richardapi.get_all_categories(self.api_url) eq_(len(cats), 1) cats[0]['title'] = cat.title
def test_get_categories(self): cat = factories.CategoryFactory() cats = richardapi.get_all_categories(self.api_url) assert len(cats) == 1 cats[0]['title'] = cat.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