From 94b58f74374636852d7997924de2e5757d09b85d Mon Sep 17 00:00:00 2001 From: lza_menace Date: Sat, 17 Oct 2020 21:39:19 -0700 Subject: [PATCH] use a bool to track reddit posts --- suchwow/app.py | 2 +- suchwow/models.py | 1 + suchwow/reddit.py | 12 ++++++++---- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/suchwow/app.py b/suchwow/app.py index 138c251..e269dc7 100644 --- a/suchwow/app.py +++ b/suchwow/app.py @@ -67,7 +67,7 @@ def create_accounts(): @app.cli.command("reddit_recent") def reddit_recent(): # run every 5 mins - all_posts = Post.select().order_by(Post.timestamp.desc()).where(Post.reddit_url == None) + all_posts = Post.select().order_by(Post.timestamp.desc()).where(Post.to_reddit == False) for post in all_posts: diff = datetime.now() - post.timestamp recent_post = diff < timedelta(hours=2) diff --git a/suchwow/models.py b/suchwow/models.py index fe5d5de..02bfb3d 100644 --- a/suchwow/models.py +++ b/suchwow/models.py @@ -17,6 +17,7 @@ class Post(Model): address_index = IntegerField() timestamp = DateTimeField(default=datetime.now) reddit_url = CharField(null=True) + to_reddit = BooleanField(default=False) class Meta: database = db diff --git a/suchwow/reddit.py b/suchwow/reddit.py index 4deec30..a23bae4 100644 --- a/suchwow/reddit.py +++ b/suchwow/reddit.py @@ -46,7 +46,11 @@ def make_post(post): comment = "".join(_comment) reddit_post = Reddit().post(title, url) reddit_comment = Reddit().comment(reddit_post, comment) - post.reddit_url = reddit_post.url - post.save() - print(f"Posted #{post.id} to Reddit - {reddit_post.url}") - return True + if reddit_post: + post.to_reddit = True + post.save() + print(f"Posted #{post.id} to Reddit") + return True + else: + print(f"Unable to post #{post.id} to Reddit") + return False