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
- import datetime
- data = sqlite3.connect('checked.db')
- cur = data.cursor()
- cur.execute('CREATE TABLE IF NOT EXISTS checked(id, created, username)')
- data.commit()
- sub = 'Discgolf'
- os.system('@echo off')
- os.system('chcp 65001')
- patterns = ['MVP','gyro','overmold','energy','nitro','octane','catalyst','phase','photon','wave','orbital','motion','tesla','inertia','impulse','shock','volt','amp','resistor','servo','switch','relay','signal','matrix','vector','axis','tensor','tangent','ion','anode','spin','atom','axiom','thrill','defy','vanish','fireball','wrath','insanity','virus','clash','crave','inspire','alias','theory','envy','proxy','streamline','streamlined','solomold','lost','portal','pro','basket','voyager']
- 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 message(self):
- if self.check_database() is True and time.mktime(datetime.datetime.now().timetuple()) - self.submission.created_utc < (60*60*1.5):
- reddit.redditor('MVP_Steve').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('****').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)
- if any(pattern in self.title for pattern in patterns if ' ' in pattern):
- self.message()
- 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)
- if any(pattern in comment.body.lower() for pattern in patterns if ' ' in pattern):
- self.comment_message(comment.author.name,comment.permalink(), comment.body, pattern)
- except Exception as e:
- if e == KeyboardInterrupt:
- sys.exit()
- else:
- pass
- def run(self):
- self.check_comments()
- self.check_regex()
- def main():
- while True:
- for submission in reddit.subreddit(sub).hot(limit=1000):
- try:
- search_submission(submission)
- except Exception as e:
- if e == KeyboardInterrupt:
- sys.exit()
- else:
- pass
- time.sleep(2)
- if __name__ == '__main__':
- reddit = sign_in('DataCollectionBot',
- 'w0rd543rch1ng',
- 'xIZ1lwxV5P5tVQ',
- 'areezNIh8UbUIkBz6icMAf7GFZQ',
- 'An agent to search for words on Reddit')
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement