def test_database_add_episodes(prevent_modification): copyfile(my_dir + "/datafiles/database_example1.db", Database.PATH) mydatabase = Database() myfeed_path = my_dir + "/feeds/valid_basic.xml" myfeed = Feed(file=myfeed_path) episodes = myfeed.parse_episodes() mydatabase.replace_feed(myfeed) assert len(mydatabase.episodes(myfeed)) == 0 mydatabase.replace_episodes(myfeed, episodes) assert len(mydatabase.episodes(myfeed)) == len(episodes)
def import_subscriptions(path: str, database: Database) -> None: subscriptions = Subscriptions() # Load may raise an error, but they are user-friendly enough that we don't # need to catch them here. It's also okay to crash at this point. subscriptions.load(path) print("Importing %d feeds..." % len(subscriptions.feeds)) for feed in subscriptions.feeds: database.replace_feed(feed) episodes = feed.parse_episodes() database.replace_episodes(feed, episodes) print("Imported '%s' with %d episodes" % (str(feed), len(episodes)))
def import_subscriptions(path: str, database: Database) -> None: subscriptions = Subscriptions() # Load may raise an error, but they are user-friendly enough that we don't # need to catch them here. It's also okay to crash at this point. subscriptions.load(path) for generated in subscriptions.parse(): if isinstance(generated, Feed): feed = generated database.replace_feed(feed) episodes = feed.parse_episodes() database.replace_episodes(feed, episodes) print("Added \"%s\" with %d episodes" % (str(feed), len(episodes))) else: print("ERROR: Failed to load %s -- %s" % (str(generated[0]), str(generated[1]))) print("Imported %d feeds" % len(subscriptions.feeds))