-
Notifications
You must be signed in to change notification settings - Fork 0
/
twitter_login.py
38 lines (29 loc) · 1.11 KB
/
twitter_login.py
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
#!/usr/bin/python
# -*- coding: utf-8 -*-
__author__ = "Wei Wang"
__email__ = "tskatom@vt.edu"
import os
import twitter
from twitter.oauth import write_token_file, read_token_file
from twitter.oauth_dance import oauth_dance
def login():
#loging to twitter application
APP_NAME = "Finance_Harvest"
CONSUMER_KEY = "Bkvk7JFZmzaVpLjGAWBtxQ"
CONSUMER_SECRET = "y9tugnYJeU8aMNW44o6hwWHC3QVktCYtW3RDm3Mdk"
TOKEN_FILE = 'out/twitter.oauth'
try:
(oauth_token, oauth_token_secret) = read_token_file(TOKEN_FILE)
except IOError, e:
print e.errno, e.strerror
(oauth_token, oauth_token_secret) = oauth_dance(
APP_NAME, CONSUMER_KEY, CONSUMER_SECRET)
if not os.path.isdir('out'):
os.mkdir('out')
write_token_file(TOKEN_FILE, oauth_token, oauth_token_secret)
return twitter.Twitter(domain='api.twitter.com', api_version='1.1',
auth=twitter.oauth.OAuth(
oauth_token, oauth_token_secret,
CONSUMER_KEY, CONSUMER_SECRET))
if __name__ == "__main__":
login()