def test_save_and_restore(self): horse_podcast = Podcast.from_dict(self.feed_dict) with tempfile.NamedTemporaryFile(suffix='.json') as f: tmp = f.name horse_podcast.save_to_file(tmp) restored_podcast = Podcast.from_file(tmp) os.unlink(tmp) self.assertEqual(horse_podcast.url, restored_podcast.url) self.assertEqual(len(horse_podcast.episodes), len(restored_podcast.episodes))
def add_podcast(self, args): # check if we already have it p = Podcast(args.url) path = self.get_podcast_path(p) if os.path.exists(path): raise(Exception('already exists: %s : %s' % (args.url, path))) p = Podcast.from_url(args.url) if args.title: p.title = args.title self.podcasts.append(p) p.save_to_file(path) return p
def test_update_from_other_podcast(self): updated_feed_dict = copy.deepcopy(self.feed_dict) updated_feed_dict['episodes'].append({'listened': False, 'media_path': None, 'media_url': 'http://localhost/ep4.mp3', 'published': 'Fri, 27 Jun 2008 07:00:00 GMT', 'title': 'Tail'}) podcast = Podcast.from_dict(self.feed_dict) other = Podcast.from_dict(updated_feed_dict) new_episode_count = podcast.update_from_podcast(other) self.assertEqual(len(podcast.episodes), 4) self.assertEqual(new_episode_count, 1) other.url = 'http://otherhost/feed.xml' with self.assertRaises(Exception): podcast.update_from_podcast(other)
def load_podcasts(self): log.debug('looking for feeds in: %s' % self.config['feed_dir']) self.podcasts = [] for path in glob.glob('%s/*.json' % self.config['feed_dir']): podcast = Podcast.from_file(path) self.podcasts.append(podcast) return len(self.podcasts)
def import_podcasts(self, args): log.debug('import_podcasts(filter=%s, input_path=%s)' % (args.filter, args.path)) with get_fh_or(sys.stdin, args.path, 'r') as f: data = json.load(f) for podcast_dict in data: try: p = Podcast.from_dict(podcast_dict) log.debug('import_podcasts: examining: %s' % p.title) path = self.get_podcast_path(p) if os.path.exists(path): raise(Exception('already exists: %s for %s' % (path, p.title))) p.path = path if p.matches_filter(args.filter): log.debug('import_podcasts: Podcast matches filter, saving... %s' % p.title) p.save() except Exception as e: log.warning('import_podcasts: exception while importing podcast: %s' % e)
def test_feed_from_dict(self): horse_podcast = Podcast.from_dict(self.feed_dict) self.assertEqual(len(horse_podcast.episodes), 3) self.assertEqual(horse_podcast.title, 'My Lovely Horse')
def test_episode_from_file(self): feed_file = '%s/tests/feed.xml' % os.popen("git rev-parse --show-toplevel").read().strip() robots_podcast = Podcast.from_file_feed(feed_file) self.assertEqual(len(robots_podcast.episodes), 185) self.assertEqual(robots_podcast.title, 'Robots - The Podcast for News and Views on Robotics')