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
f9c76746
Commit
f9c76746
authored
Feb 06, 2022
by
minamotorin
Committed by
GitHub
Feb 06, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Related to twintproject/twint#1335
This commit doesn't completely fix the problem, but `twint.Profile` works
parent
92239ae6
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
53 additions
and
42 deletions
+53
-42
twint/feed.py
twint/feed.py
+53
-42
No files found.
twint/feed.py
View file @
f9c76746
...
...
@@ -59,9 +59,12 @@ def _get_cursor(response):
next_cursor
=
response
[
'timeline'
][
'instructions'
][
0
][
'addEntries'
][
'entries'
][
-
1
][
'content'
][
'operation'
][
'cursor'
][
'value'
]
except
KeyError
:
# this is needed because after the first request location of cursor is changed
next_cursor
=
response
[
'timeline'
][
'instructions'
][
-
1
][
'replaceEntry'
][
'entry'
][
'content'
][
'operation'
][
'cursor'
][
'value'
]
try
:
# this is needed because after the first request location of cursor is changed
next_cursor
=
response
[
'timeline'
][
'instructions'
][
-
1
][
'replaceEntry'
][
'entry'
][
'content'
][
'operation'
][
'cursor'
][
'value'
]
except
KeyError
:
next_cursor
=
response
[
'timeline'
][
'instructions'
][
0
][
'entries'
][
-
1
][
'content'
][
'value'
]
return
next_cursor
...
...
@@ -77,46 +80,54 @@ def Json(response):
def
parse_tweets
(
config
,
response
):
logme
.
debug
(
__name__
+
':parse_tweets'
)
response
=
loads
(
response
)
if
len
(
response
[
'globalObjects'
][
'tweets'
])
==
0
:
msg
=
'No more data!'
raise
NoMoreTweetsException
(
msg
)
feed
=
[]
for
timeline_entry
in
response
[
'timeline'
][
'instructions'
][
0
][
'addEntries'
][
'entries'
]:
# this will handle the cases when the timeline entry is a tweet
if
(
config
.
TwitterSearch
or
config
.
Profile
)
and
(
timeline_entry
[
'entryId'
]
.
startswith
(
'sq-I-t-'
)
or
timeline_entry
[
'entryId'
]
.
startswith
(
'tweet-'
)):
if
'tweet'
in
timeline_entry
[
'content'
][
'item'
][
'content'
]:
_id
=
timeline_entry
[
'content'
][
'item'
][
'content'
][
'tweet'
][
'id'
]
# skip the ads
if
'promotedMetadata'
in
timeline_entry
[
'content'
][
'item'
][
'content'
][
'tweet'
]:
if
'globalObjects'
in
response
:
if
len
(
response
[
'globalObjects'
][
'tweets'
])
==
0
:
msg
=
'No more data!'
raise
NoMoreTweetsException
(
msg
)
for
timeline_entry
in
response
[
'timeline'
][
'instructions'
][
0
][
'addEntries'
][
'entries'
]:
# this will handle the cases when the timeline entry is a tweet
if
(
config
.
TwitterSearch
or
config
.
Profile
)
and
(
timeline_entry
[
'entryId'
]
.
startswith
(
'sq-I-t-'
)
or
timeline_entry
[
'entryId'
]
.
startswith
(
'tweet-'
)):
if
'tweet'
in
timeline_entry
[
'content'
][
'item'
][
'content'
]:
_id
=
timeline_entry
[
'content'
][
'item'
][
'content'
][
'tweet'
][
'id'
]
# skip the ads
if
'promotedMetadata'
in
timeline_entry
[
'content'
][
'item'
][
'content'
][
'tweet'
]:
continue
elif
'tombstone'
in
timeline_entry
[
'content'
][
'item'
][
'content'
]
and
'tweet'
in
\
timeline_entry
[
'content'
][
'item'
][
'content'
][
'tombstone'
]:
_id
=
timeline_entry
[
'content'
][
'item'
][
'content'
][
'tombstone'
][
'tweet'
][
'id'
]
else
:
_id
=
None
if
_id
is
None
:
raise
ValueError
(
'Unable to find ID of tweet in timeline.'
)
try
:
temp_obj
=
response
[
'globalObjects'
][
'tweets'
][
_id
]
except
KeyError
:
logme
.
info
(
'encountered a deleted tweet with id {}'
.
format
(
_id
))
config
.
deleted
.
append
(
_id
)
continue
elif
'tombstone'
in
timeline_entry
[
'content'
][
'item'
][
'content'
]
and
'tweet'
in
\
timeline_entry
[
'content'
][
'item'
][
'content'
][
'tombstone'
]:
_id
=
timeline_entry
[
'content'
][
'item'
][
'content'
][
'tombstone'
][
'tweet'
][
'id'
]
else
:
_id
=
None
if
_id
is
None
:
raise
ValueError
(
'Unable to find ID of tweet in timeline.'
)
try
:
temp_obj
=
response
[
'globalObjects'
][
'tweets'
][
_id
]
except
KeyError
:
logme
.
info
(
'encountered a deleted tweet with id {}'
.
format
(
_id
))
config
.
deleted
.
append
(
_id
)
continue
temp_obj
[
'user_data'
]
=
response
[
'globalObjects'
][
'users'
][
temp_obj
[
'user_id_str'
]]
if
'retweeted_status_id_str'
in
temp_obj
:
rt_id
=
temp_obj
[
'retweeted_status_id_str'
]
_dt
=
response
[
'globalObjects'
][
'tweets'
][
rt_id
][
'created_at'
]
_dt
=
datetime
.
strptime
(
_dt
,
'
%
a
%
b
%
d
%
H:
%
M:
%
S
%
z
%
Y'
)
_dt
=
utc_to_local
(
_dt
)
_dt
=
str
(
_dt
.
strftime
(
Tweet_formats
[
'datetime'
]))
temp_obj
[
'retweet_data'
]
=
{
'user_rt_id'
:
response
[
'globalObjects'
][
'tweets'
][
rt_id
][
'user_id_str'
],
'user_rt'
:
response
[
'globalObjects'
][
'tweets'
][
rt_id
][
'full_text'
],
'retweet_id'
:
rt_id
,
'retweet_date'
:
_dt
,
}
feed
.
append
(
temp_obj
)
temp_obj
[
'user_data'
]
=
response
[
'globalObjects'
][
'users'
][
temp_obj
[
'user_id_str'
]]
if
'retweeted_status_id_str'
in
temp_obj
:
rt_id
=
temp_obj
[
'retweeted_status_id_str'
]
_dt
=
response
[
'globalObjects'
][
'tweets'
][
rt_id
][
'created_at'
]
_dt
=
datetime
.
strptime
(
_dt
,
'
%
a
%
b
%
d
%
H:
%
M:
%
S
%
z
%
Y'
)
_dt
=
utc_to_local
(
_dt
)
_dt
=
str
(
_dt
.
strftime
(
Tweet_formats
[
'datetime'
]))
temp_obj
[
'retweet_data'
]
=
{
'user_rt_id'
:
response
[
'globalObjects'
][
'tweets'
][
rt_id
][
'user_id_str'
],
'user_rt'
:
response
[
'globalObjects'
][
'tweets'
][
rt_id
][
'full_text'
],
'retweet_id'
:
rt_id
,
'retweet_date'
:
_dt
,
}
feed
.
append
(
temp_obj
)
else
:
response
=
response
[
'data'
][
'user'
][
'result'
][
'timeline'
]
for
timeline_entry
in
response
[
'timeline'
][
'instructions'
][
0
][
'entries'
]:
if
timeline_entry
[
'content'
]
.
get
(
'itemContent'
):
temp_obj
=
timeline_entry
[
'content'
][
'itemContent'
][
'tweet_results'
][
'result'
][
'legacy'
]
temp_obj
[
'user_data'
]
=
timeline_entry
[
'content'
][
'itemContent'
][
'tweet_results'
][
'result'
][
'core'
][
'user_results'
][
'result'
][
'legacy'
]
feed
.
append
(
temp_obj
)
next_cursor
=
_get_cursor
(
response
)
return
feed
,
next_cursor
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