Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
comp90023-assignment-2
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Matthew O'Halloran
comp90023-assignment-2
Commits
2eac44f6
Commit
2eac44f6
authored
Apr 12, 2020
by
matt01671
Browse files
Options
Downloads
Patches
Plain Diff
added stream
parent
9739efcb
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
twitter_harvest/search/tweepy-search.py
+9
-8
9 additions, 8 deletions
twitter_harvest/search/tweepy-search.py
twitter_harvest/stream/tweepy-stream.py
+33
-0
33 additions, 0 deletions
twitter_harvest/stream/tweepy-stream.py
with
42 additions
and
8 deletions
twitter_harvest/search/tweepy-
test
.py
→
twitter_harvest/search/tweepy-
search
.py
+
9
−
8
View file @
2eac44f6
...
@@ -3,11 +3,6 @@ import tweepy
...
@@ -3,11 +3,6 @@ import tweepy
consumer_key
=
consumer_key
=
consumer_secret
=
consumer_secret
=
# OAuthHandler instance OAuth 2 Authentication
auth
=
tweepy
.
OAuthHandler
(
consumer_key
,
consumer_secret
)
api
=
tweepy
.
API
(
auth
)
def
get_tweets
(
query
,
count
=
300
):
def
get_tweets
(
query
,
count
=
300
):
# empty list to store parsed tweets
# empty list to store parsed tweets
...
@@ -30,6 +25,12 @@ def get_tweets(query, count = 300):
...
@@ -30,6 +25,12 @@ def get_tweets(query, count = 300):
t1
.
write
(
line
+
"
\n
"
)
t1
.
write
(
line
+
"
\n
"
)
return
tweets
return
tweets
def
main
():
# OAuthHandler instance OAuth 2 Authentication
auth
=
tweepy
.
OAuthHandler
(
consumer_key
,
consumer_secret
)
api
=
tweepy
.
API
(
auth
)
# creating object of TwitterClient Class
# creating object of TwitterClient Class
# calling function to get tweets
# calling function to get tweets
tweets
=
get_tweets
(
query
=
text
,
count
=
20000
)
tweets
=
get_tweets
(
query
=
text
,
count
=
20000
)
\ No newline at end of file
This diff is collapsed.
Click to expand it.
twitter_harvest/stream/tweepy-stream.py
0 → 100644
+
33
−
0
View file @
2eac44f6
import
tweepy
consumer_key
=
consumer_secret
=
#override tweepy.StreamListener to add logic to on_status
class
MyStreamListener
(
tweepy
.
StreamListener
):
def
on_status
(
self
,
status
):
print
(
status
.
text
)
def
on_error
(
self
,
status_code
):
if
status_code
==
420
:
#returning False in on_error disconnects the stream
return
False
# returning non-False reconnects the stream, with backoff.
def
main
():
# OAuthHandler instance OAuth 2 Authentication
auth
=
tweepy
.
OAuthHandler
(
consumer_key
,
consumer_secret
)
api
=
tweepy
.
API
(
auth
)
myStreamListener
=
MyStreamListener
()
myStream
=
tweepy
.
Stream
(
auth
=
api
.
auth
,
listener
=
myStreamListener
)
myStream
.
filter
(
track
=
[
'
python
'
])
if
__name__
==
"
__main__
"
:
main
()
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment