2020-10-15 07:14:50 +00:00
|
|
|
import praw
|
2020-10-15 21:56:28 +00:00
|
|
|
from flask import url_for
|
2020-10-15 21:51:00 +00:00
|
|
|
from suchwow import config, wownero
|
2020-10-15 06:51:53 +00:00
|
|
|
|
|
|
|
|
|
|
|
class Reddit(object):
|
|
|
|
def __init__(self):
|
2020-10-15 07:14:50 +00:00
|
|
|
self.reddit = praw.Reddit(
|
2020-10-15 07:00:51 +00:00
|
|
|
client_id=config.PRAW_CLIENT_ID,
|
|
|
|
client_secret=config.PRAW_CLIENT_SECRET,
|
|
|
|
user_agent=config.PRAW_USER_AGENT,
|
|
|
|
username=config.PRAW_USERNAME,
|
|
|
|
password=config.PRAW_PASSWORD
|
2020-10-15 06:51:53 +00:00
|
|
|
)
|
|
|
|
self.subreddit = "wownero"
|
|
|
|
|
2020-10-15 07:14:50 +00:00
|
|
|
def post(self, title, url):
|
2020-10-15 06:51:53 +00:00
|
|
|
try:
|
2020-10-15 07:14:50 +00:00
|
|
|
submission = self.reddit.subreddit(self.subreddit).submit(
|
2020-10-15 06:51:53 +00:00
|
|
|
title=title,
|
|
|
|
url=url,
|
|
|
|
resubmit=False,
|
|
|
|
)
|
|
|
|
return submission
|
|
|
|
except:
|
|
|
|
return False
|
|
|
|
|
2020-10-15 13:45:59 +00:00
|
|
|
def comment(self, submission, comment):
|
2020-10-15 06:51:53 +00:00
|
|
|
try:
|
2020-10-15 13:45:59 +00:00
|
|
|
_comment = submission.reply(comment)
|
|
|
|
return _comment
|
2020-10-15 06:51:53 +00:00
|
|
|
except:
|
|
|
|
return False
|
2020-10-15 21:51:00 +00:00
|
|
|
|
|
|
|
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
|