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
f7dfc15b
Commit
f7dfc15b
authored
Feb 05, 2018
by
Cody Zacharias
Committed by
GitHub
Feb 05, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #21 from hpiedcoq/patch-1
add hashtags extraction and cleanse text (urls)
parents
fa2bd816
51ecfe59
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
7 additions
and
2 deletions
+7
-2
tweep.py
tweep.py
+7
-2
No files found.
tweep.py
View file @
f7dfc15b
...
@@ -8,6 +8,7 @@ import async_timeout
...
@@ -8,6 +8,7 @@ import async_timeout
import
csv
import
csv
import
datetime
import
datetime
import
json
import
json
import
re
import
sys
import
sys
async
def
getUrl
(
init
):
async
def
getUrl
(
init
):
...
@@ -77,7 +78,8 @@ async def getTweets(init):
...
@@ -77,7 +78,8 @@ async def getTweets(init):
time
=
t
.
strftime
(
"
%
H:
%
M:
%
S"
)
time
=
t
.
strftime
(
"
%
H:
%
M:
%
S"
)
username
=
tweet
.
find
(
"span"
,
"username"
)
.
text
.
replace
(
"@"
,
""
)
username
=
tweet
.
find
(
"span"
,
"username"
)
.
text
.
replace
(
"@"
,
""
)
timezone
=
strftime
(
"
%
Z"
,
gmtime
())
timezone
=
strftime
(
"
%
Z"
,
gmtime
())
text
=
tweet
.
find
(
"p"
,
"tweet-text"
)
.
text
.
replace
(
"
\n
"
,
" "
)
text
=
tweet
.
find
(
"p"
,
"tweet-text"
)
.
text
.
replace
(
"
\n
"
,
" "
)
.
replace
(
"http"
,
" http"
)
.
replace
(
"pic.twitter"
,
" pic.twitter"
)
hashtags
=
","
.
join
(
re
.
findall
(
r'(?i)\#\w+'
,
text
,
flags
=
re
.
UNICODE
))
try
:
try
:
mentions
=
tweet
.
find
(
"div"
,
"js-original-tweet"
)[
"data-mentions"
]
.
split
(
" "
)
mentions
=
tweet
.
find
(
"div"
,
"js-original-tweet"
)[
"data-mentions"
]
.
split
(
" "
)
for
i
in
range
(
len
(
mentions
)):
for
i
in
range
(
len
(
mentions
)):
...
@@ -93,10 +95,12 @@ async def getTweets(init):
...
@@ -93,10 +95,12 @@ async def getTweets(init):
output
=
tweets
output
=
tweets
else
:
else
:
output
=
"{} {} {} {} <{}> {}"
.
format
(
tweetid
,
date
,
time
,
timezone
,
username
,
text
)
output
=
"{} {} {} {} <{}> {}"
.
format
(
tweetid
,
date
,
time
,
timezone
,
username
,
text
)
if
arg
.
hashtags
:
output
+=
" {}"
.
format
(
hashtags
)
if
arg
.
o
!=
None
:
if
arg
.
o
!=
None
:
if
arg
.
csv
:
if
arg
.
csv
:
dat
=
[
tweetid
,
date
,
time
,
timezone
,
username
,
text
]
dat
=
[
tweetid
,
date
,
time
,
timezone
,
username
,
text
,
hashtags
]
with
open
(
arg
.
o
,
"a"
,
newline
=
''
)
as
csv_file
:
with
open
(
arg
.
o
,
"a"
,
newline
=
''
)
as
csv_file
:
writer
=
csv
.
writer
(
csv_file
,
delimiter
=
"|"
)
writer
=
csv
.
writer
(
csv_file
,
delimiter
=
"|"
)
writer
.
writerow
(
dat
)
writer
.
writerow
(
dat
)
...
@@ -128,6 +132,7 @@ if __name__ == "__main__":
...
@@ -128,6 +132,7 @@ if __name__ == "__main__":
ap
.
add_argument
(
"--verified"
,
help
=
"Display Tweets only from verified users (Use with -s)."
,
action
=
"store_true"
)
ap
.
add_argument
(
"--verified"
,
help
=
"Display Tweets only from verified users (Use with -s)."
,
action
=
"store_true"
)
ap
.
add_argument
(
"--users"
,
help
=
"Display users only (Use with -s)."
,
action
=
"store_true"
)
ap
.
add_argument
(
"--users"
,
help
=
"Display users only (Use with -s)."
,
action
=
"store_true"
)
ap
.
add_argument
(
"--csv"
,
help
=
"Write as .csv file."
,
action
=
"store_true"
)
ap
.
add_argument
(
"--csv"
,
help
=
"Write as .csv file."
,
action
=
"store_true"
)
ap
.
add_argument
(
"--hashtags"
,
help
=
"Output hashtags in seperate column."
,
action
=
"store_true"
)
arg
=
ap
.
parse_args
()
arg
=
ap
.
parse_args
()
if
arg
.
u
is
not
None
:
if
arg
.
u
is
not
None
:
...
...
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