Skip to content

Commit

Permalink
Fix issue with auth token not refreshing
Browse files Browse the repository at this point in the history
  • Loading branch information
barrycarey committed Aug 12, 2024
1 parent d73480d commit 605d2ae
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def run_update_top_reposts(uow: UnitOfWork) -> None:

def update_top_reposters(uow: UnitOfWork, post_type_id: int, day_range: int = None) -> None:
log.info('Getting top repostors for post type %s with range %s', post_type_id, day_range)
range_query = "SELECT author, COUNT(*) c FROM repost WHERE detected_at > NOW() - INTERVAL :days DAY AND post_type_id=:posttype AND author is not NULL AND author!= '[deleted]' GROUP BY author HAVING c > 10 ORDER BY c DESC"
range_query = "SELECT author, COUNT(*) c FROM repost WHERE detected_at > NOW() - INTERVAL :days DAY AND post_type_id=:posttype AND author is not NULL AND author!= '[deleted]' GROUP BY author HAVING c > 10 ORDER BY c DESC LIMIT 100000"
all_time_query = "SELECT author, COUNT(*) c FROM repost WHERE post_type_id=:posttype AND author is not NULL AND author!= '[deleted]' GROUP BY author HAVING c > 10 ORDER BY c DESC LIMIT 100000"
if day_range:
query = range_query
Expand Down
19 changes: 10 additions & 9 deletions redditrepostsleuth/ingestsvc/ingestsvc.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ def get_auth_headers(reddit: Reddit) -> dict:
:param reddit:
:return:
"""
reddit.user.me()
list(reddit.subreddit('all').new(limit=1)) # Force praw to make a req so we can steal the token
return {**HEADERS, **{'Authorization': f'Bearer {reddit.auth._reddit._core._authorizer.access_token}'}}

async def main() -> None:
Expand Down Expand Up @@ -300,16 +300,17 @@ async def main() -> None:

newest_id = res_data['data']['children'][-1]['data']['id']


saved_ids = [x['id'] for x in posts_to_save]
missing_ids_in_this_req = list(set(ids_to_get).difference(saved_ids))
missed_ids += [base36decode(x) for x in missing_ids_in_this_req]
time.sleep(request_delay)

log.info('Missed IDs: %s', len(missed_ids))
if len(missed_ids) > missed_id_retry_count:
await ingest_sequence(missed_ids, alt_headers=auth_headers)
missed_ids = []
# saved_ids = [x['id'] for x in posts_to_save]
# missing_ids_in_this_req = list(set(ids_to_get).difference(saved_ids))
# missed_ids += [base36decode(x) for x in missing_ids_in_this_req]


# log.info('Missed IDs: %s', len(missed_ids))
# if len(missed_ids) > missed_id_retry_count:
# await ingest_sequence(missed_ids, alt_headers=auth_headers)
# missed_ids = []

if __name__ == '__main__':
run(main())

0 comments on commit 605d2ae

Please sign in to comment.