コード例 #1
0
    def __init__(
        self,
        directory: str,
        entry: fp.FeedParserDict,
        podcast_name: str,
        podcast_url: str,
    ):
        """`init` method.

        :param directory: download directory
        :param entry: single FeedParserDict from fp.parse(url).entries list
        :param podcast_name:
        """
        self._dl_dir = directory
        self.error: bool = None
        self.entry = entry
        self.podcast_name = podcast_name
        self._logger = logger(f"{self.__class__.__name__}")
        self.podcast_url = podcast_url
        self.title = self.entry.get("title", "No title available.").replace(
            "/", "-")  # '/' screws up filenames
        self.summary = self.entry.get("summary", "No summary available.")
        self.image = self._image_url()
        self.url = self._audio_file_url()
        self.filename = self._file_parser()
コード例 #2
0
 def test_logger(self):
     print(TEST_LOG)
     files = listdir(TEST_LOG)
     test_logger = logger('test_logger', TEST_LOG)
     # Checks that file isn't created until a log entry is created.
     self.assertNotIn('test_logger.log', files)
     test_logger.info('test message!')
     files = listdir(TEST_LOG)
     self.assertIn('test_logger.log', files)
     with open(TEST_LOG / 'test_logger.log', 'r') as file:
         line = file.read()
     self.assertIn('test message!', line)
コード例 #3
0
    def __init__(
        self,
        podcasts: List[Tuple[str, str, List[Episode]]],
        sender: str,
        password: str,
        recipient: str,
    ):
        """Init method.

        :param podcasts: List of podcast episodes that were successfully downloaded.  Each tuple making up the list
        has three elements: name, image url and a list of Episodes.
        """
        self.sender = sender
        self.password = password
        self.recipient = recipient
        self.logger = logger(f"{self.__class__.__name__}")
        self.podcasts = podcasts
        self.text = self.render_text()
        self.html = self.render_html()
コード例 #4
0
    def __init__(self, url: str, directory: str):
        """init method.

        :param url: rss feed url for this podcast
        :param directory: download directory for this podcast
        """
        self._url = url
        self._dl_dir = directory
        self._logger = logger(f"{self.__class__.__name__}")
        self.episodes: tp.List[Episode] = []
        _old_eps = Database().get_episodes(self._url)
        _feed: fp.FeedParserDict = fp.parse(self._url)
        self._name = _feed.feed.get("title", default=self._url)
        try:
            self._image = _feed.feed.image.href
        except (KeyError, AttributeError):
            self._logger.exception(f"No image for {self._url}")
            self._image = None
        self._new_entries = [
            item for item in _feed.entries if item.id not in _old_eps
        ]
        self._episode_parser()
コード例 #5
0
 def __init__(self, db_file: str = Config.database):
     self._db_file = db_file
     self._conn = sqlite3.connect(self._db_file)
     self._conn.execute("PRAGMA foreign_keys=ON")
     self.cursor = self._conn.cursor()
     self._logger = logger(f"{self.__class__.__name__}")