wikiextractor / main.py
ShoaibSSM's picture
Create main.py
31dc2ac verified
raw
history blame contribute delete
446 Bytes
from fastapi import FastAPI
import wikipedia
app = FastAPI()
@app.get("/")
async def get_wikipedia_url(topic: str):
try:
# Search for the exact page
page = wikipedia.page(topic, auto_suggest=False, redirect=True)
url = page.url
return {"topic": topic, "url": url}
except Exception:
# Default fallback if not found
return {"topic": topic, "url": "https://en.wikipedia.org/wiki/Main_Page"}