Commit 539c5244 authored by rdecoupe's avatar rdecoupe
Browse files

exception handling

parent 629cf088
......@@ -7,13 +7,36 @@ Connect to Twitter stream using Twitter API and filter tweets which have to be r
To install and run this script : please follow instructions from README.md
"""
try :
import tweepy
import sys
def exitscript():
print("The program encountered an error.\nEnd of execution")
sys.exit(1)
try:
import credentials
except ImportError:
print('it seems there is no file named :"credentials.py"')
raise ImportError('it seems there is no file named :"credentials.py"')
exitscript()
if __name__ == '__main__':
print("Collect tweets : start")
print("Collect tweets : end")
\ No newline at end of file
# Access and authorize on MOOD twitter Account
try:
auth = tweepy.OAuthHandler(credentials.consumer_key, credentials.consumer_secret)
auth.set_access_token(credentials.access_token, credentials.access_token_secret)
api = tweepy.API(auth)
# Get the User object for twitter...
user = api.get_user('twitter')
print(user.screen_name)
except tweepy.TweepError as twe:
print("Wrong credentials: please check credentials.py ")
except Exception as e:
print("Please double check credentials.py :" + e)
finally:
exitscript()
print("Collect tweets : end")
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment