Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions Website Blocker/read.me → Website Blocker/README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
# Description
This is real world program which blocks certain distracting website like Facebook,
Youtube etc during your work hours. About the program : What we are going to in this
program is that we will pass the link of websites which you think is distracting and the
time that you are working on your computer and program will block those website.
Program Architecture:
for mac:-
1. Every system have host file whether it is Mac, Windows or Linux.
Host file in Mac and Linux : "/etc/hosts"\

>Program Architecture:
Every system have host file whether it is Mac, Windows or Linux.
1. for mac: Host file in Mac and Linux : "/etc/hosts"\
2. for windows:-
C:\Windows\System32\drivers\etc\hosts

## Usage
Insert working hours, and blacklisted websties in the script. The run:

> python web_blocker.py

for windows:-
C:\Windows\System32\drivers\etc
45 changes: 45 additions & 0 deletions Website Blocker/cross-platform/web_blocker.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import time
import platform
from datetime import datetime as dt

# Detect OS and set hosts path
if platform.system() == "Windows":
hosts_path = r"C:\Windows\System32\drivers\etc\hosts"
else:
hosts_path = "/etc/hosts"

redirect = "127.0.0.1"

website_list = [
"www.facebook.com", "facebook.com"]

START_HOUR = 8
END_HOUR = 16

while True:
now = dt.now()
start = dt(now.year, now.month, now.day, START_HOUR)
end = dt(now.year, now.month, now.day, END_HOUR)

if start < now < end:
print("Working hours...")

with open(hosts_path, "r+") as file:
content = file.read()

for website in website_list:
if website not in content:
file.write(f"{redirect} {website}\n")

else:
with open(hosts_path, "r+") as file:
content = file.readlines()
file.seek(0)

for line in content:
if not any(website in line for website in website_list):
file.write(line)

file.truncate()

time.sleep(3600) # Check every hour