print debugging for reddit mentions
parent
f3e6a6e71f
commit
569f0269e3
|
@ -21,6 +21,7 @@ from files.classes.notifications import Notification
|
|||
# value from /meta (or just guessing) and doing a random selection of keywords.
|
||||
|
||||
def offsite_mentions_task(cache:Cache):
|
||||
print('hola', flush=True)
|
||||
site_mentions = get_mentions(cache, const.REDDIT_NOTIFS_SITE)
|
||||
notify_mentions(site_mentions)
|
||||
|
||||
|
@ -32,6 +33,7 @@ def offsite_mentions_task(cache:Cache):
|
|||
g.db.commit() # commit early otherwise localhost testing fails to commit
|
||||
|
||||
def get_mentions(cache:Cache, queries:Iterable[str], reddit_notifs_users=False):
|
||||
print('nword', flush=True)
|
||||
kinds = ['submission', 'comment']
|
||||
mentions = []
|
||||
exclude_subreddits = ['PokemonGoRaids', 'SubSimulatorGPT2', 'SubSimGPT2Interactive']
|
||||
|
@ -43,13 +45,15 @@ def get_mentions(cache:Cache, queries:Iterable[str], reddit_notifs_users=False):
|
|||
size = 1 if reddit_notifs_users else 100
|
||||
for kind in kinds:
|
||||
try:
|
||||
print('request', flush=True)
|
||||
data = requests.get((
|
||||
f'https://api.pushshift.io/reddit/{kind}/search?html_decode=true'
|
||||
f'&q={"%7C".join(queries)}'
|
||||
f'&subreddit=!{",!".join(exclude_subreddits)}'
|
||||
f'&after={after}'
|
||||
f'&size={size}'), timeout=15).json()['data']
|
||||
except:
|
||||
except Exception as e:
|
||||
print(e, flush=True)
|
||||
continue
|
||||
|
||||
for thing in data:
|
||||
|
@ -83,7 +87,9 @@ def get_mentions(cache:Cache, queries:Iterable[str], reddit_notifs_users=False):
|
|||
return mentions
|
||||
|
||||
def notify_mentions(mentions, send_to=None, mention_str='site mention'):
|
||||
print('notify_mentions', flush=True)
|
||||
for m in mentions:
|
||||
print(m, flush=True)
|
||||
author = m['author']
|
||||
permalink = m['permalink']
|
||||
text = sanitize(m['text'], golden=False)
|
||||
|
@ -109,6 +115,7 @@ def notify_mentions(mentions, send_to=None, mention_str='site mention'):
|
|||
distinguish_level=6)
|
||||
g.db.add(new_comment)
|
||||
g.db.flush()
|
||||
print(new_comment.id, flush=True)
|
||||
new_comment.top_comment_id = new_comment.id
|
||||
|
||||
if send_to:
|
||||
|
|
Loading…
Reference in New Issue