enhancement: Make article processor more robust with multiple path support and fallback file format detection
This commit is contained in:
parent
ba8f24fcbd
commit
abb63db4b7
@ -42,17 +42,37 @@ class ArticleProcessor:
|
||||
logger.info(f"Checking for articles in: {scraper_dir}")
|
||||
if not os.path.exists(scraper_dir):
|
||||
logger.warning(f"Scraper directory does not exist: {scraper_dir}")
|
||||
# Try alternative paths
|
||||
alternative_paths = [
|
||||
"/scraper/articles",
|
||||
"/app/articles",
|
||||
"/articles"
|
||||
]
|
||||
for alt_path in alternative_paths:
|
||||
if os.path.exists(alt_path):
|
||||
logger.info(f"Found articles directory at alternative path: {alt_path}")
|
||||
scraper_dir = alt_path
|
||||
break
|
||||
else:
|
||||
return []
|
||||
|
||||
logger.info(f"Directory exists, walking through files...")
|
||||
file_count = 0
|
||||
for root, dirs, files in os.walk(scraper_dir):
|
||||
for file in files:
|
||||
file_count += 1
|
||||
# Check for JSON files (expected format)
|
||||
if file.endswith('.json'):
|
||||
file_path = os.path.join(root, file)
|
||||
if not self.cache_manager.is_processed(file_path):
|
||||
unprocessed_articles.append((file_path, file))
|
||||
# Also check for text files (fallback for different formats)
|
||||
elif file.endswith(('.txt', '.md')):
|
||||
file_path = os.path.join(root, file)
|
||||
if not self.cache_manager.is_processed(file_path):
|
||||
unprocessed_articles.append((file_path, file))
|
||||
|
||||
logger.info(f"Found {len(unprocessed_articles)} unprocessed articles")
|
||||
logger.info(f"Scanned {file_count} files, found {len(unprocessed_articles)} unprocessed articles")
|
||||
return unprocessed_articles
|
||||
|
||||
except Exception as e:
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user