Advertisement
inqw

Untitled

Jul 21st, 2017
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.46 KB | None | 0 0
  1. import praw
  2. import time
  3. import re
  4. import sqlite3
  5.  
  6. reddit = praw.Reddit(
  7.     username='earthpornbot2',
  8.     password='',
  9.     client_id='',
  10.     client_secret='',
  11.     user_agent='verfied email checker v1 by inqw',
  12.     api_request_delay=0)
  13.  
  14. def connect_database():
  15.     file = re.sub('\.\w+$','.db',__file__)
  16.     conn = sqlite3.connect(file)
  17.     return conn
  18.  
  19. def create_database():
  20.     file = open(re.sub('\.\w+$','.sql',__file__))
  21.     db = connect_database()
  22.     db.cursor().executescript(file.read())
  23.  
  24. class Profile:
  25.  
  26.     def __init__(self, submission):
  27.         self.submission = submission
  28.         self.author = submission.author
  29.         self.url = submission.url
  30.         self.permalink = submission.permalink
  31.         self.id = submission.id
  32.         self.conn = connect_database()
  33.         self.cur = self.conn.cursor()
  34.         self.__call__()
  35.  
  36.     @property
  37.     def hasRemoved(self):
  38.         content = self.cur.execute('select * from removed where submission_id=?',(self.id,)).fetchone()
  39.         if not content:
  40.             return False
  41.         else:
  42.             return True
  43.  
  44.     @property
  45.     def hasEmail(self):
  46.         trophies_url = '/api/v1/user/{}/trophies'
  47.         user = reddit.request('GET',trophies_url.format(self.author.name))['data']['trophies']
  48.         trophies = [thing['name'] for thing in [trophy['data'] for trophy in user]]
  49.         if 'Verified Email' in trophies:
  50.             return True
  51.         else:
  52.             return False
  53.  
  54.     @property
  55.     def youngAccount(self):
  56.         min_age_req = 90
  57.         current_time = time.time()
  58.         created_time = self.author.created_utc
  59.         difference = current_time - created_time
  60.         account_age = difference // (60 * 60 * 24)
  61.         if account_age < min_age_req:
  62.             return True
  63.         else:
  64.             return False
  65.  
  66.     def addEntry(self):
  67.         self.cur.execute('insert into removed values(?,?,?)',(self.author.name, self.permalink, self.id,))
  68.         self.cur.execute('insert into authors values(?)',(self.author.name,))
  69.         self.conn.commit()
  70.  
  71.     def __call__(self):
  72.         try:
  73.             if (self.youngAccount and not self.hasEmail) and not self.hasRemoved:
  74.                 self.addEntry()
  75.                 self.submission.mod.remove()
  76.                 return True
  77.             else:
  78.                 return False
  79.         except:
  80.             return False
  81.  
  82. def accept_invites(inbox):
  83.     for message in inbox:
  84.         if 'invitation to moderate' in message.subject:
  85.             try:
  86.                 message.subreddit.mod.accept_invite()
  87.                 message.mark_read()
  88.             except:
  89.                 pass
  90.            
  91. def main():
  92.     for submission in reddit.subreddit('earthporn').stream.submissions():
  93.         post = Profile(submission)
  94.         if post == True:
  95.             print("Removed submission by /u/{}".format(submission.author.name))
  96.  
  97. if __name__ == '__main__':
  98.     main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement