setup praw and commands to post to reddit

graphs-n-shit
lza_menace 4 years ago
parent d29874a92d
commit bc0d83b832

@ -4,3 +4,4 @@ flask-session
peewee
gunicorn
six
praw

@ -1,4 +1,6 @@
import json
from datetime import datetime, timedelta
from random import choice
from os import makedirs
from flask import Flask, request, session, redirect
from flask import render_template, flash, url_for
@ -61,6 +63,33 @@ def create_accounts():
account = wallet.new_account()
print(f"Created account {account}")
@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)
for post in all_posts:
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()
return True
@app.cli.command("reddit_random")
def reddit_random():
# run every 8 hours
all_posts = Post.select().where(Post.reddit_url == None)
post = choice(all_posts)
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()
return True
@app.cli.command("payout_users")
def payout_users():
wallet = wownero.Wallet()

@ -12,3 +12,9 @@ WALLET_PORT = 8888
WALLET_PROTO = 'http'
WALLET_USER = 'suchwow'
WALLET_PASS = 'zzzzzzzzzzzzzzz'
PRAW_CLIENT_SECRET = 'xxxxxxxx'
PRAW_CLIENT_ID = 'xxxxxxxx'
PRAW_USER_AGENT = 'suchwow-yyyy-python'
PRAW_USERNAME = 'xxxxxxxx'
PRAW_PASSWORD = 'xxxxxxxx'
SERVER_NAME = 'suchwow.xyz'

@ -9,7 +9,6 @@ class Post(Model):
id = AutoField()
title = CharField()
text = CharField()
# submitter = ForeignKeyField(Profile, field=Profile.username)
submitter = CharField()
image_name = CharField()
readonly = BooleanField(default=False)
@ -17,6 +16,7 @@ class Post(Model):
account_index = IntegerField()
address_index = IntegerField()
timestamp = DateTimeField(default=datetime.now)
reddit_url = CharField(null=True)
class Meta:
database = db

@ -0,0 +1,31 @@
from praw import Reddit
from suchwow import config
class Reddit(object):
def __init__(self):
self.reddit = Reddit(
client_id=config.get("PRAW_CLIENT_ID"),
client_secret=config.get("PRAW_CLIENT_SECRET"),
user_agent=config.get("PRAW_USER_AGENT"),
username=config.get("PRAW_USERNAME"),
password=config.get("PRAW_PASSWORD")
)
self.subreddit = "wownero"
def post(title, url):
try:
submission = reddit.subreddit(self.subreddit).submit(
title=title,
url=url,
resubmit=False,
)
return submission
except:
return False
def comment(submission, post):
try:
submission.reply(f"Show this post love by sending WOW: {post.id}")
except:
return False