SAN FRANCISCO INSPECTION COLLECTOR - WINDOWS SETUP GUIDE
=========================================================

This tool collects restaurant inspection data from San Francisco's
MyHealthDepartment portal and uploads it to your server.

FILES INCLUDED:
--------------
1. SF_Collector_Windows.pyw - Main Python script
2. Run_SF_Collector.bat - Easy launcher for Windows
3. api_receiver.php - Server-side receiver (already on your server)

REQUIREMENTS:
------------
1. Windows 10/11
2. Python 3.8+ (download from https://www.python.org/downloads/)
3. Google Chrome browser
4. ChromeDriver (see setup below)

SETUP INSTRUCTIONS:
==================

Step 1: Install Python
----------------------
1. Download Python from https://www.python.org/downloads/
2. Run installer
3. CHECK "Add Python to PATH" during installation
4. Click "Install Now"

Step 2: Install Chrome & ChromeDriver
--------------------------------------
1. Install Google Chrome if not already installed
2. Check your Chrome version:
   - Open Chrome
   - Click three dots menu → Help → About Google Chrome
   - Note the version number (e.g., 120.x.x.x)

3. Download ChromeDriver:
   - Go to https://chromedriver.chromium.org/downloads
   - Download the version matching your Chrome version
   - Extract chromedriver.exe
   - Place it in C:\Windows\ or the same folder as this script

Step 3: Configure the Script
-----------------------------
1. Open SF_Collector_Windows.pyw in a text editor (Notepad++)
2. Find these lines near the top and modify them:

   SERVER_URL = "https://cleankitchens.org/data/api_receiver.php"
   → Change to your actual server URL

   API_KEY = "your-secret-api-key-change-this"
   → Change to a secure key (must match server)

   COLLECT_LIMIT = 10
   → Change to number of inspections to collect (or None for all)

Step 4: Configure Server
------------------------
1. On your server, edit api_receiver.php
2. Change the $API_KEY to match what you set above
3. Make sure the data directory is writable

RUNNING THE COLLECTOR:
=====================

Method 1: Using Batch File (Easiest)
------------------------------------
1. Double-click Run_SF_Collector.bat
2. Follow the prompts
3. Chrome will open and start collecting data

Method 2: Direct Python
-----------------------
1. Open Command Prompt
2. Navigate to this folder
3. Run: python SF_Collector_Windows.pyw

WHAT IT DOES:
============
1. Opens Chrome browser
2. Navigates to SF inspection site
3. Collects inspection IDs
4. For each inspection:
   - Opens the inspection page
   - Extracts data (facility name, address, score, etc.)
   - Downloads the PDF report
   - Saves data locally
   - Uploads to your server

OUTPUT:
======
Local: Creates folder sf_data_[timestamp] with:
  - json/ - Individual inspection JSON files
  - pdfs/ - Downloaded PDF reports

Server: Data uploaded to:
  - [your-server]/data/sf_received_data/json/
  - [your-server]/data/sf_received_data/pdfs/

TROUBLESHOOTING:
===============

"Python not found":
- Make sure Python is installed and added to PATH
- Restart Command Prompt after installing Python

"Chrome not found":
- Install Google Chrome
- Make sure ChromeDriver version matches Chrome version

"403 Forbidden":
- The script must run on a computer that can access the site
- Try opening the site manually in Chrome first
- Don't use HEADLESS mode

"Server upload failed":
- Check SERVER_URL is correct
- Check API_KEY matches server
- Check server has api_receiver.php installed

MONITORING:
==========
Check upload status:
https://[your-server]/data/api_receiver.php?action=status

View logs on server:
/data/sf_receiver.log

SECURITY:
========
- Keep API_KEY secret
- Use HTTPS for server URL
- Don't share the configured script

SUPPORT:
=======
- Check server logs for errors
- Run with HEADLESS = False to see what's happening
- Test server connection first before collecting

AUTOMATION:
==========
To run automatically:
1. Use Windows Task Scheduler
2. Create task to run Run_SF_Collector.bat
3. Set to run daily/weekly as needed

==========================================================
Last Updated: 2025-08-16