A user account is required in order to edit this wiki, but we've had to disable public user registrations due to spam.

To request an account, ask an autoconfirmed user on Chat (such as one of these permanent autoconfirmed members).

WebAppsTweet

From WHATWG Wiki
Jump to navigation Jump to search

WebAppsTweet is a simple script responsible for updating our Twitter account whenever the specification is changed. It is written on top of Twython. This page documents most of its source code, which you are free to use for any purpose.

#!/usr/bin/python
# coding=UTF-8

# The parameters passed are rev/message/flags/bug/level

import cgi
from twython import Twython

consumer_key = "..."
consumer_secret = "..."
oauth_token = "..."
oauth_secret = "..."

form = cgi.FieldStorage()
revision = ""
message = ""

try:
    revision = form["rev"].value
    message = form["message"].value
except:
    pass

if revision and message != "typo" and message != "xref":
    shorturl = "http://html5.org/r/" + revision
    message = shorturl + " — " + message
    if len(message) > 140:
        message = message[:139] + "…"

    twitter = Twython(
      twitter_token = consumer_key,
      twitter_secret = consumer_secret,
      oauth_token = oauth_token,                               
      oauth_token_secret = oauth_secret
    )
    print "Content-Type:text/plain\n"
    print twitter.updateStatus(status=message)
else:
    print "Content-Type:text/plain\n"
    print "Not today. Not today."