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") @app.cli.command("reddit_recent")
def reddit_recent(): def reddit_recent():
# run every 5 mins # 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: for post in all_posts:
diff = datetime.now() - post.timestamp diff = datetime.now() - post.timestamp
recent_post = diff < timedelta(hours=2) recent_post = diff < timedelta(hours=2)

@ -17,6 +17,7 @@ class Post(Model):
address_index = IntegerField() address_index = IntegerField()
timestamp = DateTimeField(default=datetime.now) timestamp = DateTimeField(default=datetime.now)
reddit_url = CharField(null=True) reddit_url = CharField(null=True)
to_reddit = BooleanField(default=False)
class Meta: class Meta:
database = db database = db

@ -46,7 +46,11 @@ def make_post(post):
comment = "".join(_comment) comment = "".join(_comment)
reddit_post = Reddit().post(title, url) reddit_post = Reddit().post(title, url)
reddit_comment = Reddit().comment(reddit_post, comment) reddit_comment = Reddit().comment(reddit_post, comment)
post.reddit_url = reddit_post.url if reddit_post:
post.save() post.to_reddit = True
print(f"Posted #{post.id} to Reddit - {reddit_post.url}") post.save()
return True print(f"Posted #{post.id} to Reddit")
return True
else:
print(f"Unable to post #{post.id} to Reddit")
return False