ShoaibSSM commited on
Commit
31dc2ac
·
verified ·
1 Parent(s): 00accd7

Create main.py

Browse files
Files changed (1) hide show
  1. main.py +15 -0
main.py ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastapi import FastAPI
2
+ import wikipedia
3
+
4
+ app = FastAPI()
5
+
6
+ @app.get("/")
7
+ async def get_wikipedia_url(topic: str):
8
+ try:
9
+ # Search for the exact page
10
+ page = wikipedia.page(topic, auto_suggest=False, redirect=True)
11
+ url = page.url
12
+ return {"topic": topic, "url": url}
13
+ except Exception:
14
+ # Default fallback if not found
15
+ return {"topic": topic, "url": "https://en.wikipedia.org/wiki/Main_Page"}