Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
T
Twint
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nanahira
Twint
Commits
0b634ad2
Commit
0b634ad2
authored
Apr 29, 2018
by
Cody Zacharias
Committed by
GitHub
Apr 29, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Create elasticsearch.py
parent
3848d8ab
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
126 additions
and
0 deletions
+126
-0
twint/elasticsearch.py
twint/elasticsearch.py
+126
-0
No files found.
twint/elasticsearch.py
0 → 100644
View file @
0b634ad2
from
elasticsearch
import
Elasticsearch
,
helpers
import
contextlib
import
datetime
import
time
class
RecycleObject
(
object
):
def
write
(
self
,
junk
):
pass
@
contextlib
.
contextmanager
def
nostdout
():
savestdout
=
sys
.
stdout
sys
.
stdout
=
RecycleObject
()
yield
sys
.
stdout
=
savestdout
def
weekday
(
day
):
weekdays
=
{
"Monday"
:
1
,
"Tuesday"
:
2
,
"Wednesday"
:
3
,
"Thursday"
:
4
,
"Friday"
:
5
,
"Saturday"
:
6
,
"Sunday"
:
7
,
}
return
weekday
[
day
]
def
Elastic
(
Tweet
,
config
):
# Todo play around with this some more
day
=
weekday
(
Tweet
.
date
.
strftime
(
"
%
A"
))
actions
=
[]
nLikes
=
0
nReplies
=
0
nRetweets
=
0
j_data
=
{
"_index"
:
"twint"
,
"_type"
:
"items"
,
"_id"
:
Tweet
.
id
+
"_raw"
,
"_source"
:
{
"id"
:
Tweet
.
id
,
"date"
:
Tweet
.
datestamp
,
"time"
:
Tweet
.
timestamp
,
"timezone"
:
Tweet
.
timezone
,
"tweet"
:
Tweet
.
tweet
,
"hashtags"
:
Tweet
.
hashtags
,
"username"
:
Tweet
.
username
,
"day"
:
day
,
"hour"
:
Tweet
.
time
.
strftime
(
"
%
H"
)
}
}
actions
.
append
(
j_data
)
for
l
in
range
(
int
(
Tweet
.
likes
)):
j_data
=
{
"_index"
:
"twint"
,
"_type"
:
"items"
,
"_id"
:
Tweet
.
id
+
"_likes_"
+
str
(
nLikes
),
"_source"
:
{
"id"
:
Tweet
.
id
,
"date"
:
Tweet
.
datestamp
,
"time"
:
Tweet
.
timestamp
,
"timezone"
:
Tweet
.
timezone
,
"tweet"
:
Tweet
.
tweet
,
"hashtags"
:
Tweet
.
hashtags
,
"likes"
:
True
,
"username"
:
Tweet
.
username
,
"day"
:
day
,
"hour"
:
Tweet
.
time
.
strftime
(
"
%
H"
)
}
}
actions
.
append
(
j_data
)
nLikes
+=
1
for
rep
in
range
(
int
(
Tweet
.
replies
)):
j_data
=
{
"_index"
:
"twint"
,
"_type"
:
"items"
,
"_id"
:
Tweet
.
id
+
"_replies_"
+
str
(
nReplies
),
"_source"
:
{
"id"
:
Tweet
.
id
,
"date"
:
Tweet
.
datestamp
,
"time"
:
Tweet
.
timestamp
,
"timezone"
:
Tweet
.
timezone
,
"tweet"
:
Tweet
.
tweet
,
"hashtags"
:
Tweet
.
hashtags
,
"replies"
:
True
,
"username"
:
Tweet
.
username
,
"day"
:
day
,
"hour"
:
Tweet
.
time
.
strftime
(
"
%
H"
)
}
}
actions
.
append
(
j_data
)
nReplies
+=
1
for
ret
in
range
(
int
(
Tweet
.
retweets
)):
j_data
=
{
"_index"
:
"twint"
,
"_type"
:
"items"
,
"_id"
:
Tweet
.
id
+
"_retweets_"
+
str
(
nRetweets
),
"_source"
:
{
"id"
:
Tweet
.
id
,
"date"
:
Tweet
.
datestamp
,
"time"
:
Tweet
.
timestamp
,
"timezone"
:
Tweet
.
timezone
,
"tweet"
:
Tweet
.
tweet
,
"hashtags"
:
Tweet
.
hashtags
,
"retweets"
:
True
,
"username"
:
Tweet
.
username
,
"day"
:
day
,
"hour"
:
Tweet
.
time
.
strftime
(
"
%
H"
)
}
}
actions
.
append
(
j_data
)
nRetweets
+=
1
es
=
Elasticsearch
(
config
.
Elasticsearch
)
with
nostdout
():
helpers
.
bulk
(
es
,
actions
,
chunk_size
=
2000
,
request_timeout
=
200
)
actions
=
[]
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