Created
April 7, 2016 18:34
-
-
Save Jarvl/3799acac27283f80641d57804faac9ae to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import flickrapi | |
import requests | |
import os | |
import re | |
FLICKR_KEY = "your api key" | |
FLICKR_SECRET = "your api 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() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
export DISPLAY=:0.0 | |
XAUTHORITY=/home/pi/.Xauthority | |
feh -q -Z -F -z -Y -D 5 /home/pi/photoframe/flickr |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Everytime I try to run these commands:
I get the error below:
feh ERROR: CAn't open X display. It *is* running, yeah?
Any suggestions would be much appreciated!
-Pi & Linux Newbie