Exemple #1
0
    def test_get_fetcher_opt(self, mocker):
        config.load(
            {"fetcher_opts": ["a=5", "ab=6"]},
            fetcher=mocker.MagicMock(__module__="reddit_next"),
        )

        assert config.get_fetcher_opt("a") == "5"
        assert config.get_fetcher_opt("ab") == "6"
Exemple #2
0
 def fetch_story(self):
     submissions = self.fetch_submissions()
     title = config.get_fetcher_opt("title", required=True)
     author = submissions[0].author_name
     return Story(
         title=title,
         author=author,
         chapters=[subm.as_chapter() for subm in submissions],
     )
Exemple #3
0
    def composition_order(self):
        requested_order = (
            config.get_fetcher_opt("order", required=False) or "sequential"
        )

        if requested_order not in ["sequential", "chrono"]:
            raise RuntimeError(f"Unknown order {requested_order}")

        return requested_order
Exemple #4
0
 def fetch_story(self):
     title = config.get_fetcher_opt("title", required=True)
     entries = list(self.fetch_blog_entries())
     author = entries[0].author
     return Story(
         title=title,
         author=author,
         summary="",
         chapters=[entry.as_chapter() for entry in entries],
     )
Exemple #5
0
    def categories_to_fetch(self):
        requested_categories = config.get_fetcher_opt("categories", required=False)

        if requested_categories is None:
            # By default, include only the "threadmarks" category (the main story)
            return ["threadmarks"]
        elif requested_categories == "all":
            # The special value "all" means get everything
            return self.threadmarks_categories.keys()
        else:
            # else, split the input string by delimiter
            return requested_categories.split(",")
Exemple #6
0
 def fetch_story(self):
     title = (
         config.get_fetcher_opt("title", required=True)
         + " ("
         + ", ".join(self.categories_to_fetch)
         + ")"
     )
     posts = list(self.fetch_posts())
     author = posts[0].author
     return Story(
         title=title,
         author=author,
         summary="",  # TODO some threads have summaries
         chapters=[entry.as_chapter() for entry in posts],
     )
Exemple #7
0
 def pretty_author(self):
     if self.date_updated:
         readable_date_updated = datetime.utcfromtimestamp(
             self.date_updated
         ).strftime("%Y-%m-%d")
         edited_string = f", edited {readable_date_updated}"
     else:
         edited_string = ""
     readable_date = datetime.utcfromtimestamp(self.date_published).strftime(
         "%Y-%m-%d"
     )
     # TODO get author_name more automatically
     author_name = config.get_fetcher_opt("author", required=False)
     if author_name == self.author:
         distinguish_string = "★ "
     else:
         distinguish_string = ""
     return f"{distinguish_string}{self.author} ({readable_date}{edited_string})"
Exemple #8
0
 def is_last_chapter_url(self, url):
     last_chapter_pattern = config.get_fetcher_opt("last_chapter_pattern")
     return last_chapter_pattern and re.search(last_chapter_pattern, url)