Advertisement
mcgintyj1

Untitled

Mar 30th, 2018
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.31 KB | None | 0 0
  1. # rowanbot
  2.  
  3. import praw
  4. from PyDictionary import PyDictionary
  5. import enchant
  6.  
  7. # reddit api
  8. reddit = praw.Reddit(client_id='XXX',
  9. client_secret='XXX',
  10. redirect_uri='http://localhost:8080',
  11. user_agent='/r/RowanUniversity bot by /u/mcgintyj1',
  12. password='XXX',
  13. username='XXX')
  14.  
  15. print(reddit.auth.url(['identity'], '...', 'permanent'))
  16. reddit.auth.authorize(['code'])
  17. print(reddit.user.me())
  18.  
  19. # subreddits
  20. subreddit = reddit.subreddit('RowanUniversity')
  21.  
  22. #activation phrase
  23. keyphrase = '!Rowan '
  24.  
  25. #dictionary and word check
  26. dictionary = PyDictionary()
  27.  
  28. def isWord(word):
  29. return d.check(word)
  30.  
  31. # what to reply to
  32. for comment in subreddit.stream.comments():
  33. if keyphrase in comment.body:
  34. word = comment.body.replace(keyphrase, '')
  35. try:
  36. if isWord(word):
  37. # defintion
  38. words = dictionary.meaning(word)
  39. reply = [item[0] for item in words.values()]
  40. comment.reply(word + ': ' + reply[0])
  41. print('posted')
  42. else:
  43. reply = 'This is not a word.'
  44. comment.reply(reply)
  45. print('posted')
  46. except:
  47. print('to frequent')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement