scrapper update
This commit is contained in:
parent
8f60e9bcdf
commit
02f6ed5b9b
10
scraper.py
10
scraper.py
@ -78,25 +78,29 @@ def scrape_and_store(db: Session, req: ScrapeRequest) -> List[ScrapedPost]:
|
||||
if not media_items:
|
||||
continue
|
||||
|
||||
# ✅ Upload thumbnail separately and store local version
|
||||
uploaded_thumb = upload_media_from_url(post.thumbnail_url, str(req.seller_id), f"{post_id}/thumbnail")
|
||||
final_thumbnail = uploaded_thumb or post.thumbnail_url # fallback if upload fails
|
||||
|
||||
# Save to DB
|
||||
post_entry = InstagramPost(
|
||||
ig_post_id=post_id,
|
||||
account_id=account.id,
|
||||
media_type="carousel" if post.media_type == 8 else ("video" if post.media_type == 2 else "image"),
|
||||
caption=post.caption_text or "",
|
||||
thumbnail_url=post.thumbnail_url,
|
||||
thumbnail_url=final_thumbnail,
|
||||
local_media=[m.dict() for m in media_items],
|
||||
created_at=post.taken_at or datetime.utcnow(),
|
||||
)
|
||||
db.add(post_entry)
|
||||
db.commit()
|
||||
|
||||
# Add to result for response
|
||||
# Add to response
|
||||
result.append(ScrapedPost(
|
||||
ig_post_id=post_id,
|
||||
media_type=post_entry.media_type,
|
||||
caption=post_entry.caption,
|
||||
thumbnail_url=post_entry.thumbnail_url,
|
||||
thumbnail_url=final_thumbnail,
|
||||
local_media=media_items,
|
||||
created_at=post_entry.created_at
|
||||
))
|
||||
|
||||
Loading…
Reference in New Issue
Block a user