Last active
February 13, 2024 16:29
-
-
Save Kapujino/03feaa159f72c84bbef37f3551cb069a to your computer and use it in GitHub Desktop.
This script adds a plain list of adlists to the adguard configuration AdGuardHome.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python3 | |
import yaml | |
# load AdGuardHome.yaml | |
with open('AdGuardHome.yaml', 'r') as file: | |
data = yaml.load(file, Loader=yaml.FullLoader) | |
# load file with adlist sources | |
with open('adlists.txt', 'r') as file: | |
urls = file.readlines() | |
new_entries = [] | |
starting_id = 3 # adjust the starting ID as needed | |
for url in urls: | |
url = url.strip() | |
new_filter = { | |
"enabled": True, | |
"url": url, | |
"name": url, | |
"id": starting_id | |
} | |
starting_id += 1 | |
new_entries.append(new_filter) | |
# append the new entries to the existing filters | |
data['filters'] += new_entries | |
# save the new AdGuardHome.yaml_migrated | |
with open('AdGuardHome.yaml_migrated', 'w') as file: | |
yaml.dump(data, file, default_flow_style=False) | |
print("new file created. please compare it to the old file.") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I did not find an easy solution to get the adlists from pihole, so i copied them from the webpage http://pi.hole/admin/groups-adlists.php and removed the unnecessary stuff with some regex.
Using the text editor vim you can use the following regex:
%s/\(https\:\/\/\|http\:\/\/\)\@!.//
this removes everything but http://* and https://*%s/^\s*\n//
this removes the empty lines%s/\t//g
this removes tabstopsYou can use any other method to get a clean list of your adlists.
Save this file as
adlists.txt
and put it together with this script andAdGuardHome.yaml
in one folder.ATTENTION: change
starting_id = 3
if you have already added adlists to adguard!Run the script
migrateAdlistToAdguard.py
to get a new adguard configuration calledAdGuardHome.yaml_migrated
.Carefully compare the previous configuration
AdGuardHome.yaml
with the new oneAdGuardHome.yaml_migrated
.Replace your old configuration if the changes are fine.