Advertisement
Guest User

Untitled

a guest
Apr 28th, 2019
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.46 KB | None | 0 0
  1. import praw
  2. import time
  3. import re
  4. import datetime
  5.  
  6. reddit = praw.Reddit(client_id='',
  7. client_secret='',
  8. username='',
  9. password='',
  10. user_agent='')
  11.  
  12. print("Reddit account: connected")
  13.  
  14.  
  15. # searching text file for post
  16. def check_reply(post_id):
  17. with open("already_replied.txt", "r") as f:
  18. contents = f.readlines()
  19. if contents == []:
  20. return False
  21. for line in contents:
  22. line = str(line.replace("\n", ""))
  23. post_id = str(post_id.replace(" ", ""))
  24. if line == post_id:
  25. return True
  26. else:
  27. return False
  28.  
  29.  
  30. # adding submission id to file
  31. def add_reply(post_id):
  32. with open("already_replied.txt", "w") as f:
  33. f.write(post_id + "\n")
  34.  
  35.  
  36. # setting global variables
  37. subreddit = reddit.subreddit("Memeeconomy")
  38. submissions = subreddit.stream.submissions()
  39.  
  40. # setting blacklisted words.
  41. blacklisted_words = ['Test', 'test']
  42.  
  43. for submission in submissions:
  44. # check time
  45. time_created = submission.created_utc
  46. time_now = time.time()
  47. # check if the meme came from SOL
  48. if re.search("SOL Enterprises", str(submission.author_flair_text), re.IGNORECASE):
  49. if time_now-time_created < 600:
  50. for word in blacklisted_words:
  51. # attempting to not comment on traps
  52. if word in submission.title:
  53. print("Trap meme found.")
  54. continue
  55.  
  56. if check_reply(submission.id) is False:
  57. for reply in submission.comments.list():
  58. if reply.author == "MemeInvestor_bot":
  59. print("Replying to post {0}".format(submission.title))
  60. add_reply(submission.id)
  61. time.sleep(1)
  62. reply.reply("!invest 100%")
  63. print("Replied")
  64. time.sleep(1)
  65. submission.upvote()
  66. print("Going to sleep for 4 hours")
  67. time.sleep(14100)
  68. else:
  69. continue
  70. else:
  71. print("Already posted on {}".format(submission.title))
  72. else:
  73. print("SOL meme found but posted too long ago: {0}".format(submission.title))
  74. else:
  75. continue
  76.  
  77. print("Sleeping")
  78. time.sleep(20)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement