Deliverable2 / app.py
Inara132000's picture
Update app.py
cdf8cfc verified
raw
history blame
1.99 kB
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))