From 5b83737783a4102a4125293d99d78e51b082c3f7 Mon Sep 17 00:00:00 2001 From: mwoolweaver Date: Wed, 2 Sep 2020 10:47:08 -0500 Subject: [PATCH 1/2] remove error prone total_changes function introduced in #158 also fix merge issue of #163 --- scripts/uninstall.py | 25 +++++++++---------------- scripts/whitelist.py | 23 ++++++++++------------- 2 files changed, 19 insertions(+), 29 deletions(-) diff --git a/scripts/uninstall.py b/scripts/uninstall.py index 23f8734..ca3a04e 100755 --- a/scripts/uninstall.py +++ b/scripts/uninstall.py @@ -154,26 +154,19 @@ def restart_pihole(docker): sqliteConnection = sqlite3.connect(gravity_db_location) cursor = sqliteConnection.cursor() print('[i] Successfully Connected to Gravity database') - total_domains = cursor.execute( - " SELECT * FROM domainlist WHERE type = 0 AND comment LIKE '%qjz9zk%' ") - print("[i] There are a total of {} domains in your whitelist which are added by my script" .format( - len(total_domains.fetchall()))) + total_domains = cursor.execute(" SELECT * FROM domainlist WHERE type = 0 AND comment LIKE '%qjz9zk%' ") + + totalDomains = len(total_domains.fetchall()) + print("[i] There are a total of {} domains in your whitelist which are added by my script" .format(totalDomains)) print('[i] Removing domains in the Gravity database') - cursor.execute( - " DELETE FROM domainlist WHERE type = 0 AND comment LIKE '%qjz9zk%' ") + cursor.execute (" DELETE FROM domainlist WHERE type = 0 AND comment LIKE '%qjz9zk%' ") sqliteConnection.commit() - # total_changes is returning 2x the actual value. ¯\_(ツ)_/¯ - # if I made a mistake, please create a PR - numberOfDomains = sqliteConnection.total_changes - if numberOfDomains > 1: - numberOfDomains = numberOfDomains // 2 - print("[i] {} domains are removed" .format(numberOfDomains)) - remaining_domains = cursor.execute( - " SELECT * FROM domainlist WHERE type = 0 OR type = 2 ") - print("[i] There are a total of {} domains remaining in your whitelist" .format( - len(remaining_domains.fetchall()))) + # we only removed domains we added so use total_domains + print("[i] {} domains are removed" .format(totalDomains)) + remaining_domains = cursor.execute(" SELECT * FROM domainlist WHERE type = 0 OR type = 2 ") # only show exact whitelisted domains as we don't add/remove regex + print("[i] There are a total of {} domains remaining in your exact whitelist" .format(len(remaining_domains.fetchall()))) cursor.close() diff --git a/scripts/whitelist.py b/scripts/whitelist.py index bf7d1cc..7094715 100755 --- a/scripts/whitelist.py +++ b/scripts/whitelist.py @@ -166,19 +166,16 @@ def restart_pihole(docker): sqliteConnection.commit() - # total_changes is returning 2x the actual value. ¯\_(ツ)_/¯ - # if I made a mistake, please create a PR - numberOfDomains = sqliteConnection.total_changes - if numberOfDomains > 1: - numberOfDomains = numberOfDomains // 2 - # print(f'[i] {numberOfDomains} domains are added to whitelist out of {len(whitelist_remote)}') - print("[i] {} domains are added to whitelist out of {}" .format( - numberOfDomains, len(whitelist_remote))) - total_domains = cursor.execute( - " SELECT * FROM domainlist WHERE type = 0 OR type = 2 ") - # print(f'[i] There are a total of {len(total_domains.fetchall())} domains in your whitelist') - print("[i] There are a total of {} domains in your whitelist" .format( - len(total_domains.fetchall()))) + # find only the domains we added + number_domains = cursor.execute(" SELECT * FROM domainlist WHERE type = 0 AND comment LIKE '%qjz9zk%' ") + + numberDomains = len(number_domains.fetchall()) + + #print(f'[i] {numberOfDomains} domains are added to whitelist out of {len(whitelist_remote)}') + print("[i] {} domains are added to whitelist out of {}" .format(numberDomains, len(whitelist_remote))) + total_domains = cursor.execute(" SELECT * FROM domainlist WHERE type = 0 OR type = 2 ") # only show exact whitelisted domains as we don't add/remove regex + #print(f'[i] There are a total of {len(total_domains.fetchall())} domains in your whitelist') + print("[i] There are a total of {} domains in your whitelist" .format(len(total_domains.fetchall()))) cursor.close() except sqlite3.Error as error: From 95374ae5c9090ccb3284fb0f191e29663872a081 Mon Sep 17 00:00:00 2001 From: mwoolweaver Date: Wed, 2 Sep 2020 10:53:00 -0500 Subject: [PATCH 2/2] remove comment in code --- scripts/uninstall.py | 2 +- scripts/whitelist.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/uninstall.py b/scripts/uninstall.py index ca3a04e..e56dd73 100755 --- a/scripts/uninstall.py +++ b/scripts/uninstall.py @@ -165,7 +165,7 @@ def restart_pihole(docker): # we only removed domains we added so use total_domains print("[i] {} domains are removed" .format(totalDomains)) - remaining_domains = cursor.execute(" SELECT * FROM domainlist WHERE type = 0 OR type = 2 ") # only show exact whitelisted domains as we don't add/remove regex + remaining_domains = cursor.execute(" SELECT * FROM domainlist WHERE type = 0 OR type = 2 ") print("[i] There are a total of {} domains remaining in your exact whitelist" .format(len(remaining_domains.fetchall()))) cursor.close() diff --git a/scripts/whitelist.py b/scripts/whitelist.py index 7094715..f329d6c 100755 --- a/scripts/whitelist.py +++ b/scripts/whitelist.py @@ -173,7 +173,7 @@ def restart_pihole(docker): #print(f'[i] {numberOfDomains} domains are added to whitelist out of {len(whitelist_remote)}') print("[i] {} domains are added to whitelist out of {}" .format(numberDomains, len(whitelist_remote))) - total_domains = cursor.execute(" SELECT * FROM domainlist WHERE type = 0 OR type = 2 ") # only show exact whitelisted domains as we don't add/remove regex + total_domains = cursor.execute(" SELECT * FROM domainlist WHERE type = 0 OR type = 2 ") #print(f'[i] There are a total of {len(total_domains.fetchall())} domains in your whitelist') print("[i] There are a total of {} domains in your whitelist" .format(len(total_domains.fetchall()))) cursor.close()