Skip to content

Conversation

@alikhan-s
Copy link

No description provided.

@alikhan-s alikhan-s changed the title Feature/foodrepo-cron Feature domains/foodrepo.org/cron Oct 14, 2025
@smvrnn smvrnn requested a review from Copilot October 31, 2025 16:56
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds a FoodRepo data parser and synchronization tool for extracting product information from the FoodRepo API and syncing it to a BarBase database. The implementation includes retry logic, progress tracking, and Cloudflare bypass capabilities.

  • Parser scripts to fetch product data from FoodRepo API with pagination and retry mechanisms
  • Async sync script to upload/update products in BarBase database
  • Documentation and configuration files for setup

Reviewed Changes

Copilot reviewed 5 out of 14 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
domains/foodrepo.org/parser.py FoodRepo API parser with hardcoded API key extracting product data
domains/foodrepo.org/cron/sync_barbase.py Async sync script with hardcoded API key for uploading to BarBase
domains/foodrepo.org/cron/foodrepo_parser.py Duplicate parser with placeholder API key using xlarge images
domains/foodrepo.org/README.md Documentation for parser setup and usage
COMMANDS.md Virtual environment creation command
.gitignore Adds venv and .idea/ to ignore list
.idea/* IntelliJ IDEA configuration files
Files not reviewed (6)
  • .idea/.gitignore: Language not supported
  • .idea/barbase-tools.iml: Language not supported
  • .idea/inspectionProfiles/profiles_settings.xml: Language not supported
  • .idea/misc.xml: Language not supported
  • .idea/modules.xml: Language not supported
  • .idea/vcs.xml: Language not supported

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +5 to +6

API_KEY = "1b3483017a437b7920add1855664d43b"
Copy link

Copilot AI Oct 31, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hardcoded API key should not be committed to the repository. Move this to an environment variable or configuration file that is excluded from version control.

Suggested change
API_KEY = "1b3483017a437b7920add1855664d43b"
import os
API_KEY = os.environ.get("FOODREPO_API_KEY")
if not API_KEY:
raise RuntimeError("FOODREPO_API_KEY environment variable not set. Please set it before running this script.")

Copilot uses AI. Check for mistakes.
Comment on lines 13 to 16
API_KEY = "d9997c62-6b0c-4f61-9c7e-decae5d968a3"
STATE_FILE = "data/sync_state_v2.json"
FOODREPO_FILE = "data/foodrepo.json"

Copy link

Copilot AI Oct 31, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hardcoded API key should not be committed to the repository. Move this to an environment variable or configuration file that is excluded from version control.

Suggested change
API_KEY = "d9997c62-6b0c-4f61-9c7e-decae5d968a3"
STATE_FILE = "data/sync_state_v2.json"
FOODREPO_FILE = "data/foodrepo.json"
API_KEY = os.environ.get("BARBASE_API_KEY")
STATE_FILE = "data/sync_state_v2.json"
FOODREPO_FILE = "data/foodrepo.json"
if not API_KEY:
raise RuntimeError("BARBASE_API_KEY environment variable not set")

Copilot uses AI. Check for mistakes.
log.info(f"[+] Added image {url} to product {product_id}")
else:
log.warning(f"[WARN] Could not add image ({resp.status_code})")
log.warning(f"[WARN] Could not find images for ({product_id})")
Copy link

Copilot AI Oct 31, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line 111 executes unconditionally and always logs a warning even when images were successfully added. This warning should either be inside an 'else' block for the 'if images:' condition on line 103, or removed entirely if it's not needed.

Suggested change
log.warning(f"[WARN] Could not find images for ({product_id})")
else:
log.warning(f"[WARN] Could not find images for ({product_id})")

Copilot uses AI. Check for mistakes.
BARBASE_API = "https://bb.solutionary.me/api/v1"
API_KEY = "d9997c62-6b0c-4f61-9c7e-decae5d968a3"
STATE_FILE = "data/sync_state_v2.json"
FOODREPO_FILE = "data/foodrepo.json"
Copy link

Copilot AI Oct 31, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error message on line 178 references 'foodrepo_data.json' but the constant FOODREPO_FILE is set to 'data/foodrepo.json'. These filenames are inconsistent.

Copilot uses AI. Check for mistakes.

save_json(STATE_FILE, updated_state)
log.info("[STATE] Final state saved")
save_json(STATE_FILE, updated_state)
Copy link

Copilot AI Oct 31, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The state is saved twice consecutively - once inside the async context manager (line 192) and again immediately after (line 194). Remove the duplicate save operation on line 194.

Suggested change
save_json(STATE_FILE, updated_state)

Copilot uses AI. Check for mistakes.
name = product.get("display_name_translations", {}).get(lang) or \
product.get("display_name_translations", {}).get("en", "Not found")
raw_images = product.get("images", [])
images = [img.get("large") for img in raw_images if "large" in img]
Copy link

Copilot AI Oct 31, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The parser extracts 'large' image format while the duplicate parser in foodrepo_parser.py extracts 'xlarge' format (line 54). This inconsistency could lead to different image qualities being processed. Consider standardizing to one image size across both files.

Suggested change
images = [img.get("large") for img in raw_images if "large" in img]
images = [img.get("xlarge") for img in raw_images if "xlarge" in img]

Copilot uses AI. Check for mistakes.
import random
import re
from datetime import datetime, timezone
from typing import Any, List, Dict
Copy link

Copilot AI Oct 31, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Import of 'Dict' is not used.

Suggested change
from typing import Any, List, Dict
from typing import Any, List

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants