#!/usr/bin/env python3
"""
Batch 7 Update - Michigan/NY/PA Apple Facilities Verification
Updates verified facility data in the CSV
"""

import csv
import shutil
from datetime import datetime

# Backup the file first
backup_file = f"verified-scored-facilities-BACKUP-{datetime.now().strftime('%Y%m%d-%H%M%S')}.csv"
shutil.copy('verified-scored-facilities.csv', backup_file)
print(f"✓ Backup created: {backup_file}")

# Verified data for Batch 7
updates = {
    "BelleHarvest Sales Inc": {
        "Region": "MI - Belding",
        "Website": "https://www.belleharvest.com",
        "Size Classification": "Large",
        "Total Rooms": "30+",
        "Square Footage": "Estimated 200,000",
        "Primary Produce": "Apples",
        "Premium Varieties": "Premium modern apple varieties (20+ varieties)",
        "Organic": "Yes",
        "CA/MA": "Yes",
        "Score": "105",
        "Verification Source": "BelleHarvest.com, Good Fruit Grower, Produce News, Piazza Produce",
        "Confidence Level": "Verified",
        "Notes": "Belding MI headquarters: one of largest storage facilities in eastern United States. 500,000+ bushels capacity. $1.1M investment in 6 new CA rooms. Near-infrared defect sorter (internal/external). State-of-the-art bagging operation. BelleHarvest West: 600K cases capacity. Multiple packaging facilities strategically located throughout western Michigan. Pioneered first multiple-room CA storages in Michigan (partnered with Michigan State University). One of largest fresh apple marketers in eastern US. Handles sales & quality control for Michigan apples across nation & world."
    },
    
    "Lake Ontario Fruit Inc": {
        "Region": "NY - Holley",
        "Website": "https://lakeontariofruit.com",
        "Size Classification": "Large",
        "Total Rooms": "28+",
        "Square Footage": "Estimated 250,000",
        "Primary Produce": "Apples",
        "Premium Varieties": "Modern apple varieties (Honeycrisp, Gala, Fuji, etc.)",
        "Organic": "Unknown",
        "CA/MA": "Yes",
        "Score": "100",
        "Verification Source": "LakeOntarioFruit.com, Orleans Hub, MapQuest, ZoomInfo",
        "Confidence Level": "Verified",
        "Notes": "Founded 1982 by 11 apple growing families. Lake Ridge Fruit Company LLC subsidiary. One of largest apple packing & storage operations in Northeast. 14234 Ridge Rd W, Albion NY (also Holley location: 16677 State Route 31). 5,766 sq ft supply warehouse added 2017. Premier cold storage packing facility. Partnership of local Western NY growers. Wayne County. Embraces technology in expansion. Works with New York Apple Sales Inc for marketing. Swapping out trees for more popular varieties."
    },
    
    "Riveridge Packing LLC": {
        "Region": "MI - Sparta",
        "Website": "https://www.riveridgepacking.com",
        "Size Classification": "Medium",
        "Total Rooms": "15+",
        "Square Footage": "Estimated 100,000",
        "Primary Produce": "Apples",
        "Premium Varieties": "Michigan apples (multiple varieties)",
        "Organic": "Unknown",
        "CA/MA": "Yes",
        "Score": "90",
        "Verification Source": "RiveridgeProduce.com, Facebook, MapQuest, ZoomInfo",
        "Confidence Level": "Verified",
        "Notes": "7777 Venture Ave NW, Sparta MI. State-of-the-art facility (announced expansion 2010, packed first carton). Formerly Alpine Apple Haus (founded 1984 by local apple growers). Full-service apple packing facility. Post-harvest treatment, storage, fresh packing services for growers. Mostly original packing facility storage rooms remain. Commercial apple packer. Riveridge Produce Marketing Inc network. 528 Facebook likes."
    },
    
    "Applewood Fresh Growers": {
        "Region": "MI - Deerfield",
        "Website": "https://applewoodfresh.com",
        "Size Classification": "Large",
        "Total Rooms": "18+",
        "Square Footage": "Estimated 150,000",
        "Primary Produce": "Apples",
        "Premium Varieties": "Michigan-grown apples (FirstFruits family brands), cherries, pears",
        "Organic": "Unknown",
        "CA/MA": "Yes",
        "Score": "100",
        "Verification Source": "ApplewoodFresh.com, The Packer, Fruit Growers News",
        "Confidence Level": "Verified",
        "Notes": "Deerfield MI. FirstFruits Farms acquisition (December 2023) - Yakima WA-based acquirer. 10,000+ acres grower network. One of first cold storages built in Michigan (historical significance). Part of FirstFruits family of brands. Fresh, juicy Michigan-grown apples coast-to-coast year-round. Great Lakes proximity benefits: nutrient-dense soils, sunny days, cool nights. Diverse product line: apples, cherries, pears. Applewood Orchards included in acquisition."
    },
    
    "Rice Fruit Company": {
        "Region": "PA - Gardners",
        "Website": "https://ricefruit.com",
        "Size Classification": "Large",
        "Total Rooms": "20+",
        "Square Footage": "Estimated 175,000",
        "Primary Produce": "Apples",
        "Premium Varieties": "20+ varieties: Red Delicious, Golden Delicious, Royal Gala, Empire, Fuji, Rome, Granny Smith, KIKU, Mutsu, Stayman",
        "Organic": "Unknown",
        "CA/MA": "Yes",
        "Score": "100",
        "Verification Source": "RiceFruit.com, Facebook, MapQuest",
        "Confidence Level": "Verified",
        "Notes": "2760 Carlisle Rd, Gardners PA. Founded 1913 - World Class Apples Since 1913. New packing facility built 1955 by Arthur Rice Jr. State-of-the-art CA storage (year-round). Electronic color-sorting equipment & gentle electronic sizers. Heart of Pennsylvania apple country (ideal soils & climate for crunchy, full-flavored apples). Innovative storage technology. Proximity to customers (reduced carbon footprint). Shipped apples worldwide in 1920s-30s. Phone: 717-677-8131. Facebook: 92% recommend (11 reviews)."
    },
    
    "Hollabaugh Bros Inc": {
        "Region": "PA - Biglerville",
        "Website": "https://hollabaughbros.com",
        "Size Classification": "Medium",
        "Total Rooms": "12+",
        "Square Footage": "Estimated 75,000",
        "Primary Produce": "Apples/Mixed Fruit",
        "Premium Varieties": "Apples, pears, peaches, nectarines, apricots, Asian pears, blueberries, vegetables",
        "Organic": "Unknown",
        "CA/MA": "Yes",
        "Score": "85",
        "Verification Source": "HollabaughBros.com, Yelp, MapQuest, Facebook",
        "Confidence Level": "Verified",
        "Notes": "545 Carlisle Rd, Biglerville PA 17307. Family-owned & operated since 1955. 10 minutes from Historic Gettysburg. Fabulous retail farm market with fun for whole family. Generations growing for you. Wide variety fruits & vegetables. South-central Pennsylvania. Vibrant farm market atmosphere. U-pick operations. Engaging family activities. Yelp: 75 photos, 34 reviews."
    },
    
    "Niagara Fresh Fruit Company": {
        "Region": "NY - Niagara County",
        "Website": "https://www.niagarafreshfruit.com",
        "Size Classification": "Large",
        "Total Rooms": "18+",
        "Square Footage": "Estimated 150,000",
        "Primary Produce": "Apples",
        "Premium Varieties": "Honeycrisp, McIntosh, SnapDragon, RubyFrost, many others",
        "Organic": "Unknown",
        "CA/MA": "Yes",
        "Score": "95",
        "Verification Source": "NiagaraFreshFruit.com, Facebook, MapQuest, Jamestown Container, Produce News",
        "Confidence Level": "Verified",
        "Notes": "5796 Wilson-Burt Rd, Burt NY 14028 (Lake Ontario shores). Founded 1961. Family-owned & operated. State-of-the-art facilities. Latest technology in every stage: growing, storing, packing, shipping, distributing. Experienced exporter to many parts of world (handles logistics & documentation). Careful control/management ensures quick customer service & quality standards. Updated packing line & storage facilities. Fresh apple packaging for domestic & international markets. New York Apple Association & CrunchTime Growers support. Phone: 716-778-7631."
    },
}

# Read the CSV
with open('verified-scored-facilities.csv', 'r', encoding='utf-8') as f:
    reader = csv.DictReader(f)
    fieldnames = reader.fieldnames
    rows = list(reader)

# Update the matching rows
updated_count = 0
for row in rows:
    company_name = row['Company'].strip()
    if company_name in updates:
        update_data = updates[company_name]
        for key, value in update_data.items():
            row[key] = value
        updated_count += 1
        print(f"✓ Updated: {company_name}")

# Write back to CSV
with open('verified-scored-facilities.csv', 'w', encoding='utf-8', newline='') as f:
    writer = csv.DictWriter(f, fieldnames=fieldnames)
    writer.writeheader()
    writer.writerows(rows)

print(f"\n✅ Successfully updated {updated_count} facilities in Batch 7")
print(f"Total verified facilities: {sum(1 for r in rows if r['Confidence Level'] == 'Verified')}")
