andreasgrill / auto-selfcontrol

Small utility to schedule start and stop times of SelfControl
MIT License
305 stars 37 forks source link

getting errors when trying to run #4

Closed slambert closed 8 years ago

slambert commented 8 years ago

Tested a variety of ways to work this, but kept getting errors.

If I have a config.json like it is as default:

{
"username": "steve",
"selfcontrol-path": "/Applications/SelfControl.app",
"legacy-mode": true,
"host-blacklist": [
    "twitter.com",
    "reddit.com"
],
"block-schedules":[
    {
        "weekday": 1,
        "start-hour": 8,
        "start-minute": 0,
        "end-hour": 17,
        "end-minute": 0,
        "block-as-whitelist": false,
        "host-blacklist": null
    },

... etc ...

I get an error like this:

> Start installation of Auto-SelfControl
Uncaught exception:
<type 'exceptions.TypeError'>
'int' object is not iterable
Traceback (most recent call last):
  File "auto-selfcontrol.py", line 206, in <module>
    install(config)
  File "auto-selfcontrol.py", line 170, in install
    launchplist_script = get_launchscript(config)
  File "auto-selfcontrol.py", line 139, in get_launchscript
    </plist>'''.format(path=os.path.realpath(__file__), startintervals="".join(get_launchscript_startintervals(config)))
  File "auto-selfcontrol.py", line 145, in get_launchscript_startintervals
    for weekday in list(schedule["weekday"]) if schedule.get("weekday", None) is not None else range(1,8):
TypeError: 'int' object is not iterable

If I populate the host-blacklist instead of leaving it null:

{
"username": "steve",
"selfcontrol-path": "/Applications/SelfControl.app",
"legacy-mode": true,
"host-blacklist": [
    "twitter.com",
    "reddit.com"
],
"block-schedules":[
    {
        "weekday": 1,
        "start-hour": 8,
        "start-minute": 0,
        "end-hour": 17,
        "end-minute": 0,
        "block-as-whitelist": false,
        "host-blacklist": "twitter.com","facebook.com"
    },

... etc ...

And run the script I get:

Uncaught exception:
<type 'exceptions.ValueError'>
Expecting : delimiter: line 18 column 9 (char 469)
Traceback (most recent call last):
  File "auto-selfcontrol.py", line 201, in <module>
    config = load_config([os.path.join(__location__,"config.json")])
  File "auto-selfcontrol.py", line 23, in load_config
    config.update(json.load(cfg))
  File "/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/__init__.py", line 291, in load
    **kw)
  File "/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/__init__.py", line 339, in loads
    return _default_decoder.decode(s)
  File "/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/decoder.py", line 364, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/decoder.py", line 380, in raw_decode
    obj, end = self.scan_once(s, idx)
ValueError: Expecting : delimiter: line 18 column 9 (char 469)
andreasgrill commented 8 years ago

Oh my, thanks for pointing that out! I will fix this in a second. The second exception you are getting, however, might be because of the (second) config.json. I think there might be square brackets missing (e.g. "host-blacklist": ["twitter.com","facebook.com"]).