suchwow/suchwow/reddit.py

51 lines
1.5 KiB
Python
Raw Normal View History

2020-10-15 08:14:50 +01:00
import praw
from suchwow import config, wownero
class Reddit(object):
def __init__(self):
2020-10-15 08:14:50 +01:00
self.reddit = praw.Reddit(
2020-10-15 08:00:51 +01: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
)
self.subreddit = "wownero"
2020-10-15 08:14:50 +01:00
def post(self, title, url):
try:
2020-10-15 08:14:50 +01:00
submission = self.reddit.subreddit(self.subreddit).submit(
title=title,
url=url,
resubmit=False,
)
return submission
except:
return False
def comment(self, submission, comment):
try:
_comment = submission.reply(comment)
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