Refactor Website Blocker: OOP design, improved reliability, and better user interaction#564
Refactor Website Blocker: OOP design, improved reliability, and better user interaction#564AhmadAL-Quraan wants to merge 19 commits into
Conversation
Updated README.md to enhance project description, features, usage instructions, and improvements.
…raan/Python-Scripts into improve-web_blocker-structure
AhmadAL-Quraan
left a comment
There was a problem hiding this comment.
Suggestions + mistakes
| # ---------------------------- | ||
| # Blocking logic | ||
| # ---------------------------- | ||
| def block_websites(self) -> None: |
There was a problem hiding this comment.
block_websites checks if entry not in content, which guards against duplicate lines within a single file, but it appends without ever sorting or namespacing the block, so the hosts file accumulates whatever ordering happens to occur from prior runs with different site lists. If someone runs this with ["facebook.com"] today and ["twitter.com"] tomorrow, both lists are still partially present and there's no anchor (no # BEGIN/END blocker markers) to cleanly identify and strip "everything this script ever wrote."
| # ---------------------------- | ||
| # Unblocking logic | ||
| # ---------------------------- | ||
| def unblock_websites(self) -> None: |
There was a problem hiding this comment.
unblock_websites only removes lines containing strings from the current self.websites set, so any site blocked in a previous session with a different website list is now orphaned in /etc/hosts forever, with no command to list or clean it up. That's a real bug, not a style nit: it leaves the system in a state the user can't easily recover from without manually editing the hosts file.
| # ---------------------------- | ||
| # Time logic | ||
| # ---------------------------- | ||
| def is_working_hours(self) -> bool: |
There was a problem hiding this comment.
Suggestion: working-hours logic doesn't account for weekends, timezones, or DST, and there's no day-of-week parameter despite this being pitched as a "work hours" blocker. That's a product gap I'd want flagged even if it's out of scope for this PR — at minimum it deserves a TODO and a docstring caveat.
PR Title
Refactor Website Blocker: OOP design, improved reliability, and better user interaction
Summary
Closes #562
This PR improves the website blocker implementation by refactoring the code into a modular, object-oriented design and enhancing reliability, usability, and maintainability.
Description
This change builds on the existing implementation by improving the internal structure and addressing several limitations in the current script.
The previous implementation relied on a procedural approach with limited error handling and responsiveness. This PR restructures the code into a class-based design, improves user interaction, and ensures safer handling of system modifications.
The changes are as follows:
WebsiteBlockerclass to improve structure and maintainabilityflake8andmypychecksChecks
in the repository
in the PR
Thank You,
Ahmad AL-Quraan