Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import praw
- import time
- class getPms():
- r = praw.Reddit(user_agent="Test Bot By /u/TheC4T")
- r.login(username='*************', password='***************')
- cache = []
- inboxMessage = []
- file = 'cache.txt'
- def __init__(self):
- cache = self.cacheRead(self, self.file)
- self.bot_run(self)
- self.cacheSave(self, self.file)
- time.sleep(5)
- return self.inboxMessage
- def getPms(self):
- def bot_run():
- inbox = self.r.get_inbox(limit=25)
- print(self.cache)
- # print(r.get_friends())#this works
- for message in inbox:
- if message.id not in self.cache:
- # print(message.id)
- print(message.body)
- # print(message.subject)
- self.cache.append(message.id)
- self.inboxMessage.append(message.body)
- # else:
- # print("no messages")
- def cacheSave(self, file):
- with open(file, 'w') as f:
- for s in self.cache:
- f.write(s + 'n')
- def cacheRead(self, file):
- with open(file, 'r') as f:
- cache1 = [line.rstrip('n') for line in f]
- return cache1
- # while True: #threading is needed in order to run this as a loop. Probably gonna do this in the main method though
- # def getInbox(self):
- # return self.inboxMessage
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement