-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebsite_blocker.py
89 lines (52 loc) · 1.73 KB
/
website_blocker.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
from tkinter import *
from tkinter import ttk
import platform
import sv_ttk
import sys
import pywinstyles
import darkdetect
"""
Hosts Paths On Windows, Mac & Linux:
Windows: C:\Windows\System32\drivers\etc\hosts
Mac & Linux: /etc/hosts
"""
h_path = "ENTER HOSTS FILE PATH HERE"
redirect = "127.0.0.1"
website_arr = []
def web_add():
website_arr.append(website_entry.get())
print(website_arr)
def block():
path = open(h_path, "r+")
path_r = path.read()
for website in website_arr:
path.write(f"{redirect} {website}\n")
def unblock():
with open(h_path, "r+") as path:
path_r = path.readlines()
path.seek(0)
for line in path_r:
if not any(website in line for website in website_arr):
path.write(line)
path.truncate()
root = Tk()
root.title("Website Blocker by @SmashedFrenzy16")
title_label = ttk.Label(root, text="Website Blocker", font=("Arial", 48))
title_label.pack()
blank_label = ttk.Label(root, text="").pack()
website_entry = ttk.Entry(root, width=100)
website_entry.insert(0, "Enter website URL here")
website_entry.pack()
add_website = ttk.Button(root, text="Add", command=web_add)
add_website.pack()
blank_label2 = ttk.Label(root, text="").pack()
block_button = ttk.Button(root, text="Block", command=block)
block_button.pack(side=LEFT)
unblock_button = ttk.Button(root, text="Unblock", command=unblock)
unblock_button.pack(side=RIGHT)
sv_ttk.set_theme(darkdetect.theme())
if platform.system() == "Windows":
if sys.getwindowsversion().major == 10 and sys.getwindowsversion().build >= 22000:
if sv_ttk.get_theme() == "dark":
pywinstyles.change_header_color(root, "#000000")
root.mainloop()