- Add backend stale process monitoring API (/api/stale-processes) - Add users management route - Add frontend landing page and stale process monitor UI on /scraper-tools - Move old development scripts to backend/archive/ - Update frontend build with new features 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
109 lines
4.4 KiB
JavaScript
109 lines
4.4 KiB
JavaScript
"use strict";
|
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
if (k2 === undefined) k2 = k;
|
|
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
}
|
|
Object.defineProperty(o, k2, desc);
|
|
}) : (function(o, m, k, k2) {
|
|
if (k2 === undefined) k2 = k;
|
|
o[k2] = m[k];
|
|
}));
|
|
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
}) : function(o, v) {
|
|
o["default"] = v;
|
|
});
|
|
var __importStar = (this && this.__importStar) || (function () {
|
|
var ownKeys = function(o) {
|
|
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
var ar = [];
|
|
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
return ar;
|
|
};
|
|
return ownKeys(o);
|
|
};
|
|
return function (mod) {
|
|
if (mod && mod.__esModule) return mod;
|
|
var result = {};
|
|
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
__setModuleDefault(result, mod);
|
|
return result;
|
|
};
|
|
})();
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
const pg_1 = require("pg");
|
|
const fs = __importStar(require("fs"));
|
|
const pool = new pg_1.Pool({ connectionString: process.env.DATABASE_URL });
|
|
async function importDispensaries(filePath) {
|
|
const data = JSON.parse(fs.readFileSync(filePath, 'utf-8'));
|
|
console.log(`Importing ${data.length} dispensaries...`);
|
|
let inserted = 0;
|
|
let updated = 0;
|
|
let errors = 0;
|
|
for (const d of data) {
|
|
try {
|
|
// Check if dispensary exists by name and city
|
|
const { rows: existing } = await pool.query(`SELECT id FROM dispensaries WHERE name = $1 AND city = $2`, [d.name, d.city]);
|
|
if (existing.length > 0) {
|
|
// Update existing
|
|
await pool.query(`
|
|
UPDATE dispensaries SET
|
|
dba_name = COALESCE($1, dba_name),
|
|
company_name = COALESCE($2, company_name),
|
|
slug = COALESCE($3, slug),
|
|
address = COALESCE($4, address),
|
|
state = COALESCE($5, state),
|
|
zip = COALESCE($6, zip),
|
|
latitude = COALESCE($7, latitude),
|
|
longitude = COALESCE($8, longitude),
|
|
website = COALESCE($9, website),
|
|
menu_type = COALESCE($10, menu_type),
|
|
menu_url = COALESCE($11, menu_url),
|
|
platform_dispensary_id = COALESCE($12, platform_dispensary_id),
|
|
updated_at = NOW()
|
|
WHERE id = $13
|
|
`, [
|
|
d.dba_name, d.company_name, d.slug,
|
|
d.address, d.state, d.zip,
|
|
d.latitude, d.longitude, d.website,
|
|
d.menu_type, d.menu_url, d.platform_dispensary_id,
|
|
existing[0].id
|
|
]);
|
|
console.log(`Updated: [${existing[0].id}] ${d.name} (${d.city})`);
|
|
updated++;
|
|
}
|
|
else {
|
|
// Insert new
|
|
const { rows: newRow } = await pool.query(`
|
|
INSERT INTO dispensaries (
|
|
name, dba_name, company_name, slug,
|
|
address, city, state, zip, latitude, longitude,
|
|
website, menu_type, menu_url, platform_dispensary_id,
|
|
created_at, updated_at
|
|
) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, NOW(), NOW())
|
|
RETURNING id
|
|
`, [
|
|
d.name, d.dba_name, d.company_name, d.slug,
|
|
d.address, d.city, d.state, d.zip, d.latitude, d.longitude,
|
|
d.website, d.menu_type, d.menu_url, d.platform_dispensary_id
|
|
]);
|
|
console.log(`Inserted: [${newRow[0].id}] ${d.name} (${d.city})`);
|
|
inserted++;
|
|
}
|
|
}
|
|
catch (err) {
|
|
console.error(`Error for ${d.name}: ${err.message}`);
|
|
errors++;
|
|
}
|
|
}
|
|
console.log(`\n=== Import Summary ===`);
|
|
console.log(`Inserted: ${inserted}`);
|
|
console.log(`Updated: ${updated}`);
|
|
console.log(`Errors: ${errors}`);
|
|
await pool.end();
|
|
}
|
|
const filePath = process.argv[2] || '/tmp/dispensaries-export.json';
|
|
importDispensaries(filePath).catch(console.error);
|