We create a default blocklist.yaml file that stores the blocked URLs. It can be edited with command line arguments.

save_config[source]

save_config(urls:list=None, default=False)

save_config(default=True)
True

Read in the new config file:

load_config[source]

load_config()

blocklist = load_config()
blocklist
['twitter.com',
 'youtube.com',
 'facebook.com',
 'instagram.com',
 'reddit.com',
 'netflix.com',
 'amazon.com',
 'linkedin.com']

add_urls[source]

add_urls(urls)

Testing add_urls

save_config(default=True)

assert "testsite.com" not in load_config(), "testsite.com should not be in default blocked URLs"
add_urls("testsite.com")
assert "testsite.com" in load_config(), "testsite.com should have been added to config file"

add_urls(["moresites.com", "CapitalLetters.COM"])
assert "moresites.com" in load_config(), "URL list should have been added to config file"
assert "capitalletters.com" in load_config(), "URLs should have been converted to lower case"

save_config(default=True)
testsite.com has been added to the blocklist
moresites.com, capitalletters.com have been added to the blocklist
True

remove_urls[source]

remove_urls(urls)

Testing remove_urls

save_config(default=True)

assert "facebook.com" in load_config(), "facebook.com should be in default blocked URLs"
remove_urls("facebook.com")
assert "facebook.com" not in load_config(), "facebook.com should have been removed from config file"

remove_urls(["twitter.com", "YOUTUBE.COM"])
assert "twitter.com" not in load_config(), "URL list should have been removed from config file"
assert "youtube.com" not in load_config(), "URLs should have been converted to lower case"

save_config(default=True)
facebook.com has been removed from the blocklist
twitter.com, youtube.com have been removed from the blocklist
True

show_blocklist[source]

show_blocklist()