seek ( 0 ) for host in hosts : if not any ( site in host for site in sites_to_block ): hostfile. write ( redirect ' ' site ' \n ' ) else : with open ( default_hoster, 'r ' ) as hostfile : hosts = hostfile. read () for site in sites_to_block : if site not in hosts : hostfile. " ) with open ( default_hoster, 'r ' ) as hostfile : hosts = hostfile. Ad blockers in the browser protect us from the most annoying marketing messages that the Internet tries to serve to us.751k members in the Python community. You can write a code using python that will block the mentioned websites on your computer. ondemandvideo, How to Build A Website Blocker With Python Website Blocker Python Project (28:00) ondemandvideo, Learn 2 Lines of Code for Python Program to. Import time from datetime import datetime as dt sites_to_block = Linux_host = '/etc/hosts' MacOs_host = '/private/etc/hosts' Window_host = r "C:\Windows\System32\drivers\etc\hosts" default_hoster = Linux_host redirect = "127.0.0.1" def block_websites ( start_hour, end_hour ): while True : if dt ( dt. Sharpen your coding chops with 42 creative projects in Python Follow this practical guide to learn the fundamentals of coding and take your development journey to the next level. Therefore we need to add those sites to the host files during working hours and removing them immediately when it’s going home time. The objective of Python website blocker is to block some certain websites which can distract the user during the specified amount of time. Instead of adding we are going to add 127.0.0.1 therefore whenever a user tries to access the website during working hours will be directed to the localhost. Project idea Build an application that can be used to block certain websites from opening. We will add website URLs which are mapped to localhost thus preventing from accessing the real site, for instance: Instead of adding 'we will add '127.0.0.1 Therefore we need to add those site. We will add website URLs to the host file and mapping them to the localhost thus preventing you from accessing the real site during working hours. Every operating system has a hosts file and it’s here where we are going to add list of websites we want to block. We are going to use the time and Datetime Module only which comes by default with the Python Standard Library therefore you don’t need to install anything.Įvery operating system has a host file and it’s on this file where we are going to add a list of websites we want to block by redirecting them to 127.0.0.1 (localhost). Learn Also: How to Send Emails using Python. It will block some mind destructive websites (users can set the list as per their requirements) permanently or temporarily(for a time duration: users can set the time as their choice). In this tutorial, you will learn and build your own website blocker to block certain selected sites that distract you during working hours. In this tutorial, we will create our own Website Blocker using Python to make this real-life problem grounded. Many of us struggle to focus nowadays, easily distracted by Social media and some sites on the internet which dramatically affecting our productivity.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |