本文整理汇总了Python中findspam.FindSpam类的典型用法代码示例。如果您正苦于以下问题:Python FindSpam类的具体用法?Python FindSpam怎么用?Python FindSpam使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了FindSpam类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: check_blacklist
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
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
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: handlespam
def handlespam(data):
try:
d=json.loads(json.loads(data)["data"])
reason=",".join(FindSpam.testpost(d["titleEncodedFancy"],d["siteBaseHostAddress"]))
s="[ [SmokeDetector](https://github.com/Charcoal-SE/SmokeDetector) ] %s: [%s](%s) on `%s`" % (reason,d["titleEncodedFancy"],d["url"],d["siteBaseHostAddress"])
print parser.unescape(s).encode('ascii',errors='replace')
wrap.sendMessage("11540",s)
wrapm.sendMessage("89",s)
except UnboundLocalError:
print "NOP"
示例5: test_findspam
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
示例6: handlespam
def handlespam(data):
try:
d=json.loads(json.loads(data)["data"])
title = d["titleEncodedFancy"]
reason=",".join(FindSpam.testpost(title,d["siteBaseHostAddress"]))
escapedTitle = re.sub(r"([_*\\`\[\]])", r"\\\1", title)
s="[ [SmokeDetector](https://github.com/Charcoal-SE/SmokeDetector) ] %s: [%s](%s) on `%s`" % (reason,escapedTitle,d["url"],d["siteBaseHostAddress"])
print parser.unescape(s).encode('ascii',errors='replace')
room.send_message(s)
roomm.send_message(s)
except UnboundLocalError:
print "NOP"
示例7: test_regexes
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
示例8: check_if_spam
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
示例9: checkifspam
def checkifspam(data):
d=json.loads(json.loads(data)["data"])
s= d["titleEncodedFancy"]
print time.strftime("%Y-%m-%d %H:%M:%S"),parser.unescape(s).encode("ascii",errors="replace")
site = d["siteBaseHostAddress"]
site=site.encode("ascii",errors="replace")
sys.stdout.flush()
test=FindSpam.testpost(s,site)
if (0<len(test)):
post_id = d["id"]
if(has_already_been_posted(site, post_id, s)):
return False # Don't repost. Reddit will hate you.
append_to_latest_questions(site, post_id, s)
return True
return False
示例10: checkifspam
def checkifspam(data):
global lasthost,lastid
d=json.loads(json.loads(data)["data"])
s= d["titleEncodedFancy"]
print time.strftime("%Y-%m-%d %H:%M:%S"),parser.unescape(s).encode("ascii",errors="replace")
site = d["siteBaseHostAddress"]
site=site.encode("ascii",errors="replace")
sys.stdout.flush()
test=FindSpam.testpost(s,site)
if (0<len(test)):
if(lastid==d["id"] and lasthost == d["siteBaseHostAddress"]):
return False # Don't repost. Reddit will hate you.
lastid=d["id"]
lasthost = d["siteBaseHostAddress"]
return True
return False
示例11: test
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
示例12: handlespam
def handlespam(data):
try:
d=json.loads(json.loads(data)["data"])
title = d["titleEncodedFancy"]
poster = d["ownerDisplayName"]
reason=", ".join(FindSpam.testpost(title,poster,d["siteBaseHostAddress"]))
titleToPost = GlobalVars.parser.unescape(re.sub(r"([_*\\`\[\]])", r"\\\1", title)).strip()
s="[ [SmokeDetector](https://github.com/Charcoal-SE/SmokeDetector) ] %s: [%s](%s) by [%s](%s) on `%s`" % (reason,titleToPost,d["url"],poster,d["ownerUrl"],d["siteBaseHostAddress"])
print GlobalVars.parser.unescape(s).encode('ascii',errors='replace')
if time.time() >= GlobalVars.blockedTime:
GlobalVars.charcoal_hq.send_message(s)
GlobalVars.tavern_on_the_meta.send_message(s)
for specialroom in GlobalVars.specialrooms:
sites = specialroom["sites"]
if d["siteBaseHostAddress"] in sites and reason not in specialroom["unwantedReasons"]:
specialroom["room"].send_message(s)
except:
print "NOP"
示例13: check_if_spam
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, ""
示例14: command_test_username
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)
示例15: checkifspam
def checkifspam(data):
d=json.loads(json.loads(data)["data"])
try:
_ = d["ownerUrl"]
except:
return False # owner's account doesn't exist anymore, no need to post it in chat: http://chat.stackexchange.com/transcript/message/18380776#18380776
s= d["titleEncodedFancy"]
poster = d["ownerDisplayName"]
print time.strftime("%Y-%m-%d %H:%M:%S"),GlobalVars.parser.unescape(s).encode("ascii",errors="replace")
quality_score = bayesian_score(s)
print quality_score
if(quality_score < 0.3 and d["siteBaseHostAddress"] == "stackoverflow.com"):
print GlobalVars.bayesian_testroom.send_message("[ SmokeDetector | BayesianBeta ] Quality score " + str(quality_score*100) + ": [" + s + "](" + d["url"] + ")")
site = d["siteBaseHostAddress"]
site=site.encode("ascii",errors="replace")
sys.stdout.flush()
test=FindSpam.testpost(s,poster,site)
if(is_blacklisted_user(get_user_from_url(d["ownerUrl"]))):
if(len(test) == 0):
test = "Blacklisted user"
else:
test += ", Blacklisted user"
if (0<len(test)):
post_id = d["id"]
if(has_already_been_posted(site, post_id, s) or is_false_positive(post_id, site) or is_whitelisted_user(get_user_from_url(d["ownerUrl"]))):
return False # Don't repost. Reddit will hate you.
append_to_latest_questions(site, post_id, s)
try:
owner = d["ownerUrl"]
users_file = open("users.txt", "a")
users_file.write(site + " " + owner + " " + d["titleEncodedFancy"] + " " + d["url"] + "\n")
users_file.close()
except Exception as e:
print e
return True
return False