Python Rapid API - Elementary School Friendly
Python Rapid API that filters out words that are not safe for elementary school kids
This is the Python Rapid API example using the PURGOMALUM API to filter some words with * that are not safe for elementary school kids
"""
Requests is a HTTP library for the Python programming language.
"""
import requests
# url for JSON Rapid API service
url = "https://www.purgomalum.com/service/json"
# add some banned words to filter from sentences
banned_words = "bloody,bugger,cow,crap,damn,god,goddam,jesus,hell,dead"
response = None
# builds the HTTP GET request with parameters and prints response
def get_response(sentence): # sentence to be filtered
parameters = { #http GET parameters
'add': banned_words,
'text': sentence
}
# Request filtered sentence
response = requests.request("GET", url, params=parameters)
print("Original sentence: " + sentence)
print("Elementary school friendly sentence: ")
print(response.json().get('result'))
print("\n")
# array of orginal sentences
sentence_array = [
"This is bloody hell !!!",
"Holy cow is not a right phrase for elementary schools kids",
"Crap - is not a right word that elementary school kids should use",
"God damn it -- where is hte ice-cream?",
"Phrase Jesus christ should not used in vain",
"Highway to Hell was the song from AC/DC",
"Dawn of the dead is an scary movie"
]
# Filter each sentence in the array
for row in sentence_array:
get_response(row)