You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
119 lines
3.1 KiB
119 lines
3.1 KiB
import requests, json
|
|
from time import sleep
|
|
|
|
mod = 1
|
|
headers = {'User-Agent': 'Wowbot/1.0.0'}
|
|
key = '<oauth key>'
|
|
secret = '<oauth secret>'
|
|
account = {"username": '<username>', "password": '<password>'}
|
|
token = 'dummy'
|
|
headers["Authorization"] = f'bearer {token}'
|
|
|
|
def get_oauth(key, secret, account):
|
|
creds = {"grant_type": 'password', **account}
|
|
auth = requests.auth.HTTPBasicAuth(key, secret)
|
|
request = {"auth": auth, "data": creds, "headers": headers}
|
|
response = requests.post('https://www.reddit.com/api/v1/access_token', **request)
|
|
return response.json()["access_token"]
|
|
|
|
def suchwow_list():
|
|
return requests.get("https://suchwow.xyz/api/list").json()
|
|
|
|
def fix_token():
|
|
global token, headers
|
|
token = get_oauth(key, secret, account)
|
|
headers["Authorization"] = f'bearer {token}'
|
|
|
|
def reddit_post(title, url):
|
|
data = {"api_type": 'json', "kind": 'image', "url": url, "title": title, "sr": 'bottest200000'}
|
|
request = {"headers": headers, "data": data}
|
|
|
|
response = requests.post('https://oauth.reddit.com/api/submit', **request)
|
|
|
|
if (response.status_code == 401):
|
|
fix_token()
|
|
return reddit_post(title, url)
|
|
elif (response.status_code == 200):
|
|
return response.json()
|
|
|
|
def reddit_reply(fullname, text):
|
|
data = {"api_type": 'json', "text": text, "thing_id": fullname}
|
|
request = {"headers": headers, "data": data}
|
|
|
|
response = requests.post('https://oauth.reddit.com/api/comment', **request)
|
|
|
|
if (response.status_code == 401):
|
|
fix_token()
|
|
return reddit_reply(fullname, text)
|
|
elif (response.status_code == 200):
|
|
return response.json()
|
|
|
|
def reddit_approve(id):
|
|
data = {"id": id}
|
|
request = {"headers": headers, "data": data}
|
|
|
|
response = requests.post('https://oauth.reddit.com/api/approve', **request)
|
|
|
|
if (response.status_code == 401):
|
|
fix_token()
|
|
return reddit_reply(fullname, text)
|
|
elif (response.status_code == 200):
|
|
return response
|
|
|
|
|
|
while True:
|
|
# bool for new posts
|
|
new = 0
|
|
f = open("id","r+")
|
|
id = f.readline().strip("\n")
|
|
list = suchwow_list()
|
|
|
|
for n, post in enumerate(list, start = 1):
|
|
if (post["id"] <= int(id)):
|
|
break
|
|
else:
|
|
new = 1
|
|
last = n
|
|
print(post["id"])
|
|
|
|
if (new == 1):
|
|
max = list[0]["id"]
|
|
print(max)
|
|
list = list[:last]
|
|
list.reverse()
|
|
|
|
for post in list:
|
|
title = f'SuchWow #{post["id"]} - '
|
|
topiclen = 300 - len(title)
|
|
|
|
if (len(post["title"]) > topiclen):
|
|
topiclen = topiclen - 3
|
|
topic = f'{post["title"][:topiclen]}...'
|
|
else:
|
|
topic = post["title"]
|
|
|
|
title = f'{title}{topic}'
|
|
rpost = reddit_post(title, post["image"])
|
|
rpostname = rpost["json"]["data"]["name"]
|
|
|
|
text = f'Submitted by {post["submitter"]}\n\nTimestamp: {post["timestamp"]}\n\n#[View Post]({post["href"]})\n'
|
|
|
|
reply = reddit_reply(rpostname, text)
|
|
replyname = reply["json"]["data"]["things"][0]["data"]["name"]
|
|
|
|
if (mod == 1):
|
|
print(f"Approving {rpostname}, {replyname}\n")
|
|
sleep(10)
|
|
resp = reddit_approve(rpostname)
|
|
reddit_approve(replyname)
|
|
|
|
id = post["id"]
|
|
f.truncate(0)
|
|
f.seek(0)
|
|
f.write(f'{id}\n')
|
|
if (id < max):
|
|
print("Waiting...\n")
|
|
sleep(3)
|
|
f.close()
|
|
sleep(120)
|