I have a function which returns a list of text. I am using an API from Mashape (Maui-Pro) which generates keywords from a given piece of text. Mashape requires that you use unirest for HTTP requests. I want to pass the list of text to the API and generate keywords for each piece of text but can't work out how to loop through the each piece of text in the list using unirest. Here's the code:
import unirest
from pprint import pprint
from get_articles import extract_text
def get_keywords():
text_list = extract_text()
response = unirest.post("https://maui-v1.p.mashape.com/api/keywords",
headers={"X-Mashape-Key": "UbvKOrgO0amshGoyNHDgGtxaO72vp1ck58Gjsn5BzPZADqHBtb", "Content-Type": "application/json", "Accept": "application/json"},
params=("{\"return_translations\":false," "\"return_uris\":false," "\"content\":\"A piece of text from which to return keywords.\"," "\"thesaurus\":\"English Wikipedia\"}"))
print(response.__dict__)
get_keywords()
I'd like to substitute the content text in params
with each piece of text in text_list
and return keywords for each. Any help much appreciated. Thanks!