added some docstrings and comments

This commit is contained in:
Tobias Diekershoff 2023-01-07 21:27:16 +01:00
parent 22c275391d
commit b333d0c989
1 changed files with 19 additions and 0 deletions

View File

@ -5,6 +5,8 @@
"""
This script can be used to create server block lists by compining the blocklists
of any number of other Friendica instances.
See https://git.friendi.ca/tobias/brewserverblocklist
"""
import argparse
import configparser
@ -51,6 +53,9 @@ class BrewBlocklist():
try:
pattern, reason = line.split(',')
except ValueError:
# happens in an empty line in the source CSV file, which seems
# to be the last line of the file so we can just break the loop
# one step early and ignore the exception silently.
break
self.blocklist[pattern] = self.blocklist.get(pattern, 0) + source['trust']
self.reasons[pattern] = self.reasons.get(pattern, reason)
@ -88,6 +93,10 @@ class BrewBlocklist():
"""
Print the CSV list of the collected blocklist into either STDOUT or
the output file that was defined as command line parameter.
You can upload the resulting CSV file into Friendica from the admin
panel of your node. Only the 1st and 2nd column is important. The 3rd
column contains the total trust value for the blocklist entry.
"""
if self.outputfile:
out_file = open(self.outputfile, 'w')
@ -98,7 +107,17 @@ class BrewBlocklist():
if self.outputfile:
sys.stdout = orig_stdout
out_file.close()
def main():
"""
This will run the script.
* parse the command line arguments
* check the config file is actually there
* put the cauldron on the fireplace
* collect the ingredient
* serve the result
"""
parser = argparse.ArgumentParser()
parser.add_argument('-c', '--config',
dest='configfile',