Help

Re: Script that automatically opens links, searches for element inside each link, performs action

4204 2
cancel
Showing results for 
Search instead for 
Did you mean: 
IsaiahRios
4 - Data Explorer
4 - Data Explorer

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.

4 Replies 4
IsaiahRios
4 - Data Explorer
4 - Data Explorer

Here is a screenshot of the error it gave me

Screenshot 2023-07-11 12.00.27 PM - Display 2.png

Hi Isaia

This looks like Python code, which doesn't run in the scripting block. You'll need to convert this to javascript.

 

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

Screenshot 2023-07-11 3.23.16 PM - Display 2.png

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.