Advertisement
Guest User

Untitled

a guest
Mar 21st, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.38 KB | None | 0 0
  1. import praw
  2. import re
  3. import sys
  4. import threading
  5.  
  6. reddit = praw.Reddit(user_agent='',
  7. client_id='',
  8. client_secret='',
  9. username='',
  10. password='',
  11. check_for_updates=False,
  12. )
  13.  
  14. subreddit = reddit.subreddit('')
  15. pseudo = ''
  16. regex_mauvaise = 'm[ée]lanchon'
  17. regex_bonne = 'm[ée]lenchon'
  18. message = 'Jean-Luc Mél**e**nchon.'
  19.  
  20. class threadComments (threading.Thread):
  21. def run(self):
  22. for comment in subreddit.stream.comments():
  23. sys.stdout.write('.')
  24. if (re.search(regex_mauvaise, comment.body, re.IGNORECASE) and
  25. not re.search(regex_bonne, comment.body, re.IGNORECASE)):
  26. if not comment.author.name == pseudo:
  27. comment.refresh()
  28. replies = [x.author.name.lower() for x in comment.replies]
  29. if not pseudo in replies:
  30. print("\nMélanchon détecté !")
  31. print(comment)
  32. comment.reply(message)
  33. sys.stdout.flush()
  34.  
  35. class threadSubmissions (threading.Thread):
  36. def run(self):
  37. for submission in subreddit.stream.submissions():
  38. sys.stdout.write('-')
  39. if (re.search(regex_mauvaise, submission.title, re.IGNORECASE) and
  40. not re.search(regex_bonne, submission.title, re.IGNORECASE)):
  41. replies = [x.author.name.lower() for x in submission.comments]
  42. if not pseudo in replies:
  43. print("Mélanchon detecté !")
  44. print(submission.title)
  45. submission.reply(message)
  46.  
  47. a = threadComments()
  48. b = threadSubmissions()
  49. a.start()
  50. b.start()
  51. a.join()
  52. b.join()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement