From 7c557e93d35644e1692d0a1d03dc26b6eca81157 Mon Sep 17 00:00:00 2001 From: Colin Diem Date: Tue, 21 Jun 2022 17:01:07 -0400 Subject: [PATCH] Still tinkering with how to make it work. --- costar.js | 4 +- index.html | 2 +- main.js | 187 ++++++++++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 187 insertions(+), 6 deletions(-) diff --git a/costar.js b/costar.js index 16fe7dc..00d0516 100644 --- a/costar.js +++ b/costar.js @@ -1,6 +1,4 @@ -const csvToJson = require('csvtojson'); -const { Parser } = require('json2csv'); -const fs = require('fs'); + function formatPhoneNumber(phoneNumber){ if (phoneNumber.length > 0){ diff --git a/index.html b/index.html index e803d3e..32ce99c 100644 --- a/index.html +++ b/index.html @@ -15,7 +15,7 @@ Chromium , and Electron . - + diff --git a/main.js b/main.js index 4fc4e73..a18eb3f 100644 --- a/main.js +++ b/main.js @@ -1,7 +1,9 @@ // Modules to control application life and create native browser window -const {app, BrowserWindow} = require('electron') +const {app, BrowserWindow, Menu} = require('electron') const path = require('path') -const costar = require('./costar'); +const csvToJson = require('csvtojson'); +const { Parser } = require('json2csv'); +const fs = require('fs'); function createWindow () { // Create the browser window. @@ -31,6 +33,14 @@ app.whenReady().then(() => { // dock icon is clicked and there are no other windows open. if (BrowserWindow.getAllWindows().length === 0) createWindow() }) + + // Enable dev tools + + document.getElementById('ingestBtn').addEventListener('click', processFiles()); + + // Create a custom application menu + // const mainMenu = Menu.buildFromTemplate(mainMenuTemplate); + // Menu.setApplicationMenu(mainMenu); }) // Quit when all windows are closed, except on macOS. There, it's common @@ -42,3 +52,176 @@ app.on('window-all-closed', function () { // In this file you can include the rest of your app's specific main process // code. You can also put them in separate files and require them here. + +const mainMenuTemplate = [ + { + label: 'Example' + } +] + +function formatPhoneNumber(phoneNumber){ + if (phoneNumber.length > 0){ + return `(${phoneNumber.slice(0, 3)}) ${phoneNumber.slice(3, 6)}-${phoneNumber.slice(6)}`; + } + return phoneNumber; +} + +function addQuotes(value){ + if (value.includes(',')){ + return `"${value}"`; + } + return value; +} + +function addCommaToNumber(value){ + for(var i = value.length; i > 0; i = i - 3){ + value = `${value.slice(0, i)},${value.slice(i)}`; + } + return value.slice(0, value.length - 1); +} + +function removeExtraZipCode(value){ + var pieces = value.split('-'); + return pieces[0]; +} + +function processOwnerFile(){ + csvToJson({ + noheader: false, + headers: [ + 'PropertyAddress', + 'PropertyName', + 'RBA', + 'City', + 'State', + 'Zip', + 'CountyName', + 'LandAreaAC', + 'ParcelNumber1', + 'PropertyType', + 'TrueOwnerAddress', + 'TrueOwnerCityStateZip', + 'TrueOwnerContact', + 'TrueOwnerName', + 'TrueOwnerPhone', + 'SecondaryType', + 'OwnerName', + 'OwnerPhone' + ] + }).fromFile('./data/i96.csv').then((jsonObj) => { + let data = jsonObj.map((x) => { + let y = {}; + y['Description Address L Name'] = `${x.PropertyAddress} ${x.City} ${x.State} ${x.Zip.slice(0, 5)}`; + y['Property Address L Custom Building Address'] = `${x.PropertyAddress} ${x.City} ${x.State} ${x.Zip.slice(0, 5)}`; + y['Property Name L Custom Property Name'] = addQuotes(x.PropertyName); + y['RBA L Custom SF Building'] = addQuotes(addCommaToNumber(x.RBA)); + y['Property Address P'] = x.PropertyAddress; + y['City P'] = x.City; + y['State P'] = x.State; + y['No Zip'] = x.Zip; + y['Zip P'] = x.Zip.slice(0, 5); + y['County Name C Territory'] = `${x.CountyName} County`; + y['Land Area (AC) L Custom'] = x.LandAreaAC; + y['Parcel Number L Custom'] = x.ParcelNumber1; + y['Property Type L Tag'] = 'Industrial'; + y['True Owner Address C Address: Main Address 1 Full Adress'] = addQuotes(x.TrueOwnerAddress); + y['True Owner City State Zip C Address: Main City'] = x.TrueOwnerCityStateZip.length > 0 ? addQuotes(`${removeExtraZipCode(x.TrueOwnerCityStateZip)}`): x.TrueOwnerCityStateZip; + y['True Owner Contact P Full Name'] = addQuotes(x.TrueOwnerContact); + y['True Owner Name L Custom True Owner'] = addQuotes(x.TrueOwnerName); + y['True Owner Phone P Work'] = formatPhoneNumber(x.TrueOwnerPhone); + y['Secondary Type L Custom'] = addQuotes(x.SecondaryType); + y['Owner Name L Custom Owners Name'] = ''; + y['Owner Phone L owner Phone'] = ''; + y['Owner Name Name C Name'] = x.TrueOwnerName.length > 0 ? addQuotes(x.TrueOwnerName): addQuotes(x.OwnerName); + y['Assignee L Assignee'] = 'EJR'; + y['C Tag Industrial'] = 'Industrial'; + y['Market Area L Custom'] = 'Central I-96 Corridor'; + y['Owner C Tag'] = 'Owner'; + y['Status L'] = 'Pending'; + y['C Description'] = 'Owner'; + + return y; + }); + fs.writeFileSync('./data/result.json', JSON.stringify(data, null, 2)); + const parser = new Parser({ + quote: '', + }); + const csv = parser.parse(data); + // console.log(csv); + fs.writeFileSync('./data/result.csv', csv); + }); +} + +function processTenantFile(){ + csvToJson({ + noheader: false, + headers: [ + 'FullName', + 'LastName', + 'FirstName', + 'Title', + 'CompanyName', + 'Phone', + 'Address', + 'Suite', + 'City', + 'State', + 'Zip', + 'TenantWebAddress', + 'Zip4', + 'TenantSICDescription', + 'TenantSFOccupied', + 'TenantLocation', + 'TenantEmp', + 'TenPhone', + 'MoveDate', + 'MailingAddressAddress', + 'MailingAddressCity', + 'MailingAddressState', + 'MailingAddressZip' + ] + }).fromFile('./data/i96tenant.csv').then(jsonObj => { + let data = jsonObj.map(x => { + let y = {}; + y['Full Name P Name Full Name'] = x.FullName; + y['Last Name'] = x.LastName; + y['First Name'] = x.FirstName; + y['Title P Job Title'] = x.Title; + y['Company Name C Name'] = addQuotes(x.CompanyName); + y['Phone P Phone Work'] = x.Phone; + y['Address C Address: Main Address 1'] = x.Address; + y['Suite C Address: Other Adress 2'] = x.Suite; + y['City C City'] = x.City; + y['State C State'] = x.State; + y['Zip C Zip'] = x.Zip; + y['Tenant: Web Address C URL'] = x.TenantWebAddress; + y['Tenant: SIC Description C SIC Description'] = addQuotes(x.TenantSICDescription); + y['Tenant: SF Occupied C Custom SF Occupied'] = x.TenantSFOccupied; + y['Tenant: Location C Custom Location Type'] = x.TenantLocation; + y['Tenant: # Emp C Custom Employee Count'] = x.TenantEmp; + y['Ten_Phone C Phone work'] = x.TenPhone; + y['Move Date C Custom Move Date'] = x.MoveDate; + y['Mailing Address: Address P Address: Main Address 1'] = x.MailingAddressAddress; + y['Mailing Address: City P Address: Main City'] = x.MailingAddressCity; + y['Mailing Address: State P Address: Main State'] = x.MailingAddressState; + y['Mailing Address: Zip P Address: Main State'] = x.MailingAddressZip; + y['C Tag'] = `"Industrial", "Tenant"`; + y['C Description'] = 'Tenant'; + + return y; + }); + fs.writeFileSync('./data/tenant_result.json', JSON.stringify(data, null, 2)); + const parser = new Parser({ + quote: '', + }); + const csv = parser.parse(data); + // console.log(csv); + fs.writeFileSync('./data/tenant_result.csv', csv); + }) +} + +function processFiles(){ + console.log('Yo.'); + processOwnerFile(); + processTenantFile(); +}