Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #imports
- import praw
- import time
- import os
- from datetime import date
- from os import environ
- #get date
- today = date.today().strftime("%m/%d/%Y")
- print (today)
- #defining variables for later use
- keyphrase = ("!claim ")
- space = (" ")
- extra_line = ("\n")
- #bot login
- def bot_login():
- print("logging in")
- r = praw.Reddit(username=environ["USERNAME"],
- password=environ["PASSWORD"],
- client_id=environ["CLIENT_ID"],
- client_secret=environ["CLIENT_SECRET"],
- user_agent="Waifu-Claimer.bot.v0.1")
- print("logged in")
- return r
- #bot run-process
- def run_bot(r, claimed_waifus, previous_claimers):
- print("obtaining comments...")
- for comment in r.subreddit('WaifuClaimer').comments(limit=70):
- submission = comment
- if "!claim " in comment.body and comment.id not in comments_replied_to and comment.author != r.user.me():
- waifu = comment.body.replace(keyphrase, '')
- waifu_official = waifu.lower().replace(space,'').replace(extra_line,'')
- claimer = submission.author.name
- print("claim for " + waifu_official)
- print("comment replied to: " + comment.id + " by " + claimer)
- try:
- if waifu_official not in claimed_waifus:
- previous_claimers.append(claimer)
- with open ("previous_claimers.txt", "a") as p:
- p.write(claimer + "\n")
- claimed = (previous_claimers.count(claimer))
- print("user has claimed " + str(claimed))
- if claimed == 1:
- comment.reply("[Congrats](https://i.imgur.com/HTQcCLn.gif), " + waifu + " was claimed! You have claimed " + str(claimed) + " waifu now. I sense the beginnings of an excellent harem." + "\n\n ^Click ^[here](https://www.reddit.com/r/WaifuClaimer/comments/jwohm8/waifuclaimer_bot_directory/?utm_source=share&utm_medium=web2x&context=3) ^for ^bot ^directory.")
- else:
- comment.reply("[Congrats](https://i.imgur.com/HTQcCLn.gif), " + waifu + " was claimed! You have claimed " + str(claimed) + " waifus now." + "\n\n ^Click ^[here](https://www.reddit.com/r/WaifuClaimer/comments/jwohm8/waifuclaimer_bot_directory/?utm_source=share&utm_medium=web2x&context=3) ^for ^bot ^directory.")
- claimed_waifus.append(waifu_official)
- r.subreddit('WaifuClaimer').submit(waifu + " has been claimed by u/" + claimer,selftext=("Claimer: u/" + claimer + "\n" + "\n" + "Waifu: " + waifu + "\n" + "\n" + "Date: " + today), url=None, flair_id="eebc0dc8-1d8d-11eb-be0c-0e3512b41733")
- with open ("claimed_waifus.txt", "a") as g:
- g.write(waifu_official + "\n")
- else:
- comment.reply("Sorry, someone else has already claimed them." + "\n\n ^Click ^[here](https://youtu.be/L9EDYkn4oUU) ^for ^bot ^directory.")
- except:
- print("error")
- comments_replied_to.append(comment.id)
- with open ("comments_replied_to.txt", "a") as f:
- f.write(comment.id + "\n")
- print("sleeping for 10 seconds")
- #sleep for 10 seconds...
- time.sleep(10)
- #read list of comments replied to
- def get_saved_comments():
- if not os.path.isfile("comments_replied_to.txt"):
- comments_replied_to = []
- else:
- with open("comments_replied_to.txt", "r") as f:
- comments_replied_to = f.read()
- comments_replied_to = comments_replied_to.split("\n")
- return comments_replied_to
- #read list of waifus claimed
- def get_claimed_waifus():
- if not os.path.isfile("claimed_waifus.txt"):
- claimed_waifus = []
- else:
- with open("claimed_waifus.txt", "r") as g:
- claimed_waifus = g.read()
- claimed_waifus = claimed_waifus.split("\n")
- return claimed_waifus
- #read list of users that have claimed a waifu
- def get_previous_claimers():
- if not os.path.isfile("previous_claimers.txt"):
- previous_claimers = []
- else:
- with open("previous_claimers.txt", "r") as p:
- previous_claimers = p.read()
- previous_claimers = previous_claimers.split("\n")
- return previous_claimers
- #defining more variables
- r = bot_login()
- comments_replied_to = get_saved_comments()
- claimed_waifus = get_claimed_waifus()
- previous_claimers = get_previous_claimers()
- print ("comments_replied_to and claimed_waifus")
- #active part of script
- while True:
- run_bot(r, claimed_waifus, previous_claimers)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement