Advertisement
Guest User

BlackCatBot.py

a guest
Jul 9th, 2015
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.46 KB | None | 0 0
  1. #!/usr/bin/python
  2.  
  3. import praw
  4.  
  5. import pickle, random, time
  6.  
  7. username=""
  8. password=""
  9.  
  10. r=praw.Reddit(user_agent="linux, script on pythonanywhere.com, which likes /r/BlackCats users cats (by /u/ilikeyourblackcat)")
  11.  
  12. r.login(username, password)
  13.  
  14. subreddit = r.get_subreddit('blackcats')
  15.  
  16. with open('blackCatBot.db', 'r') as pickle_in:
  17. done = pickle.load(pickle_in)
  18.  
  19.  
  20. ''' ---------------------------------------------------------------------------------------------------------------- '''
  21. ''' These below are the membership groups and their membership customized replies. '''
  22. ''' ---------------------------------------------------------------------------------------------------------------- '''
  23. default_replies = ["I like your black cat.", "Nice black cat.", "Your black cat is too cute.", "As dark as a shadow.",
  24. "What a cute shadow you have!", "Dark as midnight.", "Too cute to be a superstition!",
  25. "Wow. This is like I'm looking at my own little sweetie!", "I am the night. I am a blackcat!",
  26. "Velvety paws! So cute!", "Cuddle Bug!", "Now THAT is an adoring look!", "Cutie pie! Black cats are best cats.",
  27. "Too purrfect!", "Have you noticed that black cats are more relaxed than other cats?",
  28. "People are just jealous of the gorgeous sable color.", "It's so hard to get pictures of black cats",
  29. "What a cute baby.", "Black Velvet! Purrrrrfect!", "Look at that little face! Precious.",
  30. "I'm convinced black cats are solar powered and basking is their way of recharging their batteries for late night crazies.",
  31. "Is your cat solid black, or does it have some different colors in its undercoat? Gorgeous!",
  32. "Black cats love the sun, don't they!?", "Black cats just have the best little personalities. Too cute!",
  33. "Look at those eyes! So beautiful!", "Mesmerizing!", "Your cat is exactly like my baby! They could be twins!",
  34. "Cutie pie!", "What a cutie!", "Bellyrub!", "What a beautiful sweet kitty.", "Cats are made of stars.",
  35. "I love the floofy tail!"]
  36. ''' ---------------------------------------------------------------------------------------------------------------- '''
  37. XX = ["She", "Girl", "Pretty", "Ms.", "Ms", "Miss", "Mrs.", "Mrs", "Lady"]
  38. XY = ["Mr.", "Mr", "Handsome", "His", "Gentleman", "Gentlemen", "He"]
  39. XXreply = ["Her fur is cool, and it's black.", "She is quite the charmer.", "What a lovely lass there!",
  40. "She is a pretty black cat.", "She is so beautiful!", "So majestic. I want 8 of her!."]
  41. XYreply = ["His fur is cool, and it's black.", "He is quite the handsome boy.", "What a gentleman there!",
  42. "He is a handsome black cat.", "Very cute! Wish I had a tiny little black guy just like him.", "So majestic. I want 8 of him!"]
  43. ''' ---------------------------------------------------------------------------------------------------------------- '''
  44. #Regulars = ["Kuro", "Spam", "Felix", "Xander", "Fritz", "Ent"]
  45. #RegularReply = ["It is always a pleasure to see %s on Black Cats.", "Good to see you again %s!"]
  46. Kuro = ["Kuro"]
  47. KuroReply = ["It is always a pleasure to see Kuro on Black Cats.", "Good to see you again Kuro!",
  48. "Kuro, it's an honor to see you again!", "Kuro, have you been getting more vocal?",
  49. "I wish I had a kitty just like Kuro!"]
  50. Spam = ["Spam"]
  51. SpamReply = ["It is always a pleasure to see Spam on Black Cats.", "Good to see you again Spam!",
  52. "Spam, it's an honor to see you again!"]
  53. Felix = ["Felix"]
  54. FelixReply = ["It is always a pleasure to see Felix on Black Cats.", "Good to see you again Felix!",
  55. "Felix, it's an honor to see you again!"]
  56. Xander = ["Xander"]
  57. XanderReply = ["It is always a pleasure to see Xander on Black Cats.", "Good to see you again Xander!",
  58. "Xander, it's an honor to see you again!"]
  59. Ent = ["Ent"]
  60. EntReply = ["It is always a pleasure to see Ent on Black Cats.", "Good to see you again Ent!",
  61. "Ent, it's an honor to see you again!"]
  62. Fritz = ["Fritz"]
  63. FritzReply = ["Oh you silly Fritz, what are you up to this time!?", "Fritz is a special cat.",
  64. "Fritz, you look like you could use a kitty breakfast taco!", "I wish I had a kitty just like Fritz!"]
  65. ''' ---------------------------------------------------------------------------------------------------------------- '''
  66.  
  67.  
  68. def Word(inTitle, inGroup):
  69.  
  70. alphabet_space = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S',
  71. 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', ' ']
  72. preNewString = []
  73. for i in inTitle.lower():
  74. if i in [j.lower() for j in alphabet_space]:
  75. preNewString.append(i)
  76. cleanString = ''.join(preNewString)
  77.  
  78. titleAsList = cleanString.split(' ')
  79. inGroup = [i.lower() for i in inGroup]
  80.  
  81. for i in titleAsList:
  82. if i in inGroup:
  83. return True
  84.  
  85.  
  86. def main():
  87.  
  88. submissions = subreddit.get_new()
  89.  
  90. for submission in submissions:
  91.  
  92. if submission.id not in done:
  93.  
  94. done.append(submission.id)
  95. with open('blackCatBot.db', 'w') as pickle_out:
  96. pickle.dump(done, pickle_out)
  97.  
  98. if submission.is_self == True:
  99.  
  100. if Word(submission.title, Fritz) == True:
  101. submission.add_comment(random.choice(FritzReply))
  102.  
  103. elif Word(submission.title, Kuro) == True:
  104. submission.add_comment(random.choice(KuroReply))
  105.  
  106. elif Word(submission.title, Spam) == True:
  107. submission.add_comment(random.choice(SpamReply))
  108.  
  109. elif Word(submission.title, Felix) == True:
  110. submission.add_comment(random.choice(FelixReply))
  111.  
  112. elif Word(submission.title, Xander) == True:
  113. submission.add_comment(random.choice(XanderReply))
  114.  
  115. elif Word(submission.title, Ent) == True:
  116. submission.add_comment(random.choice(EntReply))
  117.  
  118. elif Word(submission.title, XX) == True:
  119. submission.add_comment(random.choice(XXreply))
  120.  
  121. elif Word(submission.title, XY) == True:
  122. submission.add_comment(random.choice(XYreply))
  123.  
  124. else:
  125. submission.add_comment(random.choice(default_replies))
  126.  
  127.  
  128. if __name__ == "__main__":
  129. while True:
  130. try:
  131. main()
  132. except Exception as e:
  133. log="Error: "+str(e)+" @ "+str(time.time())
  134. with open('blackCatBot.log', 'a') as f:
  135. f.writelines(log)
  136. print "Sleeping for 10 minutes."
  137. time.sleep(600)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement