Advertisement
Guest User

Untitled

a guest
Aug 16th, 2017
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.41 KB | None | 0 0
  1. cat mods.csv
  2. *******************************************
  3. resistmod,esist
  4. 71tsiser,esist
  5. thefrontofprogress,esist
  6. Shadowfacts-,esist
  7. IanDesmondsTutu,esist
  8. GuyBelowMeDoesntLift,esist
  9. yzlautum,esist
  10. 4thepower,esist
  11. v12a12,esist
  12. TheBearJulep,esist
  13. MaximumEffort433,esist
  14. AgentGarak,esist
  15. agentjulianbashir,esist
  16. PostimusMaximus,esist
  17. BernieSanskrit,esist
  18. Gsteel11,esist
  19. gets_it_mountie,marchagainsttrump
  20. Avenger_of_Justice,marchagainsttrump
  21. whatwildoes,marchagainsttrump
  22. Mannos_Hands_of_Fate,marchagainsttrump
  23. Jar_O_Memes,marchagainsttrump
  24. awkwardtheturtle,marchagainsttrump
  25. ChittyBangBangYeah,marchagainsttrump
  26. order1776,marchagainsttrump
  27. randoh12,marchagainsttrump
  28. Llim,marchagainsttrump
  29. Fabulastrophe,marchagainsttrump
  30. Goatsac,marchagainsttrump
  31. nameuser4321,marchagainsttrump
  32. specification,marchagainsttrump
  33. Merari01,marchagainsttrump
  34. TheSentinel_14,marchagainsttrump
  35. List_on_Somnia,marchagainsttrump
  36. DanglyW,againsthatesubreddits
  37. AutoModerator,againsthatesubreddits
  38. 75000_Tokkul,againsthatesubreddits
  39. LIATG,againsthatesubreddits
  40. WorseThanHipster,againsthatesubreddits
  41. NewJerseyFreakshow,againsthatesubreddits
  42. DubTeeDub,againsthatesubreddits
  43. Br00ce,againsthatesubreddits
  44. siouxsie_siouxv2,againsthatesubreddits
  45. duckvimes_,againsthatesubreddits
  46. Zachums,againsthatesubreddits
  47. awkwardtheturtle,againsthatesubreddits
  48. Deefian,againsthatesubreddits
  49. PizzaRollers,againsthatesubreddits
  50. TheSentinel_14,againsthatesubreddits
  51. TzHaar-ket-om,againsthatesubreddits
  52. ******************************************
  53. cat praw.ini
  54. ******************************************
  55. cat praw.ini
  56. [DEFAULT]
  57. # A boolean to indicate whether or not to check for package updates.
  58. check_for_updates=True
  59.  
  60. # Object to kind mappings
  61. comment_kind=t1
  62. message_kind=t4
  63. redditor_kind=t2
  64. submission_kind=t3
  65. subreddit_kind=t5
  66.  
  67. # The URL prefix for OAuth-related requests.
  68. oauth_url=https://oauth.reddit.com
  69.  
  70. # The URL prefix for regular requests.
  71. reddit_url=https://www.reddit.com
  72.  
  73. # The URL prefix for short URLs.
  74. short_url=https://redd.it
  75.  
  76. [HateSubredditBot]
  77. client_id=changeme
  78. client_secret=changeme
  79. password=changeme
  80. username=changeme
  81. user_agent=HateSubredditBot v0.2
  82.  
  83. ********************************************
  84. cat HateSubredditBot.py
  85. ********************************************
  86. #!/usr/bin/python
  87. import praw
  88. import pdb
  89. import re
  90. import os
  91. import csv
  92. # CHANGEME CHANGEME CHANGEME CHANGEME
  93.  
  94. postto_subreddit = "AgainstHateSubreddits"
  95.  
  96. # Read mods.csv file format modname,subredditname
  97.  
  98. file1reader = csv.reader(open("mods.csv"), delimiter=",")
  99.  
  100. # Create the Reddit instance
  101.  
  102. reddit = praw.Reddit('HateSubredditBot')
  103.  
  104. # Have we run this code before? If not, create an empty list
  105.  
  106. if not os.path.isfile("posts_replied_to.txt"):
  107. posts_replied_to = []
  108.  
  109. # If we have run the code before, load the list of posts we have replied to
  110. else:
  111. # Read the file into a list and remove any empty values
  112. with open("posts_replied_to.txt", "r") as f:
  113. posts_replied_to = f.read()
  114. posts_replied_to = posts_replied_to.split("\n")
  115. posts_replied_to = list(filter(None, posts_replied_to))
  116.  
  117. # For each user in the file1reader
  118. for username, subreddit in file1reader:
  119. user = reddit.redditor(username)
  120.  
  121. #Load their most recent 5 comments
  122. for comment in user.comments.new(limit=5):
  123. if comment.id not in posts_replied_to:
  124. # Extract the exact URL to the comment
  125. comment_url = comment.link_permalink + comment.id
  126. # Extract the text of the comment (up to 75 characters)
  127. comment_text = (comment.body[:75] + '..') if len(comment.body) > 75 else comment.body
  128. # Create the string we will use for the post title
  129. post_content = "r/"+subreddit+" mod u/" +username+" commented \"" + comment_text + "\""
  130. # Debugging only
  131. # print(comment_url)
  132. # print(post_content)
  133. # Submit the post to reddit
  134. reddit.subreddit(postto_subreddit).submit(post_content, url=comment_url)
  135. # Save in our list that we have posted this comment so we don't do it again
  136. posts_replied_to.append(comment.id)
  137.  
  138. # Write our updated list back to the file
  139. with open("posts_replied_to.txt", "w") as f:
  140. for post_id in posts_replied_to:
  141. f.write(post_id + "\n")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement