本文整理汇总了Python中Actions.get_unread方法的典型用法代码示例。如果您正苦于以下问题:Python Actions.get_unread方法的具体用法?Python Actions.get_unread怎么用?Python Actions.get_unread使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Actions
的用法示例。
在下文中一共展示了Actions.get_unread方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: run
# 需要导入模块: import Actions [as 别名]
# 或者: from Actions import get_unread [as 别名]
def run(self):
while True:
if not self.check_status():
break
# see if we need to update mods
if datetime.datetime.now() - self.last_mod_update > self.policy.Mod_Update_Period:
if __debug__:
logging.info(u"Blacklist Query updating mod list...")
self.update_mods()
if __debug__:
logging.info(u"Modlist updated to: {}".format(u", ".join(self.mod_list)))
# get unread
unread = Actions.get_unread(self.praw, limit=self.policy.Unread_To_Load)
try:
messages = [message for message in unread]
if __debug__:
logging.info(u"Blacklist query processing {} messages...".format(len(messages)))
for message in messages:
self.process_message(message)
if __debug__:
logging.info(u"Blacklist query processing message from user {}.\nSubject:{}\nBody:{}".
format(message.author.name if message.author.name is not None else u"DELETED",
message.subject, message.body))
except Exception, e:
logging.error(u"Error on retrieving unread messages")
if __debug__:
logging.exception(e)
self.log_error()
self.message_cache = []
# and wait (min of 30s to prevent return of cached answers on default PRAW install)
time.sleep(max(self.policy.Blacklist_Query_Period, 30))
示例2: test_get_message
# 需要导入模块: import Actions [as 别名]
# 或者: from Actions import get_unread [as 别名]
def test_get_message(credentials):
r = praw.Reddit(user_agent=credentials['USERAGENT'])
r.login(username=credentials['ALTUSER'], password=credentials['ALTPASS'])
messages = a.get_unread(r)
message = messages.next()
success = message.author.name == 'centralscruuutinizer' and message.body == "testmessage" and message.subject == "test"
if success:
print "Test Get Message: Passed"
return True
print "Test Get Message: Failed"
return True
示例3: test_blacklist_query
# 需要导入模块: import Actions [as 别名]
# 或者: from Actions import get_unread [as 别名]
def test_blacklist_query():
try:
os.remove("test_database.db")
except:
pass
credentials = CRImport("TestCredentials.cred")
credentials["SUBREDDIT"] = "centralscrutinizer"
# swap usernames
temp = credentials['USERNAME']
credentials['USERNAME'] = credentials['ALTUSER']
credentials['ALTUSER'] = temp
temp = credentials['PASSWORD']
credentials['PASSWORD'] = credentials['ALTPASS']
credentials['ALTPASS'] = temp
#get subs
mypraw = u.create_multiprocess_praw(credentials)
pol = Policies.DebugPolicy(None)
#alt user
my_handler = praw.handlers.MultiprocessHandler()
r = praw.Reddit(user_agent="message-send-test", handler=my_handler)
r.login(username=credentials['ALTUSER'], password=credentials['ALTPASS'])
#mark all old as read
for x in a.get_unread(mypraw, None):
x.mark_as_read()
for x in a.get_unread(r, None):
x.mark_as_read()
class author_dummy:
def __init__(self):
self.name = credentials['ALTUSER']
class message_dummy:
def __init__(self, text, id):
self.author = author_dummy()
self.body = text
self.id = id
self.subject = "test"
def mark_as_read(self):
pass
print "Starting Blacklist Query tests..."
#h'ok here we go.
#first we'll create three posts from a black/whitelisted channel and a not found
with DataBase.DataBaseWrapper("test_database.db") as db:
entries = [
("arghdos", "youtube.com", "http://www.youtube.com/user/arghdos", Blacklist.BlacklistEnums.Whitelisted, 0),
("IGN", "youtube.com", "http://www.youtube.com/user/IGN", Blacklist.BlacklistEnums.Blacklisted, 0),
("Karen Jones", "youtube.com", "http://www.youtube.com/user/Karen Jones", Blacklist.BlacklistEnums.NotFound,
0)]
db.add_channels(entries)
#create scrutinizer
cs = CentralScrutinizer.CentralScrutinizer(credentials, pol, "test_database.db")
bq = cs.bquery
print "Testing Add/Remove..."
#test print functions
id = 0
message = message_dummy("add\nwhitelist\nhttp://soundcloud.com/maggiesmithmusic/100-needles-for-zil", id)
id += 1
result = bq.process_message(message)
r_list = db.get_channels(blacklist=Blacklist.BlacklistEnums.Whitelisted, domain="soundcloud",
id_filter="MaggieSmithMusic")
if not len(r_list) or result != "":
print "Failed"
return False
message = message_dummy("remove\nwhitelist\nMaggieSmithMusic\nsoundcloud", id)
id += 1
result = bq.process_message(message)
#result should be "" and "" should be listed in the message
r_list = db.get_channels(blacklist=Blacklist.BlacklistEnums.Whitelisted, domain="soundcloud",
id_filter="MaggieSmithMusic")
if len(r_list) or result != "":
print "Failed"
return False
message = message_dummy("add\nblacklist\nhttp://soundcloud.com/maggiesmithmusic/100-needles-for-zil", id)
id += 1
result = bq.process_message(message)
r_list = db.get_channels(blacklist=Blacklist.BlacklistEnums.Blacklisted, domain="soundcloud",
id_filter="MaggieSmithMusic")
if not len(r_list) or result != "":
print "Failed"
return False
message = message_dummy("remove\nblacklist\nhttp://soundcloud.com/maggiesmithmusic/100-needles-for-zil", id)
id += 1
result = bq.process_message(message)
#result should be "" and "" should be listed in the message
r_list = db.get_channels(blacklist=Blacklist.BlacklistEnums.Blacklisted, domain="soundcloud",
id_filter="MaggieSmithMusic")
if len(r_list) or result != "":
print "Failed"
#.........这里部分代码省略.........