Skip to content

Commit

Permalink
Merge pull request #164 from mwoolweaver/master
Browse files Browse the repository at this point in the history
remove error prone total_changes function introduced in #158
  • Loading branch information
anudeepND authored Sep 2, 2020
2 parents 520566d + 95374ae commit 67fbf57
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 29 deletions.
25 changes: 9 additions & 16 deletions scripts/uninstall.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 ")
print("[i] There are a total of {} domains remaining in your exact whitelist" .format(len(remaining_domains.fetchall())))

cursor.close()

Expand Down
23 changes: 10 additions & 13 deletions scripts/whitelist.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 ")
#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:
Expand Down

0 comments on commit 67fbf57

Please sign in to comment.