Created
October 30, 2013 22:27
-
-
Save imjohsep/7241442 to your computer and use it in GitHub Desktop.
Twitter Oauth with Tweepy and ConfigParser
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import ConfigParser | |
import tweepy | |
Twitter Oauth with ConfigParseConfig = ConfigParser.ConfigParser() | |
Config.read('config.ini') | |
def ConfigSectionMap(section): | |
dict1 = {} | |
options = Config.options(section) | |
for option in options: | |
try: | |
dict1[option] = Config.get(section, option) | |
if dict1[option] == -1: | |
DebugPrint("skip: %s" % option) | |
except: | |
print("exception on %s!" % option) | |
dict1[option] = None | |
return dict1 | |
def oauth(): | |
consumer_key = ConfigSectionMap('Oauth')['key'] | |
consumer_secret = ConfigSectionMap('Oauth')['secret'] | |
access_token = ConfigSectionMap('Token')['access_token'] | |
access_token_secret = ConfigSectionMap('Token')['access_token_secret'] | |
auth = tweepy.OAuthHandler(consumer_key, consumer_secret) | |
auth.set_access_token(access_token, access_token_secret) | |
api = tweepy.API(auth) | |
user = api.get_user() | |
print user.screen_name | |
def main(): | |
oauth() | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment