Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import praw
- import os
- import sys
- import time
- import re
- import tkinter
- import sqlite3
- data = sqlite3.connect('checked.db')
- cur = data.cursor()
- cur.execute('CREATE TABLE IF NOT EXISTS checked(id, created, username)')
- data.commit()
- os.system('@echo off')
- os.system('chcp 65001')
- patterns = ['testing']
- word = re.compile(r'\w+')
- def sign_in(*args):
- reddit = praw.Reddit(username=args[0],password=args[1],client_id=args[2],client_secret=args[3], user_agent=args[4])
- return reddit
- class search_submission(object):
- def __init__(self, submission):
- self.id = submission.id
- self.created = submission.created_utc
- self.submission = submission
- self.title = submission.title
- self.permalink = submission.permalink
- self.author = submission.author.name
- self.run()
- def submit_to_database(self):
- cur.execute('INSERT INTO checked VALUES(?,?,?)',[self.id,self.created,self.author])
- data.commit()
- def check_database(self):
- cur.execute('SELECT * FROM checked WHERE id=?',[self.id])
- if cur.fetchone():
- return False
- else:
- return True
- def submission_message(self):
- if self.check_database() is True:
- reddit.redditor('iNeverQuiteWas').message('{}'.format(self.title),'[{}]({})'.format(self.title,self.permalink))
- print('Sending message concerning {}'.format(self.author))
- self.submit_to_database()
- def comment_message(self,author, __permalink__, body,pattern_matched):
- if self.check_database() is True:
- reddit.redditor('iNeverQuiteWas').message('Comment Match','Found a match for "{}" by /u/{}. Check the following link:\n\n[{}]({})'.format(pattern_matched,author,body,__permalink__))
- print('Message sent')
- self.submit_to_database()
- def check_regex(self):
- title_text = word.findall(self.title)
- next((self.message() for thing in title_text if any(pattern in thing for pattern in patterns)),None)
- def check_comments(self):
- for comment in self.submission.comments:
- try:
- comment_text = word.findall(comment.body.lower())
- next((self.comment_message(comment.author.name,comment.permalink(), comment.body, thing) for thing in comment_text if any(pattern in thing for pattern in patterns)),None)
- except Exception as e:
- if e == KeyboardInterrupt:
- sys.exit()
- else:
- time.sleep(1)
- print('Unable to parse because {}'.format(e))
- def run(self):
- self.check_comments()
- def main():
- while True:
- for submission in reddit.subreddit('all').hot(limit=1000):
- try:
- search_submission(submission)
- except Exception as e:
- if e == KeyboardInterrupt:
- sys.exit()
- else:
- pass
- if __name__ == '__main__':
- reddit = sign_in('',
- '',
- '',
- '',
- '')
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement