Last active
August 29, 2015 14:02
-
-
Save tsaiid/cdabe03353be5811c8bb to your computer and use it in GitHub Desktop.
This file contains 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
import xml.etree.ElementTree as ET | |
import urllib2 | |
import re | |
import os | |
# remove current images | |
working_dir = os.path.dirname(os.path.realpath(__file__)) | |
for root, dirs, files in os.walk(working_dir, topdown=False): | |
for file in files: | |
if os.path.splitext(file)[1].lower() in ('.jpg', '.jpeg'): | |
full_path = os.path.join(root, file) | |
# print os.path.join(root, file) | |
os.remove(full_path) | |
# fetch rss | |
rss_url = 'http://feeds.feedburner.com/LargeFlickrInterestingnessFeedForWallpaper' | |
res = urllib2.urlopen(rss_url) | |
rss = res.read() | |
# fetch images | |
root = ET.XML(rss) | |
for item in root[0].iter('item'): | |
link = item.find('link').text | |
filename = re.split('\/', link)[-1] | |
jpg = urllib2.urlopen(link) | |
fh = open(working_dir + "/" + filename, 'w') | |
fh.write(jpg.read()) | |
fh.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment