# Journey Import Cron ## Script `php/cron/import-journeys.php` The script imports BigChange vehicle tracking CSV rows into the `journeys` table. - Supports `--csv=/path/file.csv` - Supports `--url=https://...` - Supports BigChange URL template mode (no manual CSV step) - Supports env vars: - `JOURNEYS_CSV_PATH` - `JOURNEYS_CSV_URL` - `BC_JOURNEYS_URL_TEMPLATE` - `BC_USERNAME` - `BC_PASSWORD` - `BC_KEY` It deduplicates rows using `vehicle + start + stop + location + distance`. ## Fully Automated BigChange Mode Set `BC_JOURNEYS_URL_TEMPLATE` with date placeholders and run the same script nightly. You can also skip template setup completely and just set: - `BC_USERNAME` - `BC_PASSWORD` - `BC_KEY` In that case the script auto-builds: `https://webservice.bigchangeapps.com/v01/services.ashx?login=...&pwd=...&key=...&action=journeys&Start={from_iso}&End={to_iso}` Supported placeholders: - `{from_iso}` / `{to_iso}` -> `YYYY-MM-DD` - `{from_dmy}` / `{to_dmy}` -> `DD/MM/YYYY` - `{from_ymd}` / `{to_ymd}` -> `YYYYMMDD` - `{from_ts}` / `{to_ts}` -> `YYYY-MM-DDTHH:MM:SS` Date window defaults: - `from = yesterday` - `to = today` Optional CLI override: - `--from=YYYY-MM-DD` - `--to=YYYY-MM-DD` Example template using your working endpoint: ```bash export BC_JOURNEYS_URL_TEMPLATE="https://webservice.bigchangeapps.com/v01/services.ashx?login={username}&pwd={password}&key={key}&action=journeys&Start={from_iso}&End={to_iso}" ``` Then either: - replace `{username}` / `{password}` / `{key}` directly in the value, or - build it from env in your shell before scheduling. ## Example Manual Runs ```bash php /home/keith/git/guardian-jms/php/cron/import-journeys.php --csv=/home/keith/git/guardian-jms/docs/journey_report.csv ``` ```bash php /home/keith/git/guardian-jms/php/cron/import-journeys.php --url="https://example.com/journey_report.csv" ``` ## Nightly Cron Example ```bash 15 2 * * * /usr/bin/php /home/keith/git/guardian-jms/php/cron/import-journeys.php --csv=/home/keith/imports/journey_report.csv >> /home/keith/git/guardian-jms/logs/journeys-import.log 2>&1 ``` If you pull CSV from a URL: ```bash 15 2 * * * JOURNEYS_CSV_URL="https://example.com/journey_report.csv" /usr/bin/php /home/keith/git/guardian-jms/php/cron/import-journeys.php >> /home/keith/git/guardian-jms/logs/journeys-import.log 2>&1 ``` If you want full BigChange automation (no manual export): ```bash 15 2 * * * BC_JOURNEYS_URL_TEMPLATE="https://webservice.bigchangeapps.com/v01/services.ashx?login=YOUR_LOGIN&pwd=YOUR_PWD&key=YOUR_KEY&action=YOUR_TRACKING_ACTION&from={from_dmy}&to={to_dmy}" /usr/bin/php /home/keith/git/guardian-jms/php/cron/import-journeys.php >> /home/keith/git/guardian-jms/logs/journeys-import.log 2>&1 ``` Recommended cron using the direct credentials mode: ```bash 15 2 * * * BC_USERNAME="YOUR_LOGIN" BC_PASSWORD="YOUR_PASSWORD" BC_KEY="YOUR_KEY" /usr/bin/php /home/keith/git/guardian-jms/php/cron/import-journeys.php >> /home/keith/git/guardian-jms/logs/journeys-import.log 2>&1 ```