-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
13 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,37 @@ | ||
import asyncio | ||
|
||
from fastapi import APIRouter | ||
from fastapi.requests import Request | ||
|
||
from app.config import API_KEY_NAME | ||
from app.services.scrapers.common import InfoExtractService | ||
from fastapi import Security | ||
from app.auth import verify_api_key | ||
from app.utils.logger import logger | ||
from app.utils.parse import get_url_metadata | ||
|
||
router = APIRouter(prefix="/scraper") | ||
|
||
|
||
@router.post("/getItem", dependencies=[Security(verify_api_key)]) | ||
async def get_item_route(request: Request): | ||
logger.debug("A scraper getItem request received") | ||
query_params = dict(request.query_params) | ||
url = query_params.pop("url") | ||
ban_list = query_params.pop("ban_list", None) | ||
logger.debug(f"get_item_route: url: {url}, query_params: {query_params}") | ||
if API_KEY_NAME in query_params: | ||
query_params.pop(API_KEY_NAME) | ||
url_metadata = await get_url_metadata(url, ban_list) | ||
|
||
item = InfoExtractService(url_metadata, **query_params) | ||
result = await item.get_item() | ||
logger.debug(f"getItem result: {result}") | ||
return result | ||
|
||
|
||
@router.post("/getUrlMetadata", dependencies=[Security(verify_api_key)]) | ||
async def get_url_metadata_route(request: Request): | ||
url = request.query_params.get("url") | ||
ban_list = request.query_params.get("ban_list") | ||
|
||
url_metadata = await get_url_metadata(url, ban_list) | ||
return url_metadata.to_dict() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters