Skip to content

Instantly share code, notes, and snippets.

Last active Dec 19, 2015
What would you like to do?
Generate an images-only feed for the Dilbert comic.
# update dilbert rss every morning at 2am
0 2 * * * /home/user/bin/
#!/usr/bin/env python
# quick install for the dependencies:
# apt-get install python-pip python-dateutil
# pip install beautifulsoup4 requests feedparser webhelpers
import requests
from bs4 import BeautifulSoup
import feedparser
from webhelpers.feedgenerator import Atom1Feed
from datetime import datetime
from time import mktime
from dateutil import parser
base = ""
feed = ""
rss = feedparser.parse(feed)
feed_updated = datetime.fromtimestamp(mktime(rss["feed"]["updated_parsed"]))
output = Atom1Feed(title=u"Dilbert Images Only",
description=u"Get the dilbert images")
for entry in rss["entries"]:
link = entry["link"]
title = entry["title"]
soup = BeautifulSoup(requests.get(entry["link"]).content)
img_wrapper = soup.findAll("div", {'class': 'STR_Image' })[0]
img_link = base + img_wrapper.find("img")["src"]
description="<a href='" + link + "'><img src='" + img_link + "' /></a>",
print output.writeString('utf-8')
cd /home/user/bin/
python > /home/user/public_html/other/dilbert.xml
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment