DebasishDhal99 commited on
Commit
0b5acb5
·
1 Parent(s): a6ef7f1

Add docstrings for all functional routes

Browse files
Files changed (1) hide show
  1. main.py +41 -1
main.py CHANGED
@@ -46,6 +46,12 @@ def health_check():
46
 
47
  @app.get("/wiki/search/summary/{summary_page_name}")
48
  async def get_wiki_summary(summary_page_name: str, background_tasks: BackgroundTasks):
 
 
 
 
 
 
49
  if summary_page_name in summary_cache:
50
  # print("Cache hit for summary:", page_name) #Working
51
  return JSONResponse(content=summary_cache[summary_page_name], status_code=200)
@@ -83,7 +89,13 @@ async def get_wiki_summary(summary_page_name: str, background_tasks: BackgroundT
83
  )
84
 
85
  @app.get("/wiki/search/full/{full_page}")
86
- def search_wiki_full_page(full_page: str, background_tasks: BackgroundTasks):
 
 
 
 
 
 
87
  if full_page in full_page_cache:
88
  # print("Cache hit for full_page:", full_page) #Working
89
  return JSONResponse(content=full_page_cache[full_page], status_code=200)
@@ -123,6 +135,10 @@ def search_wiki_full_page(full_page: str, background_tasks: BackgroundTasks):
123
 
124
  @app.post("/geodistance")
125
  def get_geodistance(payload: Geodistance):
 
 
 
 
126
  lat1, lon1 = payload.lat1, payload.lon1
127
  lat2, lon2 = payload.lat2, payload.lon2
128
  unit = payload.unit
@@ -159,6 +175,30 @@ def get_geodistance(payload: Geodistance):
159
 
160
  @app.post("/wiki/nearby")
161
  async def get_nearby_wiki_pages(payload: NearbyWikiPage):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
162
  lat, lon = payload.lat, payload.lon
163
  radius = payload.radius
164
  limit = payload.limit
 
46
 
47
  @app.get("/wiki/search/summary/{summary_page_name}")
48
  async def get_wiki_summary(summary_page_name: str, background_tasks: BackgroundTasks):
49
+ """
50
+ This function fetches the summary of a Wikipedia page along with its geographical coordinates.
51
+ It also caches the result in ephemeral in-memory cache in the background.
52
+ Input: summary_page_name: str - Name of the Wikipedia page to fetch summary for.
53
+ Output: {"title": "Page Title", "content": "Summary content here", "latitude": float, "longitude": float9}
54
+ """
55
  if summary_page_name in summary_cache:
56
  # print("Cache hit for summary:", page_name) #Working
57
  return JSONResponse(content=summary_cache[summary_page_name], status_code=200)
 
89
  )
90
 
91
  @app.get("/wiki/search/full/{full_page}")
92
+ async def search_wiki_full_page(full_page: str, background_tasks: BackgroundTasks):
93
+ """
94
+ This function fetches the full content of a Wikipedia page along with its geographical coordinates.
95
+ It also caches the result in ephemeral in-memory cache in the background.
96
+ Input: full_page: str - Name of the Wikipedia page to fetch full content for.
97
+ Output: {"title": "Page Title", "content": "Full content here", "latitude": float, "longitude": float}
98
+ """
99
  if full_page in full_page_cache:
100
  # print("Cache hit for full_page:", full_page) #Working
101
  return JSONResponse(content=full_page_cache[full_page], status_code=200)
 
135
 
136
  @app.post("/geodistance")
137
  def get_geodistance(payload: Geodistance):
138
+ """
139
+ Input: "lat1", "lon1", "lat2", "lon2", "unit (km/mi)"
140
+ Output: {"distance": float, "unit": str, "lat1": float, "lon1": float, "lat2": float, "lon2": float}
141
+ """
142
  lat1, lon1 = payload.lat1, payload.lon1
143
  lat2, lon2 = payload.lat2, payload.lon2
144
  unit = payload.unit
 
175
 
176
  @app.post("/wiki/nearby")
177
  async def get_nearby_wiki_pages(payload: NearbyWikiPage):
178
+ """
179
+ Returns a list of wikipedia pages whose geographical coordinates are within a specified radius from a given location.
180
+ Input:
181
+ - lat: Latitude of the reference point
182
+ - lon: Longitude of the reference point
183
+ - radius: Radius in meters within which to search for pages
184
+ - limit: Maximum number of pages to return
185
+
186
+ Output:
187
+ {
188
+ "pages": [
189
+ {
190
+ "pageid": 123456,
191
+ "title": "Page Title",
192
+ "lat": 54.163337,
193
+ "lon": 37.561109,
194
+ "dist": 123.45 # Dist. in meters from the reference point
195
+ ...
196
+ },
197
+ ...
198
+ ],
199
+ "count": 10 #Total no. of such pages
200
+ }
201
+ """
202
  lat, lon = payload.lat, payload.lon
203
  radius = payload.radius
204
  limit = payload.limit