Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 22 additions & 2 deletions auto-selfcontrol.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,15 @@ def load_config(path):
exit_with_error("The JSON config file {configfile} is not correctly formatted."
"The following exception was raised:\
\n{exc}".format(configfile=path, exc=exception))

if config.get("host-blacklist-paths",None) is not None:
# add to config["host-blacklist"] if it exists
blacklist = set(config["host-blacklist"]) if config.get("host-blacklist", None) is not None else set()
for blacklist_filename in config["host-blacklist-paths"]:
blacklist_location = os.path.realpath(os.path.join(os.getcwd(),blacklist_filename))
with open(blacklist_location,"rt") as bl:
for host in bl:
blacklist.add(host.strip())
config["host-blacklist"] = list(blacklist)
return config


Expand Down Expand Up @@ -247,8 +255,20 @@ def get_end_date_of_schedule(schedule):


def get_schedule_weekdays(schedule):

"""Return a list of weekdays the specified schedule is active."""
return [schedule["weekday"]] if schedule.get("weekday", None) is not None else range(1, 8)
if schedule.get("weekday", None) is not None:
if schedule["weekday"] == "weekdays":
return range(1,6)
elif schedule["weekday"] == "weekends":
return range(6,8)
elif type(schedule["weekday"]) == list:
return schedule["weekday"]
elif type(schedule["weekday"]) == int:
return [schedule["weekday"]]
else:
return range(1,8)



def set_selfcontrol_setting(key, value, username):
Expand Down
93 changes: 36 additions & 57 deletions config.json
Original file line number Diff line number Diff line change
@@ -1,59 +1,38 @@
{
"username": "MY_USERNAME",
"selfcontrol-path": "/Applications/SelfControl.app",
"host-blacklist": [
"twitter.com",
"reddit.com"
],
"block-schedules":[
{
"weekday": 1,
"start-hour": 8,
"start-minute": 0,
"end-hour": 17,
"end-minute": 0
},
{
"weekday": 2,
"start-hour": 8,
"start-minute": 0,
"end-hour": 17,
"end-minute": 0
},
{
"weekday": 3,
"start-hour": 8,
"start-minute": 0,
"end-hour": 17,
"end-minute": 0
},
{
"weekday": 4,
"start-hour": 8,
"start-minute": 0,
"end-hour": 17,
"end-minute": 0
},
{
"weekday": 5,
"start-hour": 8,
"start-minute": 0,
"end-hour": 17,
"end-minute": 0
},
{
"weekday": 6,
"start-hour": 8,
"start-minute": 0,
"end-hour": 17,
"end-minute": 0
},
{
"weekday": 7,
"start-hour": 8,
"start-minute": 0,
"end-hour": 17,
"end-minute": 0
}
]
"username": "shiv",
"selfcontrol-path": "/Applications/SelfControl.app",
"host-blacklist": [],
"host-blacklist-paths": [
"blacklist.txt"
],
"block-schedules": [
{
"weekday": "weekdays",
"start-hour": 10,
"start-minute": 0,
"end-hour": 13,
"end-minute": 0
},
{
"weekday": "weekdays",
"start-hour": 14,
"start-minute": 30,
"end-hour": 18,
"end-minute": 0
},
{
"weekday": "weekdays",
"start-hour": 20,
"start-minute": 0,
"end-hour": 22,
"end-minute": 0
},
{
"weekday": "weekends",
"start-hour": 10,
"start-minute": 0,
"end-hour": 13,
"end-minute": 0
}
]
}