Advertisement
Guest User

entavg

a guest
Nov 1st, 2013
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.83 KB | None | 0 0
  1. import praw
  2. user_agent = ("/r/trees high average checker")
  3. r = praw.Reddit(user_agent=user_agent)
  4. trees = r.get_subreddit('trees')
  5. submissions = trees.get_hot(limit=1)
  6. highs = []
  7.  
  8. def check_text(text):
  9.     indexes = []
  10.     i = 0
  11.     for character in text:
  12.         i+=1
  13.         if character == '[' or character == '{':
  14.             indexes.append(i)
  15.     for index in indexes:
  16.         try:
  17.             high = int(text[index])
  18.             highs.append(high)
  19.         except: pass
  20.  
  21. def check_submissions(amount=10):
  22.     submissions = trees.get_hot(limit=amount)
  23.     for submission in submissions:
  24.         check_text(submission.title)
  25.         for comment in submission.comments:
  26.             if not isinstance(comment, praw.objects.MoreComments): check_text(comment.body)
  27.  
  28. def check_avg():
  29.     total = 0
  30.     for high in highs:
  31.         total += high
  32.     return total/len(highs)
  33.  
  34. check_submissions(amount=100)
  35. print check_avg()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement