use a bool to track reddit posts

This commit is contained in:
lza_menace 2020-10-17 21:39:19 -07:00
parent cda49c8146
commit 94b58f7437
3 changed files with 10 additions and 5 deletions

View file

@ -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)

View file

@ -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

View file

@ -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