I am writing a personal assistant in Python 3 for changing wallpaper in macOS. I am getting some error. So help me with this process.

I tried with this code gven below but at first I got:

"IsADirectoryError: [Errno 21] Is a directory:'/Users/suryakantkumar/SofiaAssistant/wallpaper/'" error.

Then after putting a file in directory, it said:

Say something...

You said: change wallpaper

wallpaper changed successfully

But wallpaper didn't changed.

elif 'change wallpaper' in command:
    folder = '/Users/suryakantkumar/SofiaAssistant/wallpaper/'
    for the_file in os.listdir(folder):
        file_path = os.path.join(folder, the_file)
        try:
            if os.path.isfile(file_path):
                os.unlink(file_path)
        except Exception as e:
            print(e)
    api_key = 'fd66364c0ad9e0f8aabe54ec3cfbed0a947f3f4014ce3b841bf2ff6e20948795'
    url = 'https://api.unsplash.com/photos/random?client_id=' + api_key #pic from unspalsh.com
    #f = urllib2.urlopen(url)
    f = urlopen(url)
    json_string = f.read()
    f.close()
    parsed_json = json.loads(json_string)
    photo = parsed_json['urls']['full']
    urllib.request.urlretrieve(photo, '/Users/suryakantkumar/SofiaAssistant/wallpaper/File16') # Location where we download the image to.
    subprocess.call(["killall Dock"], shell=True)
    sofiaResponse('wallpaper changed successfully')

I expected that wallpaper will change but it didn't happened.

0 Answers