Guest User

RedditBot /r/competitiveoverwatch

a guest
Aug 29th, 2016
29
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.54 KB | None | 0 0
  1. import requests
  2. from   bs4 import BeautifulSoup
  3. import praw
  4. import webbrowser
  5. import time
  6.  
  7. def parse_data(keyword):
  8.     url = ('http://overwatch.gamepedia.com/{0}'.format(keyword))
  9.     raw = requests.get(url)
  10.     soup = BeautifulSoup(raw.text, 'html.parser')
  11.     bio = soup.find('table', 'infoboxtable')
  12.     player = {}
  13.  
  14.     for weapon in soup.select('.ability_details'):
  15.         name = weapon.find('span').text
  16.         player[name] = {}
  17.  
  18.         for div in weapon.select('.infoboxtable td > div'):
  19.             stat  = div.text.strip().encode('utf-8')
  20.             value = div.find_parent('td').find_next('td').text.strip().encode('utf-8')
  21.             player[name][stat] = value
  22.  
  23.     playerlist = []
  24.  
  25.     for key, value in player.items():
  26.         temp = [key,value]
  27.         playerlist.append(temp)
  28.     return playerlist
  29.  
  30. def scan_reddit():
  31.     r = praw.Reddit(user_agent='OW WikiHelp developed (by /u/Superf1cial)',
  32.                     client_id='', client_secret="",
  33.                     username='NAME', password='PW')
  34.  
  35.     already_done = set()
  36.  
  37.     keywords= ['Genji', 'McCree', 'Pharah', 'Reaper', 'Tracer', 'Bastion', 'Hanzo', 'Junkrat',
  38.                'Mei', 'Torbjörn', 'Widowmaker', 'D.Va', 'Reinhardt', 'Roadhog', 'Winston', 'Zarya',
  39.                'Ana', 'Lucio', 'Mercy', 'Symettra', 'Zenyatta']
  40.  
  41.     subreddit = r.get_subreddit('competitiveoverwatch')
  42.     for c in praw.helpers.comment_stream(r, subreddit):
  43.         has_word = any(string in c.body for string in keywords)
  44.         if c.id not in already_done and has_word:
Add Comment
Please, Sign In to add comment