diff --git a/AO3/search.py b/AO3/search.py index 445d527..faa7987 100644 --- a/AO3/search.py +++ b/AO3/search.py @@ -25,6 +25,22 @@ DESCENDING = "desc" ASCENDING = "asc" +# Category IDs +CATEGORY_FF = 116 +CATEGORY_FM = 22 +CATEGORY_GEN = 21 +CATEGORY_MM = 23 +CATEGORY_MULTI = 2246 +CATEGORY_OTHER = 24 + +# Warning IDs +WARNING_CHOOSE_NOT_TO_USE = 14 +WARNING_VIOLENCE = 17 +WARNING_DEATH = 18 +WARNING_NONE = 16 +WARNING_NONCON = 19 +WARNING_UNDERAGE = 20 + class Search: def __init__( @@ -51,7 +67,10 @@ def __init__( characters="", relationships="", tags="", - session=None): + session=None, + category_ids=None, + warning_ids=None, + ): self.any_field = any_field self.title = title @@ -75,7 +94,9 @@ def __init__( self.sort_column = sort_column self.sort_direction = sort_direction self.revised_at = revised_at - + self.category_ids = category_ids + self.warning_ids = warning_ids + self.session = session self.results = None @@ -93,7 +114,7 @@ def update(self): self.word_count, self.language, self.fandoms, self.rating, self.hits, self.kudos, self.crossovers, self.bookmarks, self.excluded_tags, self.comments, self.completion_status, self.page, self.sort_column, self.sort_direction, self.revised_at, self.session, - self.characters, self.relationships, self.tags) + self.characters, self.relationships, self.tags, self.category_ids, self.warning_ids) results = soup.find("ol", {"class": ("work", "index", "group")}) if results is None and soup.find("p", text="No results found. You may want to edit your search to make it less specific.") is not None: @@ -139,7 +160,10 @@ def search( session=None, characters="", relationships="", - tags=""): + tags="", + category_ids=None, + warning_ids=None, +): """Returns the results page for the search as a Soup object Args: @@ -214,6 +238,18 @@ def search( query.add_field(f"work_search[sort_direction]={sort_direction}") if revised_at != "": query.add_field(f"work_search[revised_at]={revised_at}") + if category_ids is not None: + if isinstance(category_ids, (list, tuple)): + for cat in category_ids: + query.add_field(f"work_search[category_ids][]={cat}") + else: + query.add_field(f"work_search[category_ids][]={category_ids}") + if warning_ids is not None: + if isinstance(warning_ids, (list, tuple)): + for warning in warning_ids: + query.add_field(f"work_search[archive_warning_ids][]={warning}") + else: + query.add_field(f"work_search[archive_warning_ids][]={warning_ids}") url = f"https://archiveofourown.org/works/search?{query.string}"