This is the core functionality of beproductive. A defined list of websites is added to the `hosts` file of the OS with a redirect to `127.0.0.1`.

class Blocker[source]

Blocker(redirect='127.0.0.1')

The core of the package. It modifies the hosts file of the OS.

Blocker.block[source]

Blocker.block(notify=False)

Blocks all specified websites by replacing hosts file with hosts.blocked

Blocker.unblock[source]

Blocker.unblock(notify=False)

Unblocks all websites by restoring the original hosts file

Blocker.notify[source]

Blocker.notify(message, title='Be Productive', duration=5)

Sends notification to CLI and - if available - to GUI

Using Blocker

import filecmp
blocker = Blocker()
blocker.blocklist
['twitter.com',
 'youtube.com',
 'facebook.com',
 'instagram.com',
 'reddit.com',
 'netflix.com',
 'amazon.com',
 'linkedin.com']
assert filecmp.cmp(host_fp, host_fp_copy) == True, "hosts file should be identical to hosts.original"
blocker.block()
'Websites blocked'
assert filecmp.cmp(host_fp, host_fp_blocked) == True, "hosts file should be identical to hosts.blocked"
blocker.unblock()
'Websites unblocked'
assert filecmp.cmp(host_fp, host_fp_copy) == True, "hosts file should be identical to hosts.original"