From 363d8d39acf7f37be6dd1f6f7646e1c3d64621b7 Mon Sep 17 00:00:00 2001 From: niggasinparis Date: Wed, 1 Feb 2023 20:34:43 +0530 Subject: [PATCH] Dump everything --- LICENSE | 5 +++ README | 14 +++++++ id | 1 + reddit.py | 118 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 138 insertions(+) create mode 100644 LICENSE create mode 100644 README create mode 100644 id create mode 100644 reddit.py diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..5135ae2 --- /dev/null +++ b/LICENSE @@ -0,0 +1,5 @@ +Copyright © 2023 by niggasinparis + +Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies. + +THE SOFTWARE IS PROVIDED “AS IS” AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. diff --git a/README b/README new file mode 100644 index 0000000..12c5e31 --- /dev/null +++ b/README @@ -0,0 +1,14 @@ +'id' contains an integer specifying the id (suchwow) of the last meme posted to reddit + +Steps: + Go to https://www.reddit.com/prefs/apps + Click "Create App" and select "script" + Enter any valid url as the redirect url + Enter any name in the name field ('Wowbot' preferred) + Copy the app key (below name) and replace with the key + Copy the app secret and replace with the secret + Replace and with your bot's credentials + +Workaround for spam filter: + Add your bot to your subreddit as a mod with perms to manage posts + Set mod=1 in the code diff --git a/id b/id new file mode 100644 index 0000000..a77fd92 --- /dev/null +++ b/id @@ -0,0 +1 @@ +6000 diff --git a/reddit.py b/reddit.py new file mode 100644 index 0000000..674e0e7 --- /dev/null +++ b/reddit.py @@ -0,0 +1,118 @@ +import requests, json +from time import sleep + +mod = 1 +headers = {'User-Agent': 'Wowbot/1.0.0'} +key = '' +secret = '' +account = {"username": '', "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)