diff --git a/foodie_automator_google.py b/foodie_automator_google.py index 6f53d6f..8ecfee1 100644 --- a/foodie_automator_google.py +++ b/foodie_automator_google.py @@ -87,7 +87,7 @@ class GoogleTrendsScraper: """Load and return the set of used images.""" try: data = load_json_file(FILE_PATHS["used_images"], IMAGE_EXPIRATION_DAYS) - return {entry["title"] for entry in data if "title" in entry} + return {entry["url"] for entry in data if "url" in entry} except Exception as e: logger.error(f"Error loading used images: {e}") return set() diff --git a/foodie_automator_reddit.py b/foodie_automator_reddit.py index 9a32a50..b360a7f 100644 --- a/foodie_automator_reddit.py +++ b/foodie_automator_reddit.py @@ -146,7 +146,7 @@ class RedditScraper: """Load and return the set of used images.""" try: data = load_json_file(FILE_PATHS["used_images"], IMAGE_EXPIRATION_DAYS) - return {entry["title"] for entry in data if "title" in entry} + return {entry["url"] for entry in data if "url" in entry} except Exception as e: logger.error(f"Error loading used images: {e}") return set() diff --git a/foodie_automator_rss.py b/foodie_automator_rss.py index 0682f6a..660f4c2 100644 --- a/foodie_automator_rss.py +++ b/foodie_automator_rss.py @@ -142,7 +142,7 @@ class RSSScraper: """Load and return the set of used images.""" try: data = load_json_file(FILE_PATHS["used_images"], IMAGE_EXPIRATION_DAYS) - return {entry["title"] for entry in data if "title" in entry} + return {entry["url"] for entry in data if "url" in entry} except Exception as e: logger.error(f"Error loading used images: {e}") return set() diff --git a/foodie_config.py b/foodie_config.py index 124a449..2975016 100644 --- a/foodie_config.py +++ b/foodie_config.py @@ -282,7 +282,7 @@ PERSONA_CONFIGS: Dict[str, PersonaConfig] = { } # File paths -BASE_DIR = Path("/home/shane/foodie_automator") +BASE_DIR = Path("/home/blade/insiderfoodie/foodie_automator") FILE_PATHS = { "posted_rss_titles": BASE_DIR / "posted_rss_titles.json", "posted_google_titles": BASE_DIR / "posted_google_titles.json", diff --git a/foodie_utils.py b/foodie_utils.py index f236d78..9901d09 100644 --- a/foodie_utils.py +++ b/foodie_utils.py @@ -904,6 +904,9 @@ def load_used_images(): with open(USED_IMAGES_FILE, 'r') as f: used_images = set(json.loads(line.strip())['url'] for line in f if line.strip()) logger.info(f"Loaded {len(used_images)} used images from {USED_IMAGES_FILE}") + else: + used_images = set() + logger.info(f"Used images file {USED_IMAGES_FILE} does not exist yet. Starting with empty set.") except Exception as e: logger.error(f"Failed to load used images: {e}") used_images = set() @@ -911,6 +914,9 @@ def load_used_images(): def save_used_images(): """Save the set of used image URLs to file.""" try: + # Create directory if it doesn't exist + os.makedirs(os.path.dirname(USED_IMAGES_FILE), exist_ok=True) + with open(USED_IMAGES_FILE, 'w') as f: for url in used_images: json.dump({'url': url, 'timestamp': datetime.now(timezone.utc).isoformat()}, f)