blob: f3b21a631e176cf82443e3a4202a3e56991421ae (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
#!/usr/bin/env python3
# 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 cgi
import configparser
import requests_oauthlib
cfg = configparser.ConfigParser()
cfg.read('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("developer.twitter.com and put the consumer and consumersecret values")
print("in the [twitter] section of planet.ini.")
sys.exit(1)
oauth = requests_oauthlib.OAuth1Session(cfg.get('twitter', 'consumer'), cfg.get('twitter', 'consumersecret'), callback_uri='oob')
fetch_response = oauth.fetch_request_token('https://api.twitter.com/oauth/request_token')
auth_url = oauth.authorization_url('https://api.twitter.com/oauth/authorize')
print("Please go to {0} and log in".format(auth_url))
pin = input('Enter the PIN received here:')
oauth2 = requests_oauthlib.OAuth1Session(cfg.get('twitter', 'consumer'),
cfg.get('twitter', 'consumersecret'),
fetch_response.get('oauth_token'),
fetch_response.get('oauth_token_secret'),
verifier=pin)
tokens = oauth2.fetch_access_token('https://api.twitter.com/oauth/access_token')
print("Access token received.")
print("Register the following two valuesi n planet.ini under [twitter]:")
print("token={0}".format(tokens.get('oauth_token')))
print("secret={0}".format(tokens.get('oauth_token_secret')))
|