Spaces:
Sleeping
Sleeping
File size: 1,991 Bytes
992f04e 639d80a 00bfe96 992f04e 639d80a 992f04e 639d80a cdf8cfc 992f04e 639d80a 992f04e 639d80a 992f04e 639d80a 00bfe96 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
from deliverable2 import URLValidator
import os
import json
from dotenv import load_dotenv
# Load environment variables from a .env file (if present)
load_dotenv()
# Retrieve API key from environment variables
SERPAPI_API_KEY = os.getenv("SERPAPI_API_KEY")
# Ensure API key is provided before initializing
if not SERPAPI_API_KEY:
raise ValueError("SERPAPI_API_KEY is not set. Please configure your environment variables.")
# Initialize the validator correctly
validator = URLValidator(serpapi_key=SERPAPI_API_KEY)
## List of queries
queries = [
"How blockchain works",
"Climate change effects",
"COVID-19 vaccine effectiveness",
"Latest AI advancements",
"Stock market trends",
"Healthy diet tips",
"Space exploration missions",
"Electric vehicle benefits",
"History of the internet",
"Nutritional benefits of a vegan diet",
"Mental health awareness"
]
# Corresponding URLs
urls = [
"https://www.ibm.com/topics/what-is-blockchain",
"https://www.nationalgeographic.com/environment/article/climate-change-overview",
"https://www.cdc.gov/coronavirus/2019-ncov/vaccines/effectiveness.html",
"https://www.technologyreview.com/topic/artificial-intelligence",
"https://www.bloomberg.com/markets",
"https://www.healthline.com/nutrition/healthy-eating-tips",
"https://www.nasa.gov/missions",
"https://www.tesla.com/benefits",
"https://www.history.com/topics/inventions/history-of-the-internet",
"https://www.hsph.harvard.edu/nutritionsource/healthy-weight/diet-reviews/vegan-diet/",
"https://www.who.int/news-room/fact-sheets/detail/mental-health-strengthening-our-response"
]
# Process queries and URLs separately but use them together
results = []
for query, url in zip(queries, urls):
result = validator.rate_url_validity(query, url)
results.append({
"Query": query,
"URL": url,
"Result": result
})
# Print formatted output
print(json.dumps(results, indent=2))
|