Async Python script to fetch jewelry making charges from brand websites, analyze with Google Gemini, and store in MongoDB.
- Install dependencies:
pip install -r requirements.txt- Set environment variables:
# Google Gemini API Key (required)
export GEMINI_API_KEY="your_gemini_api_key_here"
# MongoDB URI (optional - defaults to localhost)
export MONGODB_URI="mongodb://localhost:27017/"- Go to Google AI Studio
- Sign in with your Google account
- Click "Create API Key"
- Copy your API key
Run the script:
python jewelry_scraper.py- Fetches HTML asynchronously from 4 jewelry brand websites using
httpx - Analyzes content using Google Gemini SDK with structured JSON output
- Validates data using Pydantic models
- Stores in MongoDB with upsert functionality
Data stored in MongoDB follows this structure:
{
"brand": "kalyan",
"categories": {
"Gold Rings": "₹300-500 per gram",
"Gold Chains": "₹200-400 per gram",
...
},
"timestamp": "2024-02-10T12:00:00Z",
"source_url": "https://..."
}- Database:
jewelry_db - Collection:
making_charges - Updates existing records or inserts new ones based on brand name
✅ Async/await patterns for concurrent fetching
✅ Structured output from Gemini API
✅ Pydantic validation
✅ MongoDB storage with upsert
✅ Error handling for each step
✅ Progress logging