thomas commited on
Commit ·
4b17d8c
1
Parent(s): 3f2d2d3
feature(#32): fixed selection_item function to get only its link from the list.
Browse files- src/common/utils.py +11 -0
- src/router/browser_router.py +2 -1
src/common/utils.py
CHANGED
|
@@ -1,5 +1,6 @@
|
|
| 1 |
import json
|
| 2 |
import os
|
|
|
|
| 3 |
|
| 4 |
from firebase_admin import credentials
|
| 5 |
|
|
@@ -87,3 +88,13 @@ def parseJsonFromCompletion(data: str) -> json:
|
|
| 87 |
# fmt: on
|
| 88 |
result = json.loads(result.replace("':", '":'))
|
| 89 |
return result
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import json
|
| 2 |
import os
|
| 3 |
+
import re
|
| 4 |
|
| 5 |
from firebase_admin import credentials
|
| 6 |
|
|
|
|
| 88 |
# fmt: on
|
| 89 |
result = json.loads(result.replace("':", '":'))
|
| 90 |
return result
|
| 91 |
+
|
| 92 |
+
|
| 93 |
+
def parseUrlFromStr(text: str) -> str:
|
| 94 |
+
# Search for the link using regex
|
| 95 |
+
link = re.search(r"(https?://\S+)", text)
|
| 96 |
+
|
| 97 |
+
if link:
|
| 98 |
+
return link.group(0)
|
| 99 |
+
else:
|
| 100 |
+
return ""
|
src/router/browser_router.py
CHANGED
|
@@ -1,6 +1,7 @@
|
|
| 1 |
from fastapi import APIRouter, Request, Depends
|
| 2 |
|
| 3 |
from src.common.assembler import Assembler
|
|
|
|
| 4 |
from src.model.requests.request_model import BrowserItem
|
| 5 |
from src.service.browser_service import BrowserService
|
| 6 |
|
|
@@ -37,7 +38,7 @@ def construct_blueprint_browser_api() -> APIRouter:
|
|
| 37 |
except Exception as e:
|
| 38 |
return assembler.to_response(400, "Failed to get item in a browser", "")
|
| 39 |
return assembler.to_response(
|
| 40 |
-
200, "Getting an item in a browser successfully", item_link
|
| 41 |
)
|
| 42 |
|
| 43 |
return router
|
|
|
|
| 1 |
from fastapi import APIRouter, Request, Depends
|
| 2 |
|
| 3 |
from src.common.assembler import Assembler
|
| 4 |
+
from src.common.utils import parseUrlFromStr
|
| 5 |
from src.model.requests.request_model import BrowserItem
|
| 6 |
from src.service.browser_service import BrowserService
|
| 7 |
|
|
|
|
| 38 |
except Exception as e:
|
| 39 |
return assembler.to_response(400, "Failed to get item in a browser", "")
|
| 40 |
return assembler.to_response(
|
| 41 |
+
200, "Getting an item in a browser successfully", parseUrlFromStr(item_link)
|
| 42 |
)
|
| 43 |
|
| 44 |
return router
|