refactor to use shared function for posting and commenting

This commit is contained in:
lza_menace 2020-10-15 14:51:00 -07:00
parent 6abd4912f6
commit 232efac2c1
2 changed files with 22 additions and 24 deletions

View file

@ -9,7 +9,7 @@ from suchwow import config
from suchwow.models import Post, Profile, Comment, Notification, db
from suchwow.routes import auth, comment, post, profile, leaderboard
from suchwow.utils.decorators import login_required
from suchwow.reddit import Reddit
from suchwow.reddit import make_post
from suchwow import wownero
@ -72,13 +72,7 @@ def reddit_recent():
diff = datetime.now() - post.timestamp
recent_post = diff < timedelta(hours=2)
if recent_post:
title = f"[SuchWow!][{post.submitter}][#{post.id}] {post.title}"
url = url_for("post.read", id=post.id)
reddit_post = Reddit().post(title, url)
post.reddit_url = reddit_post.url
post.save()
print(f"Posted #{post.id} to Reddit - {reddit_post.url}")
return True
make_post(post)
@app.cli.command("reddit_random")
def reddit_random():
@ -86,21 +80,7 @@ def reddit_random():
wallet = wownero.Wallet()
all_posts = Post.select().where(Post.reddit_url == None)
post = choice(all_posts)
title = f"SuchWow #{post.id} - {post.title}"
url = url_for('post.uploaded_file', filename=post.image_name)
_comment = [
f"'{post.text}'\n\nSubmitter: {post.submitter}\n",
f"Timestamp (UTC): {post.timestamp}\n",
"\nShow this poster some love by sending WOW to the following address: ",
f"{wallet.get_address(account=post.account_index)}"
]
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
make_post(post)
@app.cli.command("payout_users")
def payout_users():

View file

@ -1,5 +1,5 @@
import praw
from suchwow import config
from suchwow import config, wownero
class Reddit(object):
@ -30,3 +30,21 @@ class Reddit(object):
return _comment
except:
return False
def make_post(post):
wallet = wownero.Wallet()
title = f"SuchWow #{post.id} - {post.title}"
url = url_for('post.uploaded_file', filename=post.image_name)
_comment = [
f"Submitter: {post.submitter}\n",
f"Timestamp (UTC): {post.timestamp}\n",
"\nShow this poster some love by sending WOW to the following address:\n\n",
f"{wallet.get_address(account=post.account_index)}"
]
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