Auto-update: Fri Jan 17 11:58:21 PST 2025
This commit is contained in:
parent
1863edbc06
commit
ab86c3566f
1 changed files with 5 additions and 9 deletions
|
@ -20,13 +20,12 @@ from fastapi import APIRouter, BackgroundTasks, UploadFile, Form, HTTPException,
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from sijapi import Archivist, News, Tts, OBSIDIAN_VAULT_DIR, OBSIDIAN_RESOURCES_DIR
|
from sijapi import Archivist, News, Tts, OBSIDIAN_VAULT_DIR, OBSIDIAN_RESOURCES_DIR
|
||||||
from sijapi.utilities import html_to_markdown, download_file, sanitize_filename, assemble_journal_path, assemble_archive_path, contains_profanity, is_ad_or_tracker
|
from sijapi.utilities import html_to_markdown, download_file, sanitize_filename, assemble_journal_path, assemble_archive_path, contains_profanity, is_ad_or_tracker
|
||||||
from sijapi.routers import gis, llm, tts, note
|
from sijapi.routers import gis, llm, tts, note, email
|
||||||
from sijapi.logs import get_logger
|
from sijapi.logs import get_logger
|
||||||
l = get_logger(__name__)
|
l = get_logger(__name__)
|
||||||
|
|
||||||
news = APIRouter()
|
news = APIRouter()
|
||||||
|
|
||||||
|
|
||||||
@news.post("/clip")
|
@news.post("/clip")
|
||||||
async def clip_post(
|
async def clip_post(
|
||||||
bg_tasks: BackgroundTasks,
|
bg_tasks: BackgroundTasks,
|
||||||
|
@ -153,7 +152,8 @@ async def process_and_save_article(
|
||||||
title: Optional[str] = None,
|
title: Optional[str] = None,
|
||||||
tts_mode: str = "summary",
|
tts_mode: str = "summary",
|
||||||
voice: str = Tts.elevenlabs.default,
|
voice: str = Tts.elevenlabs.default,
|
||||||
site_name: Optional[str] = None
|
site_name: Optional[str] = None,
|
||||||
|
email_address: str = None
|
||||||
) -> str:
|
) -> str:
|
||||||
'''
|
'''
|
||||||
Primary function for saving articles.
|
Primary function for saving articles.
|
||||||
|
@ -162,7 +162,7 @@ Primary function for saving articles.
|
||||||
# Fetch and parse article
|
# Fetch and parse article
|
||||||
article = await fetch_and_parse_article(url)
|
article = await fetch_and_parse_article(url)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# Generate title and file paths
|
# Generate title and file paths
|
||||||
title = sanitize_filename(title or article.title or f"Untitled - {dt_datetime.now().strftime('%Y-%m-%d')}")
|
title = sanitize_filename(title or article.title or f"Untitled - {dt_datetime.now().strftime('%Y-%m-%d')}")
|
||||||
markdown_filename, relative_path = assemble_journal_path(dt_datetime.now(), subdir="Articles", filename=title, extension=".md")
|
markdown_filename, relative_path = assemble_journal_path(dt_datetime.now(), subdir="Articles", filename=title, extension=".md")
|
||||||
|
@ -197,10 +197,6 @@ Primary function for saving articles.
|
||||||
raise HTTPException(status_code=500, detail=str(e))
|
raise HTTPException(status_code=500, detail=str(e))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
from newspaper import Article as NewspaperArticle
|
|
||||||
|
|
||||||
async def fetch_and_parse_article(url: str) -> Article:
|
async def fetch_and_parse_article(url: str) -> Article:
|
||||||
# Try trafilatura first
|
# Try trafilatura first
|
||||||
source = trafilatura.fetch_url(url)
|
source = trafilatura.fetch_url(url)
|
||||||
|
@ -230,7 +226,7 @@ async def fetch_and_parse_article(url: str) -> Article:
|
||||||
|
|
||||||
# If trafilatura fails, use newspaper3k
|
# If trafilatura fails, use newspaper3k
|
||||||
try:
|
try:
|
||||||
newspaper_article = NewspaperArticle(url)
|
newspaper_article = Article(url)
|
||||||
newspaper_article.download()
|
newspaper_article.download()
|
||||||
newspaper_article.parse()
|
newspaper_article.parse()
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue