Jul 11, 2023 08:56 AM
I want to create a script that will automatically open links inside of a specified field, search for an element inside of the links ex. another url, and perform an action based on the existence of the element or lack thereof. I want the script to be activated every time that field has another link added to it as I have an automation continuously adding more data to the table and I want the script to keep up. If anybody has any tips on how to create this script it would be greatly appreciated. I got a script from eden ai but I don't know how to code and don't really understand it. Here it is
import json
import requests
# Function to search for specific elements within the links in the Airtable database
def text_search(api_key, texts, query):
headers = {"Authorization": f"Bearer {api_key}"}
url = "https://api.edenai.run/v2/text/search"
payload = {"providers": "openai", "texts": texts, "query": query}
response = requests.post(url, json=payload, headers=headers)
result = json.loads(response.text)
return result['openai']['items']
# Function to extract important words and expressions from the links in the Airtable database
def keyword_extraction(api_key, text):
headers = {"Authorization": f"Bearer {api_key}"}
url = "https://api.edenai.run/v2/text/keyword_extraction"
payload = {"providers": "amazon,microsoft", "language": "en", "text": text}
response = requests.post(url, json=payload, headers=headers)
result = json.loads(response.text)
return result['amazon']['items']
# Example usage
api_key = "Your_API_Key"
# Search for specific elements within the links
texts = [
"In Roman mythology, Romulus and Remus are twin brothers whose story tells of the events that led to the founding of the city of Rome and the Roman Kingdom by Romulus.",
"In ancient Roman religion and myth, Mars was the god of war and also an agricultural guardian, a combination characteristic of early Rome.",
"Proto-Indo-European mythology is the body of myths and deities associated with the Proto-Indo-Europeans, the hypothetical speakers of the reconstructed Proto-Indo-European language",
"The Ashvamedha was a horse sacrifice ritual followed by the Śrauta tradition of Vedic religion.",
"Purusha is a complex concept whose meaning evolved in Vedic and Upanishadic times. Depending on source and historical timeline, it means the cosmic being or self, consciousness, and universal principle."
]
query = "Rome"
search_results = text_search(api_key, texts, query)
print(search_results)
# Extract important words and expressions from the links
text = "this is a test of Eden AI"
keyword_results = keyword_extraction(api_key, text)
print(keyword_results)
I added this to my script and tried filling whatever values I thought I could understand but it returned me an error so I don't really know what to do from here.
Jul 11, 2023 09:03 AM
Here is a screenshot of the error it gave me
Jul 11, 2023 11:55 AM
Hi Isaia
This looks like Python code, which doesn't run in the scripting block. You'll need to convert this to javascript.
Jul 11, 2023 12:25 PM
Yes I did some more research and learned that and changed the programming language to Javascript however i ran into another error that is also giving me a hard time
Jul 11, 2023 02:40 PM
Delete the lines up to and including line 4, you can't import libraries (const axios = require('axios')) into the scripting block.
If you post all the code (without any api keys showing) then it would be easier to see what's going on. Hopefully you should be able to do what you want without needing to import any libraries.