use a bool to track reddit posts

graphs-n-shit
lza_menace 4 years ago
parent cda49c8146
commit 94b58f7437

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

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

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

Loading…
Cancel
Save