Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

Created April 7, 2016 18:32
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/c85adb6e7b3589cd18918ae828cfccda to your computer and use it in GitHub Desktop.
Save anonymous/c85adb6e7b3589cd18918ae828cfccda to your computer and use it in GitHub Desktop.
New code for Flickr picture frame
#!/usr/bin/env python
import flickrapi
import requests
import os
import re
FLICKR_KEY = "your api key"
FLICKR_SECRET = "your secret"
USER_ID = "your user id"
SET_ID = "the set (album) id"
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 " ---> Restarting slideshow"
os.system("killall feh && /home/pi/bin/script_slideshow.sh")
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment