mirror of
https://github.com/metafy-social/python-scripts.git
synced 2024-11-24 04:21:12 +00:00
parent
43fb12dba4
commit
edcbbeecfd
|
@ -1,22 +0,0 @@
|
|||
### About
|
||||
|
||||
A Python3 script to block certain websites.
|
||||
|
||||
### Setup
|
||||
|
||||
* Install Python3 from [here](https://python.org).
|
||||
* Open cmd/terminal
|
||||
* Navigate inside the ```scripts\Website Blocker``` directory.
|
||||
* Run using Python
|
||||
```bash
|
||||
sudo python admin.py
|
||||
```
|
||||
Note: Add your end time in the `admin.py` file.
|
||||
|
||||
Blocking:
|
||||
![img.png](assets/img.png)
|
||||
![img_2.png](assets/img_2.png)
|
||||
|
||||
Unblocking:
|
||||
![img_1.png](assets/img_1.png)
|
||||
![img_3.png](assets/img_3.png)
|
Binary file not shown.
Binary file not shown.
|
@ -1,7 +0,0 @@
|
|||
from datetime import datetime
|
||||
from start_website_blocker import Blocker
|
||||
|
||||
end_time = datetime(2021, 10, 1, 20) # y, m, d, h, min
|
||||
sites_to_block = ['www.facebook.com', 'facebook.com']
|
||||
block = Blocker(end_time, sites_to_block)
|
||||
block.block_websites()
|
Binary file not shown.
Before Width: | Height: | Size: 18 KiB |
Binary file not shown.
Before Width: | Height: | Size: 16 KiB |
Binary file not shown.
Before Width: | Height: | Size: 168 KiB |
Binary file not shown.
Before Width: | Height: | Size: 202 KiB |
|
@ -1,42 +0,0 @@
|
|||
# a simple script to block websites
|
||||
from datetime import datetime
|
||||
import sys
|
||||
|
||||
if sys.platform == 'win32':
|
||||
hosts_path = r"C:\Windows\System32\drivers\etc\hosts"
|
||||
else:
|
||||
hosts_path = '/private/etc/hosts'
|
||||
|
||||
redirect = "127.0.0.1"
|
||||
|
||||
|
||||
class Blocker:
|
||||
def __init__(self, time, block):
|
||||
self.time = time
|
||||
self.block = block
|
||||
|
||||
def block_websites(self):
|
||||
if datetime.now() < self.time:
|
||||
print("Block sites")
|
||||
with open(hosts_path, 'r+') as hostfile:
|
||||
hosts_content = hostfile.read()
|
||||
for site in self.block:
|
||||
if site not in hosts_content:
|
||||
hostfile.write(redirect + " " + site + "\n")
|
||||
else:
|
||||
print('Unblock sites')
|
||||
with open(hosts_path, 'r+') as hostfile:
|
||||
lines = hostfile.readlines()
|
||||
hostfile.seek(0)
|
||||
for line in lines:
|
||||
if not any(site in line for site in self.block):
|
||||
hostfile.write(line)
|
||||
hostfile.truncate()
|
||||
|
||||
|
||||
# sudo python main.py
|
||||
if __name__ == '__main__':
|
||||
end_time = datetime(2021, 10, 1, 20) # y, m, d, h, min
|
||||
sites_to_block = ['www.facebook.com', 'facebook.com']
|
||||
block = Blocker(end_time, sites_to_block)
|
||||
block.block_websites()
|
Loading…
Reference in New Issue
Block a user