Last active
December 19, 2015 02:38
-
-
Save sebmaynard/5884045 to your computer and use it in GitHub Desktop.
Generate an images-only feed for the Dilbert comic.
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
# update dilbert rss every morning at 2am | |
0 2 * * * /home/user/bin/update_dilbert.sh |
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 | |
# 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 = "http://www.dilbert.com" | |
feed = "http://feed.dilbert.com/dilbert/daily_strip" | |
rss = feedparser.parse(feed) | |
feed_updated = datetime.fromtimestamp(mktime(rss["feed"]["updated_parsed"])) | |
output = Atom1Feed(title=u"Dilbert Images Only", | |
link=base, | |
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"] | |
output.add_item(title=title, | |
link=link, | |
description="<a href='" + link + "'><img src='" + img_link + "' /></a>", | |
pubdate=parser.parse(entry["published"])) | |
print output.writeString('utf-8') | |
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 | |
cd /home/user/bin/ | |
python dilbert.py > /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