Commit f9c76746 authored by minamotorin's avatar minamotorin Committed by GitHub

Related to twintproject/twint#1335

This commit doesn't completely fix the problem, but `twint.Profile` works
parent 92239ae6
...@@ -59,9 +59,12 @@ def _get_cursor(response): ...@@ -59,9 +59,12 @@ def _get_cursor(response):
next_cursor = response['timeline']['instructions'][0]['addEntries']['entries'][-1]['content'][ next_cursor = response['timeline']['instructions'][0]['addEntries']['entries'][-1]['content'][
'operation']['cursor']['value'] 'operation']['cursor']['value']
except KeyError: except KeyError:
try:
# this is needed because after the first request location of cursor is changed # this is needed because after the first request location of cursor is changed
next_cursor = response['timeline']['instructions'][-1]['replaceEntry']['entry']['content']['operation'][ next_cursor = response['timeline']['instructions'][-1]['replaceEntry']['entry']['content']['operation'][
'cursor']['value'] 'cursor']['value']
except KeyError:
next_cursor = response['timeline']['instructions'][0]['entries'][-1]['content']['value']
return next_cursor return next_cursor
...@@ -77,10 +80,11 @@ def Json(response): ...@@ -77,10 +80,11 @@ def Json(response):
def parse_tweets(config, response): def parse_tweets(config, response):
logme.debug(__name__ + ':parse_tweets') logme.debug(__name__ + ':parse_tweets')
response = loads(response) response = loads(response)
feed = []
if 'globalObjects' in response:
if len(response['globalObjects']['tweets']) == 0: if len(response['globalObjects']['tweets']) == 0:
msg = 'No more data!' msg = 'No more data!'
raise NoMoreTweetsException(msg) raise NoMoreTweetsException(msg)
feed = []
for timeline_entry in response['timeline']['instructions'][0]['addEntries']['entries']: for timeline_entry in response['timeline']['instructions'][0]['addEntries']['entries']:
# this will handle the cases when the timeline entry is a tweet # 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 if (config.TwitterSearch or config.Profile) and (timeline_entry['entryId'].startswith('sq-I-t-') or
...@@ -118,5 +122,12 @@ def parse_tweets(config, response): ...@@ -118,5 +122,12 @@ def parse_tweets(config, response):
'retweet_date': _dt, 'retweet_date': _dt,
} }
feed.append(temp_obj) 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) next_cursor = _get_cursor(response)
return feed, next_cursor return feed, next_cursor
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment