feat: remove local data for nonexisting feeds

This commit is contained in:
knoflook 2022-01-28 12:18:19 +01:00
parent b1c9c05b6d
commit df19668260
Signed by untrusted user: knoflook
GPG Key ID: D6A1D0E8FC4FEF1C

View File

@ -194,13 +194,25 @@ def main():
if not os.path.exists(output_dir): if not os.path.exists(output_dir):
os.makedirs(output_dir) os.makedirs(output_dir)
feed_dict = dict()
for url in feed_urls:
feed_name = urlparse(url).netloc
feed_dict[url] = feed_name
feed_names = feed_dict.values()
content_dirs = os.listdir(output_dir)
for i in content_dirs:
if i not in feed_names:
shutil.rmtree(os.path.join(output_dir, i))
print("%s not in feeds_list.txt, removing local data" %(i))
# add iframe to the allowlist of feedparser's sanitizer, # add iframe to the allowlist of feedparser's sanitizer,
# this is now handled in parse_post() # this is now handled in parse_post()
feedparser.sanitizer._HTMLSanitizer.acceptable_elements |= {"iframe"} feedparser.sanitizer._HTMLSanitizer.acceptable_elements |= {"iframe"}
for feed_url in feed_urls: for feed_url in feed_urls:
feed_name = urlparse(feed_url).netloc feed_name = feed_dict[feed_url]
feed_dir = os.path.join(output_dir, feed_name) feed_dir = os.path.join(output_dir, feed_name)