Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # -*- coding: utf-8 -*-
- import io
- import time
- import traceback
- import config
- import praw
- import sys
- jerrynames = ['jerry','jerry\'s','jerrys','gary','garrys','garys','garry','garry\'s','gary\'s','larry','larrys','larry\'s','terry','terrys','terry\'s','mayor gergich','mayor gergichs','mayor gergich\'s']
- #jerrynames = ['test9']
- start_time = time.time()
- # File input
- f = open('cachefile.txt','r')
- with open('cachefile.txt') as f:
- id_cache = f.read().splitlines()
- f.close()
- def botlogin():
- print ("Logging in...")
- r = praw.Reddit(username=config.BOT_USERNAME,
- password=config.BOT_PASSWORD,
- client_id=config.BOT_CLIENT_ID,
- client_secret=config.BOT_CLIENT_SECRET,
- user_agent='Jerry\'s doctor bot v0.1')
- print ("Logged in!\n")
- return r
- def runbot(r):
- print ("\nSearching for a new Jerry post...\n")
- try:
- for submission in r.subreddit(config.TARGET_SUBREDDIT).stream.submissions():
- # Sterilizing the input
- lower_title = submission.title.lower()
- normalized_title = lower_title
- encoded_title = normalized_title.encode('utf-8')
- for name in jerrynames:
- if name in encoded_title:
- if submission.id not in id_cache:
- # Case switch using custom dictionary so that the comment matches the jerry name used in the post title
- def jerry():
- return "Jerry"
- def garry():
- return "Garry"
- def larry():
- return "Larry"
- def terry():
- return "Terry"
- nameSwitch = {
- "jerry" : jerry,
- "jerry\'s" : jerry,
- "jerrys" : jerry,
- "gary" : garry,
- "garys" : garry,
- "gary\'s" : garry,
- "garry" : garry,
- "garrys" : garry,
- "garry\'s" : garry,
- "larry" : larry,
- "larrys" : larry,
- "larry\'s" : larry,
- "terry" : terry,
- "terrys" : terry,
- "terry\'s" : terry,
- "mayor gergich" : jerry,
- "mayor gergichs" : jerry,
- "mayor gergich\'s" : jerry,
- }
- replyName = nameSwitch[name]()
- # New formatting experiment 10_16_2018
- reply_text = (
- "I noticed you mentioned " + str(replyName) + " Gergich...\n\nI'm [Dr. Harris, ](https://i.imgur.com/Tw6fQHA.jpg)his physician. The first time I saw him was for a routine mumps checkup."
- "\n\nThat man has *the largest penis I have ever seen*."
- "\n\nI actually don\'t even know if he has mumps. Forgot to look. I was distracted by..."
- "\r#the largest penis I have ever seen."
- "\n\n___"
- "\n\n[*I am just a bot.*](https://imgur.com/a/6Q93L6k) *That Eagletonian prick* /u/BackyrdFurnitureFire *built me.*")
- # This actually replies to the reddit post with a comment
- submission.reply(reply_text)
- print('Located a compatible Jerry submission!\nReplying to PandR post entitled: "{}"'.format(encoded_title))
- id_cache.append(submission.id)
- cachefile = open('cachefile.txt', 'w')
- for item in id_cache:
- cachefile.write(item + "\n")
- cachefile.close()
- print "\nid_cache = ",
- print (id_cache)
- # This just waits for a bit so we don't spam the sub too bad.
- print "\nSleeping for 10 seconds..."
- time.sleep(1)
- print "10..."
- time.sleep(1)
- print "9..."
- time.sleep(1)
- print "8..."
- time.sleep(1)
- print "7..."
- time.sleep(1)
- print "6..."
- time.sleep(1)
- print "5..."
- time.sleep(1)
- print "4..."
- time.sleep(1)
- print "3..."
- time.sleep(1)
- print "2..."
- time.sleep(1)
- print "1..."
- time.sleep(1)
- print "\nSearching for a new Jerry post...\n"
- break
- # This just lets us get out if we want to
- except BaseException as e:
- if type(e) == KeyboardInterrupt:
- sys.exit(0)
- else:
- traceback.print_exc()
- # This actually runs it
- r = botlogin()
- while True: # This is what keeps it running
- runbot(r)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement