Selenium based fetch of different sources
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
from fastapi import FastAPI
|
||||
from pydantic import BaseModel
|
||||
from missing_kids import MissingKidsFetcher
|
||||
from search import SearchFetcher
|
||||
from logger import get_logger
|
||||
logger = get_logger()
|
||||
|
||||
@@ -12,17 +13,41 @@ def get_missing_kids(pages: int = -1):
|
||||
logger.info("Get missing kids, #pages={}".format(pages))
|
||||
res = {"list_urls": MissingKidsFetcher().get_missing_kids_urls(first_n_pages=pages)}
|
||||
except Exception as e:
|
||||
logger.warning("Exception: {}".format(str(e)), exc_info=True)
|
||||
res = {}
|
||||
return res
|
||||
|
||||
class Body(BaseModel):
|
||||
class BodyVerifyMissingKid(BaseModel):
|
||||
url: str
|
||||
|
||||
@app.post("/verify_missing_kid/")
|
||||
def get_missing_kids(data: Body):
|
||||
def get_missing_kids(data: BodyVerifyMissingKid):
|
||||
try:
|
||||
logger.info("Verify missing kid, URL={}".format(data.url))
|
||||
res = MissingKidsFetcher().verify_missing_kid_url(data.url)
|
||||
except Exception as e:
|
||||
logger.warning("Exception: {}".format(str(e)), exc_info=True)
|
||||
res = {}
|
||||
return res
|
||||
return res
|
||||
|
||||
class BodyFetchSearch(BaseModel):
|
||||
search: str
|
||||
|
||||
@app.post("/fetch_search/")
|
||||
def fetch_search(data: BodyFetchSearch):
|
||||
try:
|
||||
# Initialize
|
||||
search_fetcher, results = SearchFetcher(), {}
|
||||
# Iterate
|
||||
for source in search_fetcher.get_available_sources():
|
||||
logger.info("Fetch based search source={} search={}".format(source, data.search))
|
||||
# Fetch
|
||||
results[source] = SearchFetcher().search(source, data.search)
|
||||
# Empty?
|
||||
if (len(results[source]) == 0):
|
||||
results.pop(source)
|
||||
|
||||
except Exception as e:
|
||||
logger.warning("Exception: {}".format(str(e)), exc_info=True)
|
||||
results = {}
|
||||
return results
|
||||
|
||||
Reference in New Issue
Block a user