First Pi project. Sorry in advance.
I'm trying to setup a Flickr photoframe. i followed this instructable. When I boot the Raspberry Pi the slideshow is starting on its own. However, when I upload a new picture while this slideshow is running it closes, but it doesn't restart/reopen the slideshow script. How can i fix this?
This is the python script i'm using: (blanked out the keys)
#!/usr/bin/env python
import flickrapi
import requests
import os
import re
import time
FLICKR_KEY = "xxx"
FLICKR_SECRET = "xxx"
USER_ID = "xxx"
SET_ID = "xxx"
def make_url(photo):
# url_template = "http://farm{farm-id}.staticflickr.com/
# {server-id}/{id}_{secret}_[mstzb].jpg"
photo['filename'] = "%(id)s_%(secret)s_z.jpg" % photo
url = ("http://farm%(farm)s.staticflickr.com/%(server)s/%(filename)s"
% photo)
return url, photo['filename']
def main():
#get new imaged from flickr
print " ---> Requesting photos..."
count = 0
update = False
flickr = flickrapi.FlickrAPI(FLICKR_KEY, FLICKR_SECRET)
photos = flickr.walk_set(SET_ID)
for photo in photos:
count += 1
url, filename = make_url(photo.attrib)
path = '/home/pi/photoframe/flickr/%s' % filename
try:
image_file = open(path)
print " ---> Already have %s" % url
except IOError:
print " ---> Downloading %s" % url
r = requests.get(url)
image_file = open(path, 'w')
image_file.write(r.content)
image_file.close()
update = True
#check to see if it needs to remove photos from folder
filelist = os.listdir("/home/pi/photoframe/flickr")
if count < len(filelist):
print " ---> Removing photos"
for f in filelist:
pics = flickr.walk_set(SET_ID)
print f
for pic in pics:
url, filename = make_url(pic.attrib)
matchObj = re.match(f, filename)
if matchObj:
print " ---> Found %s, matched %s" %(f,filename)
break
else:
print " ---> Deleting %s" %f
os.remove("/home/pi/photoframe/flickr/%s" %f)
update = True
#if it added or removed a photo, update slideshow
if update == True:
print " ---> killing"
os.system("killall feh")
print " ---> sleep"
time.sleep( 5 )
print " ---> starting"
os.system("/home/pi/bin/script_slideshow.sh")
if __name__ == '__main__':
main()
os.system("kill all feh")
Python won't be able to launch yourscripy_slidedhow.sh
script because your Python process would have already been closed by then – Mohammad Ali May 05 '16 at 16:05"--->sleep"
? I'm guessing that it doesn't because the program has probably been killed by then. But if you expect more/better advice your going to need to post the terminal output that you get when you run your script, and what you did to create said output. – Mohammad Ali May 05 '16 at 16:07