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
9739efcb
Commit
9739efcb
authored
Apr 12, 2020
by
matt01671
Browse files
Options
Downloads
Patches
Plain Diff
folder for twitter harvesting
parent
0a8f4a34
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
twitter_harvest/search/tweepy-test.py
+35
-0
35 additions, 0 deletions
twitter_harvest/search/tweepy-test.py
with
35 additions
and
0 deletions
twitter_harvest/search/tweepy-test.py
0 → 100644
+
35
−
0
View file @
9739efcb
import
tweepy
consumer_key
=
consumer_secret
=
# OAuthHandler instance OAuth 2 Authentication
auth
=
tweepy
.
OAuthHandler
(
consumer_key
,
consumer_secret
)
api
=
tweepy
.
API
(
auth
)
def
get_tweets
(
query
,
count
=
300
):
# empty list to store parsed tweets
tweets
=
[]
target
=
open
(
"
tweets.txt
"
,
'
w
'
,
encoding
=
"
utf-8
"
)
t1
=
open
(
"
review.txt
"
,
'
w
'
,
encoding
=
"
utf-8
"
)
# call twitter api to fetch tweets
fetched_tweets
=
api
.
search
(
query
,
count
=
count
)
# Other params, geocode, lang
for
tweet
in
fetched_tweets
:
# empty dictionary to store required params of a tweet
parsed_tweet
=
{}
# saving text of tweet
parsed_tweet
[
'
text
'
]
=
tweet
.
text
if
"
http
"
not
in
tweet
.
text
:
line
=
re
.
sub
(
"
[^A-Za-z]
"
,
"
"
,
tweet
.
text
)
target
.
write
(
line
+
"
\n
"
)
t1
.
write
(
line
+
"
\n
"
)
return
tweets
# creating object of TwitterClient Class
# calling function to get tweets
tweets
=
get_tweets
(
query
=
text
,
count
=
20000
)
\ No newline at end of file
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