add some exception handling for problems
This commit is contained in:
parent
e0b30df10a
commit
f71425528e
|
@ -32,6 +32,7 @@ class BrewBlocklist():
|
|||
self.auto_accept = auto_accept
|
||||
self.auto_accept_direction = auto_accept_direction
|
||||
self.safe_harbor = []
|
||||
self.error = []
|
||||
config = configparser.RawConfigParser()
|
||||
config.read(configfile)
|
||||
for section in config.sections():
|
||||
|
@ -62,6 +63,9 @@ class BrewBlocklist():
|
|||
if source['type'] == 'friendica':
|
||||
# Friendica publishes the blocklist as CSV file
|
||||
requ = requests.get('https://{}/blocklist/domain/download'.format(source['url']))
|
||||
if not requ.status_code == requests.codes.ok:
|
||||
self.error.append('The request to {} failed'.format(sources['url']))
|
||||
break
|
||||
for line in requ.text.split('\n'):
|
||||
try:
|
||||
pattern, reason = line.split(',')
|
||||
|
@ -75,9 +79,15 @@ class BrewBlocklist():
|
|||
elif source['type'] == 'mastodon':
|
||||
# Mastodon has an API endpoint that contains the information
|
||||
requ = requests.get('https://{}//api/v1/instance/domain_blocks'.format(source['url']))
|
||||
if not requ.status_code == requests.codes.ok:
|
||||
self.error.append('The request to {} failed'.format(sources['url']))
|
||||
break
|
||||
try:
|
||||
for item in requ.json():
|
||||
self.blocklist[item['domain']] = self.blocklist.get(item['domain'], 0) + source['trust']
|
||||
self.reasons[item['domain']] = self.reasons.get(item['domain'], item['comment'])
|
||||
except:
|
||||
self.error.append('{} returned no valid json to the API call'.format(source['url']))
|
||||
else:
|
||||
raise ValueError('{} is not a supported node type, check your config file'.format(source['type']))
|
||||
|
||||
|
@ -129,6 +139,9 @@ class BrewBlocklist():
|
|||
if self.outputfile:
|
||||
sys.stdout = orig_stdout
|
||||
out_file.close()
|
||||
if len(self.error):
|
||||
print("\n\nWhile creating the blocklist the following problems occured:")
|
||||
print("\n".join(self.error))
|
||||
|
||||
def main():
|
||||
"""
|
||||
|
|
Loading…
Reference in a new issue