crawling check
parent
0d3543d84d
commit
26cd946e1b
|
|
@ -1,5 +1,5 @@
|
|||
import uuid6
|
||||
from fastapi import APIRouter, BackgroundTasks, Depends, status
|
||||
from fastapi import APIRouter, BackgroundTasks, Depends, status, HTTPException
|
||||
from common.deps import verify_api_key
|
||||
from common.db import fetchone, insert_instagram_row, insert_facebook_row, insert_naver_blog_row, insert_youtube_row, insert_gangnam_unni_row, insert_analysis_run
|
||||
from models.analysis import AnalysisCreate, AnalysisStartResponse, AnalysisStatusResponse
|
||||
|
|
@ -19,6 +19,8 @@ async def start_analysis(body: AnalysisCreate, background_tasks: BackgroundTasks
|
|||
"SELECT owner_user_id FROM hospital_baseinfo WHERE hospital_id = %s",
|
||||
(hospital_id,),
|
||||
)
|
||||
if not hospital:
|
||||
raise HTTPException(status_code=409, detail="Clinic not found")
|
||||
owner_user_id = hospital["owner_user_id"] if hospital else 0
|
||||
|
||||
ig_url = body.channels.instagram[0] if isinstance(body.channels.instagram, list) else body.channels.instagram
|
||||
|
|
@ -33,7 +35,7 @@ async def start_analysis(body: AnalysisCreate, background_tasks: BackgroundTasks
|
|||
if ig_id:
|
||||
background_tasks.add_task(collect_instagram, analysis_run_id, ig_id, ig_url)
|
||||
if fb_id:
|
||||
background_tasks.add_task(collect_facebook, analysis_run_id, fb_id, body.channels.facebook)
|
||||
background_tasks.add_task(collect_facebook, analysis_run_id, fb_id, f"https://www.facebook.com/{body.channels.facebook}")
|
||||
if nb_id:
|
||||
background_tasks.add_task(collect_naver_blog, analysis_run_id, nb_id, body.channels.naver_blog)
|
||||
if yt_id:
|
||||
|
|
|
|||
|
|
@ -2,5 +2,7 @@ import os
|
|||
from fastapi import Header, HTTPException
|
||||
|
||||
async def verify_api_key(x_api_key: str = Header(...)):
|
||||
print(x_api_key)
|
||||
print(os.getenv("API_KEY"))
|
||||
if x_api_key != os.getenv("API_KEY"):
|
||||
raise HTTPException(status_code=401, detail="Invalid API Key")
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
from fastapi import FastAPI
|
||||
from dotenv import load_dotenv
|
||||
from api import routers
|
||||
import os
|
||||
|
||||
load_dotenv()
|
||||
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ from integrations.firecrawl import FirecrawlClient
|
|||
|
||||
|
||||
async def collect_instagram(analysis_run_id: str, row_id: int, url: str) -> None:
|
||||
print("start a insta")
|
||||
await set_instagram_status(row_id, "processing")
|
||||
data = await ApifyClient(get_env("APIFY_API_TOKEN")).fetch_instagram_profile(normalize_handle("instagram", url))
|
||||
await save_instagram_raw_data(row_id, data)
|
||||
|
|
@ -21,6 +22,7 @@ async def collect_instagram(analysis_run_id: str, row_id: int, url: str) -> None
|
|||
|
||||
|
||||
async def collect_facebook(analysis_run_id: str, row_id: int, url: str) -> None:
|
||||
print("start a facebook")
|
||||
await set_facebook_status(row_id, "processing")
|
||||
data = await ApifyClient(get_env("APIFY_API_TOKEN")).fetch_facebook_page(url)
|
||||
await save_facebook_raw_data(row_id, data)
|
||||
|
|
@ -28,6 +30,7 @@ async def collect_facebook(analysis_run_id: str, row_id: int, url: str) -> None:
|
|||
|
||||
|
||||
async def collect_naver_blog(analysis_run_id: str, row_id: int, url: str) -> None:
|
||||
print("start a blog")
|
||||
await set_naver_blog_status(row_id, "processing")
|
||||
data = await NaverClient(get_env("NAVER_CLIENT_ID"), get_env("NAVER_CLIENT_SECRET")).fetch_blog_rss(normalize_handle("naver_blog", url))
|
||||
await save_naver_blog_raw_data(row_id, data)
|
||||
|
|
@ -35,6 +38,7 @@ async def collect_naver_blog(analysis_run_id: str, row_id: int, url: str) -> Non
|
|||
|
||||
|
||||
async def collect_youtube(analysis_run_id: str, row_id: int, url: str) -> None:
|
||||
print("start a youtube")
|
||||
await set_youtube_status(row_id, "processing")
|
||||
data = await YouTubeClient(get_env("YOUTUBE_API_KEY")).fetch_channel(normalize_handle("youtube", url))
|
||||
await save_youtube_raw_data(row_id, data)
|
||||
|
|
@ -42,6 +46,7 @@ async def collect_youtube(analysis_run_id: str, row_id: int, url: str) -> None:
|
|||
|
||||
|
||||
async def collect_gangnam_unni(analysis_run_id: str, row_id: int, url: str) -> None:
|
||||
print("start a gangnam_unni")
|
||||
await set_gangnam_unni_status(row_id, "processing")
|
||||
data = await FirecrawlClient(get_env("FIRECRAWL_API_KEY")).fetch_gangnam_unni(url)
|
||||
await save_gangnam_unni_raw_data(row_id, data)
|
||||
|
|
|
|||
|
|
@ -7,6 +7,8 @@ services:
|
|||
container_name: o2o-infinith-backend
|
||||
ports:
|
||||
- "8000:8000"
|
||||
env_file:
|
||||
- .env
|
||||
volumes:
|
||||
- ./app:/app
|
||||
restart: unless-stopped
|
||||
|
|
|
|||
Loading…
Reference in New Issue