mirror of
https://git.wownero.com/lza_menace/suchwow.git
synced 2024-08-15 01:03:19 +00:00
setup praw and commands to post to reddit
This commit is contained in:
parent
d29874a92d
commit
bc0d83b832
5 changed files with 68 additions and 1 deletions
|
@ -4,3 +4,4 @@ flask-session
|
||||||
peewee
|
peewee
|
||||||
gunicorn
|
gunicorn
|
||||||
six
|
six
|
||||||
|
praw
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
import json
|
import json
|
||||||
|
from datetime import datetime, timedelta
|
||||||
|
from random import choice
|
||||||
from os import makedirs
|
from os import makedirs
|
||||||
from flask import Flask, request, session, redirect
|
from flask import Flask, request, session, redirect
|
||||||
from flask import render_template, flash, url_for
|
from flask import render_template, flash, url_for
|
||||||
|
@ -61,6 +63,33 @@ def create_accounts():
|
||||||
account = wallet.new_account()
|
account = wallet.new_account()
|
||||||
print(f"Created account {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")
|
@app.cli.command("payout_users")
|
||||||
def payout_users():
|
def payout_users():
|
||||||
wallet = wownero.Wallet()
|
wallet = wownero.Wallet()
|
||||||
|
|
|
@ -12,3 +12,9 @@ WALLET_PORT = 8888
|
||||||
WALLET_PROTO = 'http'
|
WALLET_PROTO = 'http'
|
||||||
WALLET_USER = 'suchwow'
|
WALLET_USER = 'suchwow'
|
||||||
WALLET_PASS = 'zzzzzzzzzzzzzzz'
|
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()
|
id = AutoField()
|
||||||
title = CharField()
|
title = CharField()
|
||||||
text = CharField()
|
text = CharField()
|
||||||
# submitter = ForeignKeyField(Profile, field=Profile.username)
|
|
||||||
submitter = CharField()
|
submitter = CharField()
|
||||||
image_name = CharField()
|
image_name = CharField()
|
||||||
readonly = BooleanField(default=False)
|
readonly = BooleanField(default=False)
|
||||||
|
@ -17,6 +16,7 @@ class Post(Model):
|
||||||
account_index = IntegerField()
|
account_index = IntegerField()
|
||||||
address_index = IntegerField()
|
address_index = IntegerField()
|
||||||
timestamp = DateTimeField(default=datetime.now)
|
timestamp = DateTimeField(default=datetime.now)
|
||||||
|
reddit_url = CharField(null=True)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
database = db
|
database = db
|
||||||
|
|
31
suchwow/reddit.py
Normal file
31
suchwow/reddit.py
Normal file
|
@ -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
|
Loading…
Reference in a new issue