Find file
Fetching contributors…
Cannot retrieve contributors at this time
executable file 61 lines (47 sloc) 1.91 KB
#!/usr/bin/env python
# vim: ai ts=4 sts=4 sw=4
"""PostgreSQL Planet Aggregator
This file contains simpler wrapper for getting the oauth credentials
to set up the twitter access.
Copyright (C) 2010 PostgreSQL Global Development Group
import sys
import oauth2 as oauth
import cgi
import ConfigParser
cfg = ConfigParser.ConfigParser()'planet.ini')
if not cfg.has_option('twitter', 'consumer') or not cfg.has_option('twitter', 'consumersecret'):
print "Before you can run this, you need to register an application at"
print " and put the consumer and consumersecret values"
print "in the [twitter] section of planet.ini."
consumer = oauth.Consumer(cfg.get('twitter', 'consumer'), cfg.get('twitter', 'consumersecret'))
client = oauth.Client(consumer)
resp, content = client.request("", "GET")
if resp['status'] != '200':
print "request_token call failed!"
print resp
req_token_cred = dict(cgi.parse_qsl(content))
print "Received request token."
print "Token secret: %s" % req_token_cred['oauth_token_secret']
print ""
print "Now, go to the following URL:"
print "" % req_token_cred['oauth_token']
print ""
pin = raw_input('Enter the PIN here:')
token = oauth.Token(req_token_cred['oauth_token'], req_token_cred['oauth_token_secret'])
client = oauth.Client(consumer, token)
# Put the PIN on the URL, because it seems to not work to use token.set_verifier()
resp, content = client.request('' % pin, "POST")
if resp['status'] != '200':
print "access_token failed!"
print resp
print content
r = dict(cgi.parse_qsl(content))
print "Access token received."
print "Token: %s" % r['oauth_token']
print "Secret: %s" % r['oauth_token_secret']
print "Record these two values in planet.ini, and you're good to go!"