Fix category counting error

This commit is contained in:
asdf 2021-07-21 20:22:45 +10:00
parent 29e7e3addd
commit dbb63f8332
1 changed files with 6 additions and 3 deletions

View File

@ -179,7 +179,7 @@ class LinkData:
for record in self.link_data:
name = record[4]
timestamp = record[2]
if name != "":
if name != "": # only replies have column 4 empty
if name not in [cat_record["name"] for cat_record in self.categories]:
self.categories.append(
{"name": name, "count": 1, "last_updated": timestamp}
@ -197,9 +197,12 @@ class LinkData:
except KeyError:
continue
parent_cat_name = parent_record[4]
if parent_cat_name not in [cat_record["name"] for cat_record in self.categories]:
if parent_cat_name not in [
cat_record["name"] for cat_record in self.categories
]:
self.categories.append(
{"name": parent_cat_name, "count": 1, "last_updated": timestamp}
# append a record, but set the count to 0 because the parent record will be counted at some stage
{"name": parent_cat_name, "count": 0, "last_updated": timestamp}
)
else:
for cat_record in self.categories: