Created
August 4, 2009 14:56
-
-
Save abi/161289 to your computer and use it in GitHub Desktop.
Tweet your new blogposts on Wordpress with Web Hooks/Hookpress
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
# Python 2.5.2 powered by GAE | |
# | |
# Like a typical App Engine environment with req and resp objects. | |
# Make HTTP requests with: fetch (see App Engine documentation) | |
# | |
USERNAME = "username" | |
PASSWORD = "password" | |
STATUS = "[infinity symbol goes here] " + req.get("post_title") + " " + req.get("post_url") | |
from google.appengine.api import urlfetch | |
import base64 | |
import urllib | |
#This ensures that we don't tweet everytime the post is updated after the post is published | |
#Wordpress continues to call the publish_post hook even when published posts are simply updated | |
if req.get("post_date_gmt") == req.get("post_modified_gmt"): | |
form_fields = { "status": STATUS, "source": "HookPress" } | |
payload = urllib.urlencode(form_fields) | |
base64string = base64.encodestring('%s:%s' % (USERNAME, PASSWORD))[:-1] | |
authheader = "Basic %s" % base64string | |
url = "https://twitter.com/statuses/update.json" | |
result = urlfetch.fetch(url=url,payload=payload,method=urlfetch.POST, headers={"Authorization": authheader}) | |
if int(result.status_code) != 200: | |
resp.out.write("failure!") | |
resp.out.write("success!") | |
else: | |
resp.out.write("already tweeted this post.") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment