mirror of
https://gitea.gofwd.group/dstrawsb/ballistic-builder.git
synced 2025-12-06 02:36:44 -05:00
csv import
This commit is contained in:
@@ -1,28 +0,0 @@
|
||||
import { sectionLinks } from "../../lib/linkList/sectionLinks";
|
||||
import Link from "next/link";
|
||||
import armoryLinks from "../../lib/linkList/sectionLinks";
|
||||
|
||||
let linksArray = [
|
||||
sectionLinks.UPPERS,
|
||||
sectionLinks.LOWERS,
|
||||
sectionLinks.BARRELS,
|
||||
sectionLinks.OPTICS,
|
||||
sectionLinks.ACCESSORIES,
|
||||
];
|
||||
export const Armory = (props:any) => {
|
||||
return (
|
||||
(<div>
|
||||
<h4>{props.titleText}</h4>
|
||||
<ul>
|
||||
{linksArray.map((link, index) => (
|
||||
<li key={index}>
|
||||
<Link href={link.URL} legacyBehavior>
|
||||
{link.TEXT}
|
||||
</Link>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
</div>)
|
||||
);
|
||||
}
|
||||
export default Armory;
|
||||
@@ -1,23 +0,0 @@
|
||||
{
|
||||
"name": "armory",
|
||||
"version": "0.0.0",
|
||||
"private": true,
|
||||
"main": "./index",
|
||||
"author": {
|
||||
"name": "Sean Strawsburg",
|
||||
"email": "sean@goforward.group",
|
||||
"url": "https://goforward.group/"
|
||||
},
|
||||
"contributors": [
|
||||
{
|
||||
"name": "Don Strawsburg",
|
||||
"email": "don@goforward.group",
|
||||
"url": "https://goforward.group/"
|
||||
},
|
||||
{
|
||||
"name": "Sean Strawsburg",
|
||||
"email": "sean@goforward.group",
|
||||
"url": "https://goforward.group/"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
@import '../../scss/variables.scss';
|
||||
@@ -1,38 +0,0 @@
|
||||
import React from 'react';
|
||||
|
||||
import styles from './style.module.scss'
|
||||
|
||||
const Button = ({
|
||||
children,
|
||||
className,
|
||||
color = 'black',
|
||||
type = 'button',
|
||||
...props
|
||||
}) => (
|
||||
<button
|
||||
className={`${className} Button Button_${color}`}
|
||||
type={type}
|
||||
{...props}
|
||||
>
|
||||
{children}
|
||||
</button>
|
||||
);
|
||||
|
||||
const ButtonUnobtrusive = ({
|
||||
children,
|
||||
className,
|
||||
type = 'button',
|
||||
...props
|
||||
}) => (
|
||||
<button
|
||||
className={`${className} Button_unobtrusive`}
|
||||
type={type}
|
||||
{...props}
|
||||
>
|
||||
{children}
|
||||
</button>
|
||||
);
|
||||
|
||||
export { ButtonUnobtrusive };
|
||||
|
||||
export default Button;
|
||||
@@ -1,23 +0,0 @@
|
||||
{
|
||||
"name": "button",
|
||||
"version": "0.0.0",
|
||||
"private": true,
|
||||
"main": "./index",
|
||||
"author": {
|
||||
"name": "Sean Strawsburg",
|
||||
"email": "sean@goforward.group",
|
||||
"url": "https://goforward.group/"
|
||||
},
|
||||
"contributors": [
|
||||
{
|
||||
"name": "Don Strawsburg",
|
||||
"email": "don@goforward.group",
|
||||
"url": "https://goforward.group/"
|
||||
},
|
||||
{
|
||||
"name": "Sean Strawsburg",
|
||||
"email": "sean@goforward.group",
|
||||
"url": "https://goforward.group/"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -1,46 +0,0 @@
|
||||
.Button {
|
||||
padding: 10px;
|
||||
background: none;
|
||||
cursor: pointer;
|
||||
transition: color 0.25s ease-in-out;
|
||||
transition: background 0.25s ease-in-out;
|
||||
}
|
||||
|
||||
.Button_white {
|
||||
border: 1px solid #fff;
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
.Button_white:hover {
|
||||
color: #000;
|
||||
background: #fff;
|
||||
}
|
||||
|
||||
.Button_black {
|
||||
border: 1px solid #000;
|
||||
color: #000;
|
||||
}
|
||||
|
||||
.Button_black:hover {
|
||||
color: #fff;
|
||||
background: #000;
|
||||
}
|
||||
|
||||
.Button_unobtrusive {
|
||||
padding: 0;
|
||||
color: #000;
|
||||
background: none;
|
||||
border: none;
|
||||
cursor: pointer;
|
||||
opacity: 1;
|
||||
transition: opacity 0.25s ease-in-out;
|
||||
outline: none;
|
||||
}
|
||||
|
||||
.Button_unobtrusive:hover {
|
||||
opacity: 0.35;
|
||||
}
|
||||
|
||||
.Button_unobtrusive:focus {
|
||||
outline: none;
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
import React from 'react';
|
||||
|
||||
import styles from './style.module.css';
|
||||
|
||||
const ErrorMessage = ({ error }) => (
|
||||
<div className="ErrorMessage">
|
||||
<small>{error.toString()}</small>
|
||||
</div>
|
||||
);
|
||||
|
||||
export default ErrorMessage;
|
||||
@@ -1,23 +0,0 @@
|
||||
{
|
||||
"name": "error",
|
||||
"version": "0.0.0",
|
||||
"private": true,
|
||||
"main": "./index",
|
||||
"author": {
|
||||
"name": "Sean Strawsburg",
|
||||
"email": "sean@goforward.group",
|
||||
"url": "https://goforward.group/"
|
||||
},
|
||||
"contributors": [
|
||||
{
|
||||
"name": "Don Strawsburg",
|
||||
"email": "don@goforward.group",
|
||||
"url": "https://goforward.group/"
|
||||
},
|
||||
{
|
||||
"name": "Sean Strawsburg",
|
||||
"email": "sean@goforward.group",
|
||||
"url": "https://goforward.group/"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
.ErrorMessage {
|
||||
margin: 20px;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
import { sectionLinks } from "@/app/lib/linkList/sectionLinks";
|
||||
import Link from "next/link";
|
||||
|
||||
let linksArray = [
|
||||
sectionLinks.BLOG,
|
||||
sectionLinks.PRICEDROPS,
|
||||
sectionLinks.BUILDS,
|
||||
sectionLinks.BUILDGUIDES,
|
||||
];
|
||||
|
||||
export const GroundZero = (props) => {
|
||||
return (
|
||||
(<div>
|
||||
<h4>{props.titleText}</h4>
|
||||
<ul>
|
||||
{linksArray.map((link, index) => (
|
||||
<li key={index}>
|
||||
<Link href={link.URL} legacyBehavior>
|
||||
{link.TEXT}
|
||||
</Link>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
</div>)
|
||||
);
|
||||
}
|
||||
export default GroundZero;
|
||||
@@ -1 +0,0 @@
|
||||
@import '../../scss/variables.scss';
|
||||
@@ -1,27 +0,0 @@
|
||||
import { infoLinks } from "@/app/lib/linkList/infoLinks";
|
||||
import Link from "next/link";
|
||||
let linksArray = [
|
||||
infoLinks.ABOUT,
|
||||
infoLinks.FAQ,
|
||||
infoLinks.DISCLOSURE,
|
||||
infoLinks.PRIVACYPOLICY,
|
||||
infoLinks.PIP,
|
||||
infoLinks.TOS
|
||||
];
|
||||
export const Information = (props) => {
|
||||
return (
|
||||
(<div>
|
||||
<h4>{props.titleText}</h4>
|
||||
<ul>
|
||||
{linksArray.map((link, index) => (
|
||||
<li key={index}>
|
||||
<Link href={link.URL} legacyBehavior>
|
||||
{link.TEXT}
|
||||
</Link>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
</div>)
|
||||
);
|
||||
}
|
||||
export default Information;
|
||||
@@ -1,23 +0,0 @@
|
||||
{
|
||||
"name": "information",
|
||||
"version": "0.0.0",
|
||||
"private": true,
|
||||
"main": "./index",
|
||||
"author": {
|
||||
"name": "Sean Strawsburg",
|
||||
"email": "sean@goforward.group",
|
||||
"url": "https://goforward.group/"
|
||||
},
|
||||
"contributors": [
|
||||
{
|
||||
"name": "Don Strawsburg",
|
||||
"email": "don@goforward.group",
|
||||
"url": "https://goforward.group/"
|
||||
},
|
||||
{
|
||||
"name": "Sean Strawsburg",
|
||||
"email": "sean@goforward.group",
|
||||
"url": "https://goforward.group/"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
@import '../../scss/variables.scss';
|
||||
@@ -1,5 +1,6 @@
|
||||
import { getMags } from "@queries/PSA";
|
||||
import styles from '../styles.module.css';
|
||||
import PageHero from "@components/PageHero";
|
||||
import SortTable from "@components/SortTable";
|
||||
|
||||
export const metadata = {
|
||||
@@ -13,6 +14,7 @@ export default async function MagsPage() {
|
||||
|
||||
return (
|
||||
<div>
|
||||
<PageHero title="Magazines" />
|
||||
<div className="container mx-auto">
|
||||
<SortTable data={data}></SortTable>
|
||||
</div>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { getMuzzleDevices } from "@queries/PSA";
|
||||
import styles from '../styles.module.css';
|
||||
import PageHero from "@components/PageHero";
|
||||
|
||||
import SortTable from "@components/SortTable";
|
||||
|
||||
export default async function MuzzleDevices() {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import "../styles/globals.css";
|
||||
import Navbar from "../components/Navbar";
|
||||
import "@styles/globals.css";
|
||||
import Navbar from "@components/Navbar";
|
||||
import PopNav from "@components/PopNav/page";
|
||||
import { Roboto } from 'next/font/google'
|
||||
import constants from "@src/lib/constants";
|
||||
|
||||
@@ -188,6 +188,44 @@ export const builds = pgTable("builds", {
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
export const bb_products = pgTable("bb_products", {
|
||||
uuid: uuid().defaultRandom().primaryKey().notNull(),
|
||||
upc: varchar("UPC", { length: 100 }),
|
||||
sku: varchar("SKU", { length: 50 }),
|
||||
manufacturerId: varchar("MANUFACTURER_ID", { length: 50 }),
|
||||
brandName: varchar("BRAND_NAME", { length: 50 }),
|
||||
productName: varchar("PRODUCT_NAME", { length: 255 }),
|
||||
longDescription: text("LONG_DESCRIPTION"),
|
||||
shortDescription: varchar("SHORT_DESCRIPTION", { length: 500 }),
|
||||
department: varchar("DEPARTMENT", { length: 100 }),
|
||||
category: varchar("CATEGORY", { length: 100 }),
|
||||
subcategory: varchar("SUBCATEGORY", { length: 100 }),
|
||||
thumbUrl: varchar("THUMB_URL", { length: 500 }),
|
||||
imageUrl: varchar("IMAGE_URL", { length: 500 }),
|
||||
buyLink: varchar("BUY_LINK", { length: 500 }),
|
||||
keywords: varchar("KEYWORDS", { length: 500 }),
|
||||
reviews: varchar("REVIEWS", { length: 500 }),
|
||||
retailPrice: varchar("RETAIL_PRICE", { length: 50 }),
|
||||
salePrice: varchar("SALE_PRICE", { length: 50 }),
|
||||
brandPageLink: varchar("BRAND_PAGE_LINK", { length: 500 }),
|
||||
brandLogoImage: varchar("BRAND_LOGO_IMAGE", { length: 500 }),
|
||||
productPageViewTracking: varchar("PRODUCT_PAGE_VIEW_TRACKING", { length: 500 }),
|
||||
parentGroupId: varchar("PARENT_GROUP_ID", { length: 200 }),
|
||||
fineline: varchar("FINELINE", { length: 200 }),
|
||||
superfineline: varchar("SUPERFINELINE", { length: 200 }),
|
||||
modelnumber: varchar("MODELNUMBER", { length: 100 }),
|
||||
caliber: varchar("CALIBER", { length: 200 }),
|
||||
mediumImageUrl: varchar("MEDIUM_IMAGE_URL", { length: 500 }),
|
||||
productContentWidget: varchar("PRODUCT_CONTENT_WIDGET", { length: 500 }),
|
||||
googleCategorization: varchar("GOOGLE_CATEGORIZATION", { length: 500 }),
|
||||
itemBasedCommission: varchar("ITEM_BASED_COMMISSION", { length: 500 }),
|
||||
itemBasedCommissionRate: varchar("ITEM_BASED_COMMISSION RATE", { length: 50 }),
|
||||
updatedAt: timestamp("updated_at", { mode: 'string' }).defaultNow().notNull(),
|
||||
createdAt: timestamp("created_at", { mode: 'string' }).defaultNow().notNull(),
|
||||
deletedAt: timestamp("deleted_at", { mode: 'string' }),
|
||||
});
|
||||
|
||||
export const psa_old = pgTable("psa_old", {
|
||||
sku: varchar("SKU", { length: 50 }),
|
||||
manufacturerId: varchar("MANUFACTURER_ID", { length: 50 }),
|
||||
|
||||
9791
src/lib/dataImports/Brownells_cleaned.csv
Normal file
9791
src/lib/dataImports/Brownells_cleaned.csv
Normal file
File diff suppressed because it is too large
Load Diff
101
src/lib/dataImports/csvParse.ts
Normal file
101
src/lib/dataImports/csvParse.ts
Normal file
@@ -0,0 +1,101 @@
|
||||
import * as fs from "fs";
|
||||
import * as path from "path";
|
||||
import { parse } from 'csv-parse';
|
||||
import { bb_products } from "/home/don/code/ballistics-builder/src/drizzle/schema/schema";
|
||||
import { db } from '/home/don/code/ballistics-builder/src/db/index';
|
||||
|
||||
type BB_PRODUCTS = {
|
||||
UPC: string;
|
||||
SKU: string;
|
||||
'Manufacturer Id': string;
|
||||
"Brand Name": string;
|
||||
'Product Name': string;
|
||||
'Long Description': string;
|
||||
'Short Description': string;
|
||||
Department: string;
|
||||
Category: string;
|
||||
SubCategory: string;
|
||||
'Thumb URL': string;
|
||||
'Image URL': string;
|
||||
'Buy Link': string;
|
||||
Keywords: string;
|
||||
Reviews: string;
|
||||
'Retail Price': string;
|
||||
'Sale Price': string;
|
||||
'Brand Page Link': string;
|
||||
'Brand Logo Image': string;
|
||||
'Product Page View Tracking': string;
|
||||
'Parent Group ID': string;
|
||||
Color: string;
|
||||
Size: string;
|
||||
Pattern: string;
|
||||
Material: string;
|
||||
'Age Group': string;
|
||||
Gender: string;
|
||||
Availability: string;
|
||||
'Google Product Category': string;
|
||||
'Medium Image URL': string;
|
||||
'Variants XML': string;
|
||||
GTIN: string;
|
||||
'Key Words': string;
|
||||
'Product Content Widget': string;
|
||||
'Google Categorization': string;
|
||||
'Item Based Commission': string;
|
||||
'Item Based Commission Rate': string;
|
||||
|
||||
};
|
||||
|
||||
(() => {
|
||||
const csvFilePath = path.resolve(__dirname, '/home/don/code/ballistics-builder/src/lib/dataImports/Brownells_cleaned.csv');
|
||||
|
||||
const headers = ['SKU', 'Manufacturer Id', 'Brand Name', 'Product Name', 'Long Description', 'Short Description', 'Department', 'Category', 'SubCategory', 'Thumb URL', 'Image URL', 'Buy Link', 'Keywords', 'Reviews', 'Retail Price', 'Sale Price', 'Brand Page Link', 'Brand Logo Image', 'Product Page View Tracking', 'Parent Group ID', 'Color', 'Size', 'Pattern', 'Material', 'Age Group', 'Gender', 'UPC', 'Availability', 'Google Product Category', 'Medium Image URL', 'Variants XML', 'GTIN', 'Key Words', 'Product Content Widget', 'Google Categorization', 'Item Based Commission', 'Item Based Commission Rate', 'Item Based Commission Rule'
|
||||
];
|
||||
|
||||
const fileContent = fs.readFileSync(csvFilePath, { encoding: 'utf-8' });
|
||||
let rows: BB_PRODUCTS[] = [];
|
||||
|
||||
parse(fileContent, {
|
||||
delimiter: ',',
|
||||
columns: headers,
|
||||
from_line: 2,
|
||||
}, (error, result: BB_PRODUCTS[]) => {
|
||||
if (error) {
|
||||
console.error(error);
|
||||
}
|
||||
|
||||
// Insert data into the database
|
||||
for (const row of result) {
|
||||
db.insert(bb_products).values({
|
||||
|
||||
upc: row["UPC"],
|
||||
sku: row.SKU,
|
||||
brandName: row["Brand Name"],
|
||||
productName: row["Product Name"],
|
||||
longDescription: row["Long Description"],
|
||||
shortDescription: row["Short Description"],
|
||||
department: row.Department,
|
||||
category: row.Category,
|
||||
subcategory: row.SubCategory,
|
||||
thumbUrl: row["Thumb URL"],
|
||||
imageUrl: row["Image URL"],
|
||||
buyLink: row["Buy Link"],
|
||||
keywords: row.Keywords,
|
||||
reviews: row.Reviews,
|
||||
retailPrice: row["Retail Price"],
|
||||
salePrice: row["Sale Price"],
|
||||
brandPageLink: row["Brand Page Link"],
|
||||
brandLogoImage: row["Brand Logo Image"],
|
||||
productPageViewTracking: row["Product Page View Tracking"],
|
||||
parentGroupId: row["Parent Group ID"],
|
||||
mediumImageUrl: row["Medium Image URL"],
|
||||
productContentWidget: row["Product Content Widget"],
|
||||
googleCategorization: row["Google Categorization"],
|
||||
itemBasedCommission: row["Item Based Commission"],
|
||||
itemBasedCommissionRate: row["Item Based Commission Rate"]
|
||||
|
||||
|
||||
// ...other fields from the CSV row...
|
||||
}).execute();
|
||||
}
|
||||
});
|
||||
})();
|
||||
Reference in New Issue
Block a user