diff --git a/examples/show_category.py b/examples/show_category.py new file mode 100644 index 0000000..6086720 --- /dev/null +++ b/examples/show_category.py @@ -0,0 +1,22 @@ +from lunduke.client import DiscourseClient +from lunduke.forum.mappings import Categories + +def main(): + client = DiscourseClient() + category_ids = Categories().get_all().keys() + # https://{defaultHost}/c/{id}/show.json + # TODO: FAILS: 403 - The API KEY DOES NOT ACKNOWLEDGE THAT I AM LOGGED IN + for cat_id in category_ids: + try: + response = client.get(f"/c/{cat_id}/show.json") + print(response.request.url) + print(response.request.headers) + print(response.status_code) + print(response.json()) + except Exception as e: + print(f"Error: {e}") + + + +if __name__ == "__main__": + main() \ No newline at end of file diff --git a/lunduke/forum/mappings.py b/lunduke/forum/mappings.py index 8d1a4c5..4e9f1b7 100644 --- a/lunduke/forum/mappings.py +++ b/lunduke/forum/mappings.py @@ -6,4 +6,15 @@ class Categories: 15: "Politics OK", 16: "No Politics", 23: "Forum Stuff" - } \ No newline at end of file + } + + def get_category_name(self, category_id): + return self.categories.get(category_id, "Unknown") + + def get_category_id(self, category_name): + for category_id, category_name in self.categories.items(): + if category_name == category_name: + return category_id + + def get_all(self): + return self.categories