Skip to content

Instantly share code, notes, and snippets.

@bsag
Created June 15, 2013 15:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bsag/d03db67d5da66403e573 to your computer and use it in GitHub Desktop.
Save bsag/d03db67d5da66403e573 to your computer and use it in GitHub Desktop.
Script for Pelican/FeedPress users to ping Feedpress to update the feed and optionally also ping Pubsubhubbub hubs. You need to be a Premiumn FeedPress subscriber for this to work. You could run this independently after generating the site, or else call it from the Makefile after uploading your site. I store my FeedPress key and token (here refe…
#!/usr/bin/env python
import os
import requests
feed = "http://www.rousette.org.uk/blog/feeds/recent_articles.xml"
feedname = "butshesagirl"
# Get key and token from environment variables
# then make the request to FeedPress
mykey = os.environ['URILV_KEY']
mytoken = os.environ['URILV_TOKEN']
feedpress = "http://api.feedpress.it/feeds/ping.json"
payload = {'key': mykey, 'token': mytoken, 'feed': feedname}
r_feedpress = requests.get(feedpress, params=payload)
ping = r_feedpress.json()
if r_feedpress.status_code == 200:
print("==> {0}".format(ping['message']))
else:
print("!! Error: {:d}. {1}".format(ping['code'], ping['message']))
# Now ping Superfeedr and Appspot to inform of new content
# This is useful if you have the Pubsubhubbub option checked
# in FeedPress
appspot = "http://pubsubhubbub.appspot.com/"
superfeedr = "http://pubsubhubbub.superfeedr.com/"
payload = {'hub.mode': 'publish', 'hub.url': feed}
for feed in (appspot, superfeedr):
req = requests.post(feed, params=payload)
if req.status_code == 204:
print("==> Pinged {0}".format(feed))
else:
print("!! Error: {:d}. Could not ping {1}".format(req.status_code, feed))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment