Skip to content

Commit

Permalink
TEMPORARY hack: expand logged in session scraping to all likes
Browse files Browse the repository at this point in the history
not to be released! for snarfed/bridgy#949
  • Loading branch information
snarfed committed Jun 4, 2020
1 parent 4fe84d6 commit 66624b2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 17 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,6 @@ linkedin_client_*
meetup_client_*
reddit_app_*
twitter_app_*
twitter_scrape_headers*
TAGS
*.pyc
23 changes: 6 additions & 17 deletions granary/twitter.py
Original file line number Diff line number Diff line change
Expand Up @@ -379,23 +379,12 @@ def _user():
id = tweet['id_str']
count = tweet.get('favorite_count')
if self.is_public(activity) and count and count != cached.get('ATF ' + id):
if tweet.get('user', {}).get('screen_name') == 'islayblog':
resp = util.requests_get(
'https://api.twitter.com/2/timeline/liked_by.json?tweet_mode=extended&include_entities=true&include_user_entities=true&tweet_id=%s&count=80' % id,
headers=SCRAPE_HEADERS)
resp.raise_for_status()
likes = [self._make_like(tweet, author) for author in
resp.json()['globalObjects']['users'].values()]

else: # not a beta user
url = HTML_FAVORITES % id
try:
resp = util.urlopen(url).read()
html = source.load_json(resp, url).get('htmlUsers', '')
except urllib.error.URLError as e:
util.interpret_http_exception(e) # just log it
continue
likes = self.favorites_html_to_likes(tweet, html)
resp = util.requests_get(
'https://api.twitter.com/2/timeline/liked_by.json?tweet_mode=extended&include_entities=true&include_user_entities=true&tweet_id=%s&count=80' % id,
headers=SCRAPE_HEADERS)
resp.raise_for_status()
likes = [self._make_like(tweet, author) for author in
resp.json()['globalObjects']['users'].values()]

activity['object'].setdefault('tags', []).extend(likes)
cache_updates['ATF ' + id] = count
Expand Down

0 comments on commit 66624b2

Please sign in to comment.