Created
February 4, 2019 19:54
-
-
Save talfco/e5a7fd55aac694fd751fddd69db0ee55 to your computer and use it in GitHub Desktop.
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
def __init__(self, country_code): | |
self.__country_code = country_code | |
# Dependent on the country parameter load the relevant configurations | |
file_name = "config-"+country_code+".yaml" | |
with open("../../cfg/"+file_name, 'r') as stream: | |
try: | |
self.__cfg= yaml.load(stream) | |
print(self) | |
except yaml.YAMLError as exc: | |
print("Config File ", file_name, " wrong format", exc) | |
exit(1) | |
res = {} | |
# Reading the secret values from a local disk | |
with open("../../../secret/twitter.yaml", 'r') as stream: | |
try: | |
res= yaml.load(stream) | |
except yaml.YAMLError as exc: | |
print(exc) | |
exit(1) | |
consumer_key = res['apiKey'] | |
consumer_secret = res['apiSecretKey'] | |
access_token = res['accessToken'] | |
access_token_secret = res['accessSecretToken'] | |
# attempt authentication | |
try: | |
# create OAuthHandler object | |
auth = OAuthHandler(consumer_key, consumer_secret) | |
# set access token and secret | |
auth.set_access_token(access_token, access_token_secret) | |
# create tweepy API object to fetch tweets | |
self.__api = tweepy.API(auth) | |
except: | |
print("Error: Authentication Failed") | |
exit(1) | |
self.__extract_columns() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment