檢測(cè)你書寫的郵件有沒有出現(xiàn)冒犯語言妄讯,實(shí)用簡(jiǎn)單氢伟。
import urllib.request
def read_text():
quotes = open("F:\movie_quotes.txt")
contents_of_file = quotes.read()
#print(contents_of_file)
quotes.close()
check_profanity(contents_of_file)
def check_profanity(text_to_check):
connection = urllib.request.urlopen("http://wdyl.com/profanity?q="+text_to_check)
output = connection.read()
#print(output)
connection.close()
if "true" in output:
print("Profanity Alert!!")
elif "false" in output:
print("This document has no curse words!")
else:
print("Could not scan the document properly.")
read_text()