Start Umbau zu postgres
This commit is contained in:
File diff suppressed because it is too large
Load Diff
1
crawler/data/businesses_.json
Normal file
1
crawler/data/businesses_.json
Normal file
@@ -0,0 +1 @@
|
||||
[]
|
||||
@@ -11,17 +11,20 @@
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"devDependencies": {
|
||||
"typescript": "^5.2.2"
|
||||
"typescript": "^5.4.5"
|
||||
},
|
||||
"dependencies": {
|
||||
"@types/node": "^20.12.7",
|
||||
"currency.js": "^2.0.4",
|
||||
"fs-extra": "^11.2.0",
|
||||
"inquirer": "^9.2.17",
|
||||
"ioredis": "^5.3.2",
|
||||
"node-fetch": "^3.3.2",
|
||||
"pg": "^8.11.5",
|
||||
"puppeteer": "^22.1.0",
|
||||
"redis": "^4.6.13",
|
||||
"redis-om": "^0.4.3",
|
||||
"uuidv4": "^6.2.13",
|
||||
"winston": "^3.13.0",
|
||||
"yargs": "^17.7.2"
|
||||
}
|
||||
|
||||
85
crawler/postgres_business_import.ts
Normal file
85
crawler/postgres_business_import.ts
Normal file
@@ -0,0 +1,85 @@
|
||||
import pkg from 'pg';
|
||||
const { Pool } = pkg;
|
||||
import fsextra from 'fs-extra';
|
||||
const { fstat, readFileSync, writeJsonSync } = fsextra;
|
||||
import { v4 as uuidv4 } from 'uuid';
|
||||
// PostgreSQL Verbindungskonfiguration
|
||||
const pool = new Pool({
|
||||
user: 'bizmatch',
|
||||
host: 'localhost',
|
||||
database: 'bizmatch',
|
||||
password: 'xieng7Seih',
|
||||
port: 5432,
|
||||
});
|
||||
|
||||
// Typdefinition für das JSON-Objekt
|
||||
interface BusinessListing {
|
||||
userId?: string;
|
||||
listingsCategory: string;
|
||||
title: string;
|
||||
description: string;
|
||||
type: string;
|
||||
state: string;
|
||||
city: string;
|
||||
id: string;
|
||||
price: number;
|
||||
salesRevenue: number;
|
||||
leasedLocation: boolean;
|
||||
established: number;
|
||||
employees: number;
|
||||
reasonForSale: string;
|
||||
supportAndTraining: string;
|
||||
cashFlow: number;
|
||||
brokerLicencing: string;
|
||||
internalListingNumber: number;
|
||||
realEstateIncluded: boolean;
|
||||
franchiseResale: boolean;
|
||||
draft: boolean;
|
||||
internals: string;
|
||||
created: Date;
|
||||
}
|
||||
|
||||
// Funktion zum Einlesen und Importieren von JSON-Daten
|
||||
async function importJsonData(filePath: string): Promise<void> {
|
||||
try {
|
||||
const data: string = readFileSync(filePath, 'utf8');
|
||||
const jsonData: BusinessListing[] = JSON.parse(data); // Erwartet ein Array von Objekten
|
||||
const out: BusinessListing[] =[]
|
||||
// Daten für jedes Listing in die Datenbank einfügen
|
||||
for (const listing of jsonData) {
|
||||
// const uuid = uuidv4();
|
||||
// listing.id=uuid;
|
||||
const values = [
|
||||
listing.userId, listing.listingsCategory, listing.title, listing.description,
|
||||
listing.type, listing.state, listing.city, listing.id, listing.price, listing.salesRevenue,
|
||||
listing.leasedLocation, listing.established, listing.employees,
|
||||
listing.reasonForSale, listing.supportAndTraining, listing.cashFlow, listing.brokerLicencing,
|
||||
listing.internalListingNumber, listing.realEstateIncluded, listing.franchiseResale,
|
||||
listing.draft, listing.internals, listing.created, new Date(), 0, null
|
||||
];
|
||||
const json_values = [
|
||||
listing.id, listing
|
||||
]
|
||||
|
||||
await pool.query(`INSERT INTO businesses
|
||||
(user_id, listings_category, title, description, type, state, city, id, price, sales_revenue, leased_location,
|
||||
established, employees, reason_for_sale, support_and_training, cash_flow, broker_licencing, internal_listing_number,
|
||||
real_estate_included, franchise_resale, draft, internals, created, updated, visits, last_visit)
|
||||
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21, $22, $23, $24, $25, $26)`, values);
|
||||
|
||||
await pool.query('INSERT INTO businesses_json (id, data) VALUES ($1,$2)', json_values);
|
||||
|
||||
// out.push(listing);
|
||||
}
|
||||
writeJsonSync('./data/businesses_.json',out);
|
||||
console.log('All data imported successfully.');
|
||||
} catch (err) {
|
||||
console.error('Error importing data:', err.message);
|
||||
} finally {
|
||||
// Schließen der Verbindung zum Pool
|
||||
await pool.end();
|
||||
}
|
||||
}
|
||||
|
||||
// Passen Sie den Dateipfad an Ihre spezifischen Bedürfnisse an
|
||||
importJsonData('./data/businesses_.json');
|
||||
Reference in New Issue
Block a user