A powerful and simple Python script designed to improve productivity by blocking distracting websites (like Facebook, YouTube, etc.) during specific working hours. The script modifies the system's hosts file to redirect unwanted traffic.
- Time-Based Blocking: Automatically blocks websites during "Work Hours" and unblocks them during "Free Time."
- Customizable List: Easily add or remove websites from the block list.
- Platform Independent: Works on Windows, macOS, and Linux.
- Local Execution: No external software or browser extensions required.
- Language: Python 3.x
- Module Used:
time,datetime(Standard Python libraries). - System Logic: File I/O operations on the system's
hostsfile.
The script runs in the background and checks the current time:
- During Work Hours: It adds the distracting websites' URLs to the
hostsfile, mapping them to127.0.0.1(localhost). - During Free Time: It removes those lines from the
hostsfile, allowing normal access.
You need Administrative/Root privileges to run this script because it modifies system files.
- Clone the repository:
git clone [https://github.com/wajiharubab648-coder/website-blocker.git](https://github.com/wajiharubab648-coder/website-blocker.git)
2. **Run the script as Administrator:**
```bash
python website_blocker.py
- Create a System Tray icon for easy on/off toggle.
- Add a simple GUI using Tkinter for managing the block list.
- Support for temporary "Focus Sessions" (Pomodoro style).
- Understanding how the Operating System handles DNS and the
hostsfile. - Working with Python's file handling (
r+mode) to read and write simultaneously. - Handling system-level permissions and background execution.
Developed by Wajiha | BSIT Student | Learning Python & Problem Solving