本文整理汇总了Python中findspam.FindSpam.test_post方法的典型用法代码示例。如果您正苦于以下问题:Python FindSpam.test_post方法的具体用法?Python FindSpam.test_post怎么用?Python FindSpam.test_post使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类findspam.FindSpam
的用法示例。
在下文中一共展示了FindSpam.test_post方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: check_blacklist
# 需要导入模块: from findspam import FindSpam [as 别名]
# 或者: from findspam.FindSpam import test_post [as 别名]
def check_blacklist(string_to_test, is_username, is_watchlist):
# Test the string and provide a warning message if it is already caught.
if is_username:
question = Post(api_response={'title': 'Valid title', 'body': 'Valid body',
'owner': {'display_name': string_to_test, 'reputation': 1, 'link': ''},
'site': "", 'IsAnswer': False, 'score': 0})
answer = Post(api_response={'title': 'Valid title', 'body': 'Valid body',
'owner': {'display_name': string_to_test, 'reputation': 1, 'link': ''},
'site': "", 'IsAnswer': True, 'score': 0})
else:
question = Post(api_response={'title': 'Valid title', 'body': string_to_test,
'owner': {'display_name': "Valid username", 'reputation': 1, 'link': ''},
'site': "", 'IsAnswer': False, 'score': 0})
answer = Post(api_response={'title': 'Valid title', 'body': string_to_test,
'owner': {'display_name': "Valid username", 'reputation': 1, 'link': ''},
'site': "", 'IsAnswer': True, 'score': 0})
question_reasons, _ = FindSpam.test_post(question)
answer_reasons, _ = FindSpam.test_post(answer)
# Filter out duplicates
reasons = list(set(question_reasons) | set(answer_reasons))
# Filter out watchlist results
if not is_watchlist:
reasons = list(filter(lambda reason: "potentially bad keyword" not in reason, reasons))
return reasons
示例2: check_if_spam
# 需要导入模块: from findspam import FindSpam [as 别名]
# 或者: from findspam.FindSpam import test_post [as 别名]
def check_if_spam(post):
# if not post.body:
# body = ""
# test, why = FindSpam.test_post(title, body, user_name, post_site,
# is_answer, body_is_summary, owner_rep, post_score)
test, why = FindSpam.test_post(post)
if datahandling.is_blacklisted_user(parsing.get_user_from_url(post.user_url)):
test.append("blacklisted user")
blacklisted_user_data = datahandling.get_blacklisted_user_data(parsing.get_user_from_url(post.user_url))
if len(blacklisted_user_data) > 1:
if blacklisted_user_data[1] == "metasmoke":
blacklisted_by = "the metasmoke API"
else:
blacklisted_by = "http:" + blacklisted_user_data[1]
blacklisted_post_url = blacklisted_user_data[2]
if blacklisted_post_url:
rel_url = blacklisted_post_url.replace("http:", "", 1)
why += u"\nBlacklisted user - blacklisted for {} (" \
u"https://m.erwaysoftware.com/posts/by-url?url={}) by {}".format(blacklisted_post_url, rel_url,
blacklisted_by)
else:
why += u"\n" + u"Blacklisted user - blacklisted by {}".format(blacklisted_by)
if 0 < len(test):
if datahandling.has_already_been_posted(post.post_site, post.post_id, post.title) \
or datahandling.is_false_positive((post.post_id, post.post_site)) \
or should_whitelist_prevent_alert(post.user_url, test) \
or datahandling.is_ignored_post((post.post_id, post.post_site)) \
or datahandling.is_auto_ignored_post((post.post_id, post.post_site)):
return False, None, "" # Don't repost. Reddit will hate you.
return True, test, why
return False, None, ""
示例3: test_regexes
# 需要导入模块: from findspam import FindSpam [as 别名]
# 或者: from findspam.FindSpam import test_post [as 别名]
def test_regexes(title, body, username, site, body_is_summary, match):
# If we want to test answers separately, this should be changed
is_answer = False
result = FindSpam.test_post(title, body, username, site, is_answer, body_is_summary, 1, 0)[0]
print title
print result
isspam = False
if len(result) > 0:
isspam = True
assert match == isspam
示例4: test_findspam
# 需要导入模块: from findspam import FindSpam [as 别名]
# 或者: from findspam.FindSpam import test_post [as 别名]
def test_findspam(title, body, username, site, body_is_summary, is_answer, expected_spam):
post = Post(api_response={'title': title, 'body': body,
'owner': {'display_name': username, 'reputation': 1, 'link': ''},
'site': site, 'question_id': '1', 'IsAnswer': is_answer,
'BodyIsSummary': body_is_summary, 'score': 0})
result = FindSpam.test_post(post)[0]
log('info', title)
log('info', "Result:", result)
scan_spam = (len(result) > 0)
if scan_spam != expected_spam:
print("Expected {1} on {0}".format(body, expected_spam))
assert scan_spam == expected_spam
示例5: check_if_spam
# 需要导入模块: from findspam import FindSpam [as 别名]
# 或者: from findspam.FindSpam import test_post [as 别名]
def check_if_spam(title, body, user_name, user_url, post_site, post_id, is_answer, body_is_summary):
if not body:
body = ""
test = FindSpam.test_post(title, body, user_name, post_site, is_answer, body_is_summary)
if is_blacklisted_user(get_user_from_url(user_url)):
test.append("Blacklisted user")
if 0 < len(test):
if has_already_been_posted(post_site, post_id, title) or is_false_positive((post_id, post_site)) \
or should_whitelist_prevent_alert(user_url, test) \
or is_ignored_post((post_id, post_site)) \
or is_auto_ignored_post((post_id, post_site)):
return False, None # Don't repost. Reddit will hate you.
return True, test
return False, None
示例6: test_regexes
# 需要导入模块: from findspam import FindSpam [as 别名]
# 或者: from findspam.FindSpam import test_post [as 别名]
def test_regexes(title, body, username, site, body_is_summary, is_answer, match):
# If we want to test answers separately, this should be changed
# is_answer = False
post = Post(api_response={'title': title, 'body': body,
'owner': {'display_name': username, 'reputation': 1, 'link': ''},
'site': site, 'question_id': '1', 'IsAnswer': is_answer,
'BodyIsSummary': body_is_summary, 'score': 0})
result = FindSpam.test_post(post)[0]
log('info', title)
log('info', "Result:", result)
isspam = False
if len(result) > 0:
isspam = True
assert match == isspam
示例7: test
# 需要导入模块: from findspam import FindSpam [as 别名]
# 或者: from findspam.FindSpam import test_post [as 别名]
def test(content, alias_used="test"):
"""
Test an answer to determine if it'd be automatically reported
:param content:
:return: A string
"""
result = "> "
if alias_used == "test-q":
kind = " question."
fakepost = Post(api_response={'title': 'Valid title', 'body': content,
'owner': {'display_name': "Valid username", 'reputation': 1, 'link': ''},
'site': "", 'IsAnswer': False, 'score': 0})
elif alias_used == "test-a":
kind = "n answer."
fakepost = Post(api_response={'title': 'Valid title', 'body': content,
'owner': {'display_name': "Valid username", 'reputation': 1, 'link': ''},
'site': "", 'IsAnswer': True, 'score': 0})
elif alias_used == "test-u":
kind = " username."
fakepost = Post(api_response={'title': 'Valid title', 'body': "Valid question body",
'owner': {'display_name': content, 'reputation': 1, 'link': ''},
'site': "", 'IsAnswer': False, 'score': 0})
elif alias_used == "test-t":
kind = " title."
fakepost = Post(api_response={'title': content, 'body': "Valid question body",
'owner': {'display_name': "Valid username", 'reputation': 1, 'link': ''},
'site': "", 'IsAnswer': False, 'score': 0})
else:
kind = " post, title or username."
fakepost = Post(api_response={'title': content, 'body': content,
'owner': {'display_name': content, 'reputation': 1, 'link': ''},
'site': "", 'IsAnswer': False, 'score': 0})
reasons, why_response = FindSpam.test_post(fakepost)
if len(reasons) == 0:
result += "Would not be caught as a{}".format(kind)
else:
result += ", ".join(reasons).capitalize()
if why_response is not None and len(why_response) > 0:
result += "\n----------\n"
result += why_response
return result
示例8: check_if_spam
# 需要导入模块: from findspam import FindSpam [as 别名]
# 或者: from findspam.FindSpam import test_post [as 别名]
def check_if_spam(title, body, user_name, user_url, post_site, post_id, is_answer, body_is_summary, owner_rep):
if not body:
body = ""
test, why = FindSpam.test_post(title, body, user_name, post_site, is_answer, body_is_summary, owner_rep)
if is_blacklisted_user(get_user_from_url(user_url)):
test.append("Blacklisted user")
blacklisted_user_data = get_blacklisted_user_data(get_user_from_url(user_url))
if len(blacklisted_user_data) > 1:
message_url = 'http:' + blacklisted_user_data[1]
blacklisted_post_url = blacklisted_user_data[2]
if blacklisted_post_url:
why += u"Blacklisted user - blacklisted for {} by {}\n".format(blacklisted_post_url, message_url)
else:
why += u"Blacklisted user - blacklisted by {}\n".format(message_url)
if 0 < len(test):
if has_already_been_posted(post_site, post_id, title) or is_false_positive((post_id, post_site)) \
or should_whitelist_prevent_alert(user_url, test) \
or is_ignored_post((post_id, post_site)) \
or is_auto_ignored_post((post_id, post_site)):
return False, None, "" # Don't repost. Reddit will hate you.
return True, test, why
return False, None, ""
示例9: command_test_username
# 需要导入模块: from findspam import FindSpam [as 别名]
# 或者: from findspam.FindSpam import test_post [as 别名]
def command_test_username(content, content_lower, *args, **kwargs):
"""
Test a username to determine if it'd be automatically reported
:param content_lower:
:param content:
:param kwargs: No additional arguments expected
:return: A string
"""
string_to_test = content[10:]
test_as_answer = False
if len(string_to_test) == 0:
return Response(command_status=True, message="Nothing to test")
result = "> "
reasons, why = FindSpam.test_post("Valid title", "Valid post body", string_to_test, "", test_as_answer, False, 1, 0)
if len(reasons) == 0:
result += "Would not be caught as a username."
return Response(command_status=True, message=result)
result += ", ".join(reasons).capitalize()
if why is not None and len(why) > 0:
result += "\n----------\n"
result += why
return Response(command_status=True, message=result)
示例10: handle_commands
# 需要导入模块: from findspam import FindSpam [as 别名]
# 或者: from findspam.FindSpam import test_post [as 别名]
#.........这里部分代码省略.........
if is_privileged(ev_room, ev_user_id, wrap2):
post_message_in_room(ev_room, "Goodbye, cruel world")
os._exit(5)
if content_lower.startswith("!!/stappit"):
if is_privileged(ev_room, ev_user_id, wrap2):
post_message_in_room(ev_room, "Goodbye, cruel world")
os._exit(6)
if content_lower.startswith("!!/master"):
if is_privileged(ev_room, ev_user_id, wrap2):
os._exit(8)
if content_lower.startswith("!!/clearbl"):
if is_privileged(ev_room, ev_user_id, wrap2):
if os.path.isfile("blacklistedUsers.txt"):
os.remove("blacklistedUsers.txt")
GlobalVars.blacklisted_users = []
return "Kaboom, blacklisted users cleared."
else:
return "There are no blacklisted users at the moment."
if content_lower.startswith("!!/block"):
if is_privileged(ev_room, ev_user_id, wrap2):
timeToBlock = content_lower[9:].strip()
timeToBlock = int(timeToBlock) if timeToBlock else 0
if 0 < timeToBlock < 14400:
GlobalVars.blockedTime = time.time() + timeToBlock
else:
GlobalVars.blockedTime = time.time() + 900
return "blocked"
if content_lower.startswith("!!/unblock"):
if is_privileged(ev_room, ev_user_id, wrap2):
GlobalVars.blockedTime = time.time()
return "unblocked"
if content_lower.startswith("!!/errorlogs"):
if is_privileged(ev_room, ev_user_id, wrap2):
count = -1
if len(message_parts) != 2:
return "The !!/errorlogs command requires 1 argument."
try:
count = int(message_parts[1])
except ValueError:
pass
if count == -1:
return "Invalid argument."
logs_part = fetch_lines_from_error_log(count)
post_message_in_room(ev_room, logs_part, False)
if content_lower.startswith("!!/pull"):
if is_privileged(ev_room, ev_user_id, wrap2):
r = requests.get('https://api.github.com/repos/Charcoal-SE/SmokeDetector/git/refs/heads/master')
latest_sha = r.json()["object"]["sha"]
r = requests.get('https://api.github.com/repos/Charcoal-SE/SmokeDetector/commits/' + latest_sha + '/statuses')
states = []
for status in r.json():
state = status["state"]
states.append(state)
if "success" in states:
os._exit(3)
elif "error" in states or "failure" in states:
return "CI build failed! :( Please check your commit."
elif "pending" in states or not states:
return "CI build is still pending, wait until the build has finished and then pull again."
if content_lower.startswith("!!/help"):
return "I'm [SmokeDetector](https://github.com/Charcoal-SE/SmokeDetector), a bot that detects spam and low-quality posts on the network and posts alerts to chat. [A command list is available here](https://github.com/Charcoal-SE/SmokeDetector/wiki/Commands)."
if content_lower.startswith("!!/apiquota"):
return GlobalVars.apiquota
if content_lower.startswith("!!/whoami"):
if (ev_room in GlobalVars.smokeDetector_user_id):
return "My id for this room is {}".format(GlobalVars.smokeDetector_user_id[ev_room])
else:
return "I don't know my user ID for this room. (Something is wrong, and it's apnorton's fault.)"
if content_lower.startswith("!!/location"):
return GlobalVars.location
if content_lower.startswith("!!/queuestatus"):
post_message_in_room(ev_room, GlobalVars.bodyfetcher.print_queue(), False)
if content_lower.startswith("!!/blame") and (ev_room == GlobalVars.meta_tavern_room_id or ev_room == GlobalVars.socvr_room_id):
GlobalVars.tavern_users_chatting = list(set(GlobalVars.tavern_users_chatting)) # Make unique
user_to_blame = random.choice(GlobalVars.tavern_users_chatting)
return "It's " + user_to_blame + "'s fault."
if "smokedetector" in content_lower and "fault" in content_lower and ("xkcdbot" in ev_user_name.lower() or "bjb568" in ev_user_name.lower()):
return "Liar"
if content_lower.startswith("!!/coffee"):
return "*brews coffee for @" + ev_user_name.replace(" ", "") + "*"
if content_lower.startswith("!!/tea"):
return "*brews a cup of " + random.choice(['earl grey', 'green', 'chamomile', 'lemon', 'darjeeling', 'mint']) + " tea for @" + ev_user_name.replace(" ", "") + "*"
if content_lower.startswith("!!/brownie"):
return "Brown!"
if content_lower.startswith("!!/test"):
string_to_test = content[8:]
if len(string_to_test) == 0:
return "Nothing to test"
result = "> "
reasons, why = FindSpam.test_post(string_to_test, string_to_test, string_to_test, "", False, False)
if len(reasons) == 0:
result += "Would not be caught for title, body and username."
return result
result += ", ".join(reasons).capitalize()
if why is not None and len(why) > 0:
result += "\n----------\n"
result += why
return result
return None
示例11: handle_commands
# 需要导入模块: from findspam import FindSpam [as 别名]
# 或者: from findspam.FindSpam import test_post [as 别名]
#.........这里部分代码省略.........
if content_lower.startswith("!!/queuestatus"):
post_message_in_room(ev_room, GlobalVars.bodyfetcher.print_queue(), False)
if content_lower.startswith("!!/blame"):
GlobalVars.users_chatting[ev_room] = list(set(GlobalVars.users_chatting[ev_room])) # Make unique
user_to_blame = random.choice(GlobalVars.users_chatting[ev_room])
return u"It's [{}]({})'s fault.".format(user_to_blame[0], user_to_blame[1])
if "smokedetector" in content_lower and "fault" in content_lower and ("xkcdbot" in ev_user_name.lower() or "bjb568" in ev_user_name.lower()):
return "Liar"
if content_lower.startswith("!!/coffee"):
return "*brews coffee for @" + ev_user_name.replace(" ", "") + "*"
if content_lower.startswith("!!/tea"):
return "*brews a cup of " + random.choice(['earl grey', 'green', 'chamomile', 'lemon', 'darjeeling', 'mint']) + " tea for @" + ev_user_name.replace(" ", "") + "*"
if content_lower.startswith("!!/brownie"):
return "Brown!"
if content_lower.startswith("!!/hats"):
wb_end = datetime(2016, 1, 4, 0, 0, 0)
now = datetime.utcnow()
if wb_end > now:
diff = wb_end - now
hours, remainder = divmod(diff.seconds, 3600)
minutes, seconds = divmod(remainder, 60)
daystr = "days" if diff.days != 1 else "day"
hourstr = "hours" if hours != 1 else "hour"
minutestr = "minutes" if minutes != 1 else "minute"
secondstr = "seconds" if seconds != 1 else "second"
return "HURRY UP AND EARN MORE HATS! Winterbash will be over in {} {}, {} {}, {} {}, and {} {}. :(".format(diff.days, daystr, hours, hourstr, minutes, minutestr, seconds, secondstr)
else:
return "Winterbash is over. :("
if content_lower.startswith("!!/test"):
string_to_test = content[8:]
if len(string_to_test) == 0:
return "Nothing to test"
result = "> "
reasons, why = FindSpam.test_post(string_to_test, string_to_test, string_to_test, "", False, False, 1, 0)
if len(reasons) == 0:
result += "Would not be caught for title, body, and username."
return result
result += ", ".join(reasons).capitalize()
if why is not None and len(why) > 0:
result += "\n----------\n"
result += why
return result
if content_lower.startswith("!!/amiprivileged"):
if is_privileged(ev_room, ev_user_id, wrap2):
return "Yes, you are a privileged user."
else:
return "No, you are not a privileged user."
if content_lower.startswith("!!/notify"):
if len(message_parts) != 3:
return False, "2 arguments expected"
user_id = int(ev_user_id)
chat_site = wrap2.host
room_id = message_parts[1]
if not room_id.isdigit():
return False, "Room ID is invalid."
else:
room_id = int(room_id)
quiet_action = ("-" in message_parts[2])
se_site = message_parts[2].replace('-', '')
r, full_site = add_to_notification_list(user_id, chat_site, room_id, se_site)
if r == 0:
if not quiet_action:
return "You'll now get pings from me if I report a post on `%s`, in room `%s` on `chat.%s`" % (full_site, room_id, chat_site)
else:
return None
elif r == -1: