Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import praw
- import re
- import sys
- import threading
- reddit = praw.Reddit(user_agent='RobotMelenchon',
- client_id='',
- client_secret='',
- username='ecrire_melenchon',
- password='',
- check_for_updates=False,
- )
- subreddit = reddit.subreddit('france+europe')
- pseudo = 'ecrire_melenchon'
- regex_mauvaise = 'm[ée]lanchon'
- regex_bonne = 'm[ée]lenchon'
- message = 'Jean-Luc Mél**e**nchon.'
- class threadComments (threading.Thread):
- def run(self):
- for comment in subreddit.stream.comments():
- sys.stdout.write('.')
- if (re.search(regex_mauvaise, comment.body, re.IGNORECASE) and
- not re.search(regex_bonne, comment.body, re.IGNORECASE)):
- if not comment.author.name == pseudo:
- comment.refresh()
- replies = [x.author.name.lower() for x in comment.replies]
- if not pseudo in replies:
- print("\nMélanchon détecté !")
- print(comment)
- comment.reply(message)
- sys.stdout.flush()
- class threadSubmissions (threading.Thread):
- def run(self):
- for submission in subreddit.stream.submissions():
- sys.stdout.write('-')
- if (re.search(regex_mauvaise, submission.title, re.IGNORECASE) and
- not re.search(regex_bonne, submission.title, re.IGNORECASE)):
- replies = [x.author.name.lower() for x in submission.comments]
- if not pseudo in replies:
- print("Mélanchon detecté !")
- print(submission.title)
- submission.reply(message)
- a = threadComments()
- b = threadSubmissions()
- a.start()
- b.start()
- a.join()
- b.join()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement