Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
umr-tetis
MOOD
mood-tetis-tweets-collect
Commits
539c5244
Commit
539c5244
authored
Jun 09, 2020
by
rdecoupe
Browse files
exception handling
parent
629cf088
Changes
1
Hide whitespace changes
Inline
Side-by-side
collectTweets.py
View file @
539c5244
...
...
@@ -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.
\n
End 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"
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment