chg: [tools] better feed list for misp-website

pull/9098/head
Christophe Vandeplas 2023-05-21 09:23:21 +02:00
parent dbf827f536
commit 571789a7d7
No known key found for this signature in database
GPG Key ID: BDC48619FFDC5A5B
1 changed files with 29 additions and 1 deletions

View File

@ -7,6 +7,7 @@
# General Public License v3.0
#
# Copyright (C) 2017 Alexandre Dulaunoy
# Copyright (C) 2023 Christophe Vandeplas
import json
@ -17,6 +18,33 @@ with open(default_feed) as feed_file:
feedlist = json.load(feed_file)
items = []
for feed in feedlist:
output = "- [{}]({}) - {} - feed format: {}".format(feed['Feed']['name'], feed['Feed']['url'],feed['Feed']['provider'],feed['Feed']['source_format'])
print (output)
items.append(output)
items = sorted(items, key=lambda s: s.casefold())
print("Updating misp-website feed.md file.")
start_header_seen = False
inserted = False
with open('../../../misp-website/content/feeds.md', 'r') as f:
data_new = []
for line in f:
if start_header_seen and line.startswith('- ') and not inserted: # first item
# add new content
for item in items:
data_new.append(item)
inserted = True
elif start_header_seen and line.startswith('- '): # continue skipping
continue
else:
data_new.append(line.strip())
if inserted and line.startswith("#"):
start_header_seen = False
if line.startswith("## Default feeds"):
start_header_seen = True
with open('../../../misp-website/content/feeds.md', 'w') as f:
f.write('\n'.join(data_new))