Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2016
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.64 KB | None | 0 0
  1. app_ua = 'Comment collector by uMatthewBetts'
  2. app_id = ''
  3. app_secret = ''
  4. app_uri = 'https://127.0.0.1:65010/authorize_callback'
  5. app_scopes = 'account creddits edit flair history identity livemanage modconfig modcontributors modflair modlog modothers modposts modself modwiki mysubreddits privatemessages read report save submit subscribe vote wikiedit wikiread'
  6. app_account_code = '' #wtf is this for?
  7. app_refresh = ''
  8.  
  9. #USERNAME = ''
  10. #PASSWORD = ''
  11.  
  12. import praw
  13. import time
  14. import sqlite3
  15.  
  16. MAXPOSTS = 15
  17. SUBREDDIT = 'all'
  18.  
  19. unParsedComments = []
  20.  
  21. print("Starting up Database")
  22. sql = sqlite3.connect('reddit_comments.db')
  23. cur = sql.cursor()
  24. print("Creating database if it doesn't exist")
  25. cur.execute('CREATE TABLE IF NOT EXISTS posts (COMMENTS varchar NOT NULL)')
  26. sql.commit
  27.  
  28. print("Accessing account...")
  29. r = praw.Reddit(app_ua)
  30. r.set_oauth_app_info(app_id, app_secret, app_uri)
  31. r.refresh_access_information(app_refresh)
  32. print('Logged in.')
  33.  
  34. while (True):
  35.     print("Fetching subreddit " + SUBREDDIT)
  36.     subreddit = r.get_subreddit(SUBREDDIT)
  37.     print("Fetching Comments...")
  38.     all_comments = subreddit.get_comments(limit=MAXPOSTS)
  39.     print("Adding comments...")
  40.     for comment in all_comments:
  41.         text = comment.body
  42.         unParsedComments.append(text)
  43.         joinedComments = ''.join(map(str, unParsedComments))
  44.         cur.execute('INSERT INTO posts VALUES (?)', (joinedComments,))
  45.         sql.commit()
  46.         try:
  47.             print(unParsedComments)
  48.         except:
  49.             print("error")
  50.         del unParsedComments[:]
  51.     print('Pulling new comments')
  52.     del unParsedComments[:]
  53.     time.sleep(10)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement