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: Difference between revisions

From WHATWG Wiki
Jump to navigation Jump to search
(Created page with 'WebAppsTweet is a simple script responsible for updating [http://twitter.com/WHATWG @WHATWG] on Twitter whenever the specification is changed. It is written on top of [https://gi...')
 
No edit summary
 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
WebAppsTweet is a simple script responsible for updating [http://twitter.com/WHATWG @WHATWG] on Twitter whenever the specification is changed. It is written on top of [https://github.com/ryanmcgrath/twython Twython]. This page documents most of its source code, which you are free to use for any purpose.
WebAppsTweet is a simple script responsible for updating [[Twitter|our Twitter account]] whenever the specification is changed. It is written on top of [https://github.com/ryanmcgrath/twython Twython]. This page documents most of its source code, which you are free to use for any purpose.


<pre>#!/usr/bin/python
<pre>#!/usr/bin/python
Line 24: Line 24:
     pass
     pass


if revision:
if revision and message != "typo" and message != "xref":
     shorturl = "http://html5.org/r/" + revision
     shorturl = "http://html5.org/r/" + revision
     message = shorturl + " — " + message
     message = shorturl + " — " + message

Latest revision as of 16:12, 29 October 2013

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."