@@ -60,7 +60,7 @@ def __init__(
60
60
self .base_url = base_url
61
61
62
62
self .categories = [c .lower () for c in categories ] if categories else []
63
- self .category_id_map : dict [int , str ] = {}
63
+ self .category_id_map : dict [int , dict ] = {}
64
64
65
65
self .batch_size = batch_size
66
66
self .permissions : DiscoursePerms | None = None
@@ -83,7 +83,7 @@ def _get_categories_map(
83
83
)
84
84
categories = response .json ()["category_list" ]["categories" ]
85
85
self .category_id_map = {
86
- cat ["id" ]: cat ["name" ]
86
+ cat ["id" ]: { "name" : cat ["name" ], "slug" : cat [ "slug" ]}
87
87
for cat in categories
88
88
if not self .categories or cat ["name" ].lower () in self .categories
89
89
}
@@ -116,7 +116,7 @@ def _get_doc_from_topic(self, topic_id: int) -> Document:
116
116
sections .append (
117
117
TextSection (link = topic_url , text = parse_html_page_basic (post ["cooked" ]))
118
118
)
119
- category_name = self .category_id_map .get (topic ["category_id" ])
119
+ category_name = self .category_id_map .get (topic ["category_id" ], {}). get ( "name" )
120
120
121
121
metadata : dict [str , str | list [str ]] = (
122
122
{
@@ -158,9 +158,10 @@ def _get_latest_topics(
158
158
topics = []
159
159
empty_categories = []
160
160
161
- for category_id in self .category_id_map .keys ():
161
+ for category_id , category_dict in self .category_id_map .items ():
162
162
category_endpoint = urllib .parse .urljoin (
163
- self .base_url , f"c/{ category_id } .json?page={ page } &sys=latest"
163
+ self .base_url ,
164
+ f"c/{ category_dict ['slug' ]} /{ category_id } .json?page={ page } &sys=latest" ,
164
165
)
165
166
response = self ._make_request (endpoint = category_endpoint )
166
167
new_topics = response .json ()["topic_list" ]["topics" ]
0 commit comments