Skip to content

Commit

Permalink
Add: Script to fill extended reddit info for old DB entries
Browse files Browse the repository at this point in the history
  • Loading branch information
nilfoer committed Jul 20, 2024
1 parent 934cb87 commit e3b313f
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions dev_tools/populate_extended_reddit_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@

import praw

MODULE_DIR = os.path.abspath(os.path.dirname(__file__))
sys.path.insert(0, os.path.realpath(os.path.join(MODULE_DIR, '..')))

import gwaripper.download as dl
import gwaripper.config as cfg
import gwaripper.gwaripper as gwa
Expand All @@ -11,8 +14,6 @@
from gwaripper.logging_setup import configure_logging
from gwaripper.reddit import reddit_praw

MODULE_DIR = os.path.abspath(os.path.dirname(__file__))
sys.path.insert(0, os.path.realpath(os.path.join(MODULE_DIR, '..')))


class RowHelper:
Expand Down Expand Up @@ -45,4 +46,18 @@ def __getattr__(self, name: str):
if entry.reddit_info_id is None:
continue

praw.models.Submission()
sub = praw.models.Submission(reddit, id=row['id_on_page'])
with g.db_con:
flair_id = None
if sub.link_flair_text:
flair_id = g._get_flair_id(sub.link_flair_text)

print(f"Upd Sub<{row['id_on_page']}> flair: {sub.link_flair_text} upvotes: {sub.score} self: {bool(sub.selftext)}")

c.execute("""
UPDATE RedditInfo SET
upvotes = ?,
flair_id = ?,
selftext = ?
WHERE id = ?
""", (sub.score, flair_id, sub.selftext or None, entry.reddit_info_id))

0 comments on commit e3b313f

Please sign in to comment.