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
8bb3ac6b
Commit
8bb3ac6b
authored
Mar 15, 2018
by
Cody Zacharias
Committed by
GitHub
Mar 15, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Cleanup & Moving stuff around
parent
6f1f5629
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
36 additions
and
37 deletions
+36
-37
tweep.py
tweep.py
+36
-37
No files found.
tweep.py
View file @
8bb3ac6b
#!/usr/bin/python3
from
bs4
import
BeautifulSoup
from
elasticsearch
import
Elasticsearch
from
time
import
gmtime
,
strftime
import
argparse
import
aiohttp
...
...
@@ -7,12 +8,10 @@ import asyncio
import
async_timeout
import
csv
import
datetime
import
hashlib
import
json
import
re
import
sys
import
hashlib
from
elasticsearch
import
Elasticsearch
async
def
getUrl
(
init
):
'''
...
...
@@ -151,18 +150,6 @@ async def outTweet(tweet):
except
:
pass
jObject
=
{
"tweetid"
:
tweetid
,
"datestamp"
:
date
+
" "
+
time
,
"timezone"
:
timezone
,
"text"
:
text
,
"hashtags"
:
re
.
findall
(
r'(?i)\#\w+'
,
text
,
flags
=
re
.
UNICODE
),
"replies"
:
replies
,
"retweets"
:
retweets
,
"likes"
:
likes
,
"username"
:
username
}
# Preparing to output
'''
...
...
@@ -172,28 +159,38 @@ async def outTweet(tweet):
modes exist.
'''
if
arg
.
elasticsearch
:
jObject
=
{
"tweetid"
:
tweetid
,
"datestamp"
:
date
+
" "
+
time
,
"timezone"
:
timezone
,
"text"
:
text
,
"hashtags"
:
re
.
findall
(
r'(?i)\#\w+'
,
text
,
flags
=
re
.
UNICODE
),
"replies"
:
replies
,
"retweets"
:
retweets
,
"likes"
:
likes
,
"username"
:
username
}
es
=
Elasticsearch
(
arg
.
elasticsearch
)
es
.
index
(
index
=
"tweep"
,
doc_type
=
"items"
,
id
=
tweetid
,
body
=
json
.
dumps
(
jObject
))
return
""
output
=
""
elif
arg
.
users
:
output
=
username
elif
arg
.
tweets
:
output
=
tweets
else
:
if
arg
.
users
:
output
=
username
elif
arg
.
tweets
:
output
=
tweets
else
:
'''
The standard output is how I like it, although
this can be modified to your desire. Uncomment
the bottom line and add in the variables in the
order you want them or how you want it to look.
'''
# output = ""
output
=
"{} {} {} {} <{}> {}"
.
format
(
tweetid
,
date
,
time
,
timezone
,
username
,
text
)
if
arg
.
hashtags
:
output
+=
" {}"
.
format
(
hashtags
)
if
arg
.
stats
:
output
+=
" | {} replies {} retweets {} likes"
.
format
(
replies
,
retweets
,
likes
)
'''
The standard output is how I like it, although
this can be modified to your desire. Uncomment
the bottom line and add in the variables in the
order you want them or how you want it to look.
'''
# output = ""
output
=
"{} {} {} {} <{}> {}"
.
format
(
tweetid
,
date
,
time
,
timezone
,
username
,
text
)
if
arg
.
hashtags
:
output
+=
" {}"
.
format
(
hashtags
)
if
arg
.
stats
:
output
+=
" | {} replies {} retweets {} likes"
.
format
(
replies
,
retweets
,
likes
)
# Output section
...
...
@@ -208,7 +205,7 @@ async def outTweet(tweet):
# Writes or appends to a file.
print
(
output
,
file
=
open
(
arg
.
o
,
"a"
))
return
output
return
output
async
def
getTweets
(
init
):
'''
...
...
@@ -249,6 +246,10 @@ async def main():
'''
Putting it all together.
'''
if
arg
.
elasticsearch
:
print
(
"Indexing to Elasticsearch @"
+
str
(
arg
.
elasticsearch
))
if
arg
.
userid
is
not
None
:
arg
.
u
=
await
getUsername
()
...
...
@@ -313,8 +314,6 @@ if __name__ == "__main__":
arg
=
ap
.
parse_args
()
check
()
if
arg
.
elasticsearch
:
print
(
"Indexing to Elasticsearch @"
+
str
(
arg
.
elasticsearch
))
loop
=
asyncio
.
get_event_loop
()
loop
.
run_until_complete
(
main
())
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