Advertisement
Guest User

Untitled

a guest
Jun 16th, 2016
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.44 KB | None | 0 0
  1. import praw
  2. import time
  3.  
  4. class getPms():
  5.  
  6. r = praw.Reddit(user_agent="Test Bot By /u/TheC4T")
  7. r.login(username='*************', password='***************')
  8.  
  9. cache = []
  10. inboxMessage = []
  11. file = 'cache.txt'
  12.  
  13. def __init__(self):
  14. cache = self.cacheRead(self, self.file)
  15. self.bot_run(self)
  16. self.cacheSave(self, self.file)
  17. time.sleep(5)
  18. return self.inboxMessage
  19.  
  20. def getPms(self):
  21. def bot_run():
  22. inbox = self.r.get_inbox(limit=25)
  23. print(self.cache)
  24. # print(r.get_friends())#this works
  25. for message in inbox:
  26. if message.id not in self.cache:
  27. # print(message.id)
  28. print(message.body)
  29. # print(message.subject)
  30. self.cache.append(message.id)
  31. self.inboxMessage.append(message.body)
  32. # else:
  33. # print("no messages")
  34.  
  35. def cacheSave(self, file):
  36. with open(file, 'w') as f:
  37. for s in self.cache:
  38. f.write(s + 'n')
  39.  
  40. def cacheRead(self, file):
  41. with open(file, 'r') as f:
  42. cache1 = [line.rstrip('n') for line in f]
  43. return cache1
  44.  
  45. # while True: #threading is needed in order to run this as a loop. Probably gonna do this in the main method though
  46.  
  47.  
  48. # def getInbox(self):
  49. # return self.inboxMessage
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement