Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 4

setwd("d:/data/fiverr/shadabchow1/")

sample <- read.csv("Sample_BigCommerce.csv",header = F,stringsAsFactors = F,


na.strings=c("","NA"))

df <- read.csv("everdresses 19k-3 - everdresses 19k-3.csv", header = T,


stringsAsFactors = F, na.strings=c("","NA"))
#dt <- df[complete.cases(df), ]

#"Item Type", "Product ID", "Product Name", "Product Type", "Product


Code/SKU", "Bin Picking Number",
#"Brand Name", "Option Set", "Option Set Align", "Product Description",
"Price", "Cost Price", "Retail Price",
#"Sale Price", "Fixed Shipping Cost", "Free Shipping", "Product Warranty",
"Product Weight"," Product Width",
#"Product Height", "Product Depth", "Allow Purchases?", "Product
Visible?", "Product Availability",
#"Track Inventory", "Current Stock Level", "Low Stock Level", "Category",
#"Product Image File - 1", "Product Image Description - 1", "Product Image Is
Thumbnail - 1", "Product Image Sort - 1",
#"Product Image ID - 2", "Product Image File - 2", "Product Image
Description - 2", "Product Image Is Thumbnail - 2", "Product Image Sort - 2",
#"Product Image ID - 3", "Product Image File - 3", "Product Image
Description - 3", "Product Image Is Thumbnail - 3", "Product Image Sort - 3",
#"Product Image ID - 4", "Product Image File - 4", "Product Image
Description - 4", "Product Image Is Thumbnail - 4", "Product Image Sort - 4",
#"Product Image ID - 5", "Product Image File - 5", "Product Image
Description - 5", "Product Image Is Thumbnail - 5", "Product Image Sort - 5",
#"Search Keywords", "Page Title", "Meta Keywords", "Meta Description",
"Product Condition", "Show Product Condition?",
#"Sort Order", "Product Tax Class", "Product UPC/EAN", "Stop Processing
Rules", "Product URL", "Redirect Old URL?",
#"GPS Global Trade Item Number", "GPS Manufacturer Part Number", "GPS
Gender", "GPS Age Group", "GPS Color",
#"GPS Size", "GPS Material", "GPS Pattern", "GPS Item Group ID", "GPS
Category", "GPS Enabled", "Tax Provider Tax Code",
#"Product Custom Fields"

#dt <- df[,c(2:4)]

column_names <- c("Title","Content","Excerpt","Price","Image.URL")

dt <- df[,c(column_names)]
#dt <- df[complete.cases(df[ , 1:2]),]

library(dplyr)
dt <- dt %>%
mutate(Title= ifelse(is.na(Content),Excerpt,Title))

dt$Title <- gsub("color:","[CS]Color=",dt$Title)


dt$Title <- gsub("size:","[RT]Size=",dt$Title)
dt$Excerpt <- NULL

# changing Images into multiple


dt2 <- splitstackshape::cSplit(dt, "Image.URL", sep="||")
dt2[, ] <- lapply(dt2[, ], as.character)

#dt2$Image.URL_1<- as.character(dt2$Image.URL_1)

names(dt2)

trimws(sapply(regmatches(dt2$Image.URL_1, gregexpr("/http[a-zA-Z].*$",
dt2$Image.URL_1)), paste, collapse = ""))

length(dt2)-length(dt)

as.numeric(dt$Price)*1.5

#dt$Title[1:10] <- sapply(regmatches(dt$Title, gregexpr("- [a-zA-Z]+,.*$",


dt$Title)), paste, collapse = "")

#dt$Name <- trimws(sapply(regmatches(dt$Title, gregexpr("- [a-zA-Z].*$", dt$Title),


invert = TRUE), paste, collapse = ""))

#trimws(sapply(regmatches(dt$Title[4], gregexpr("- [a-zA-Z]+,.*$", dt$Title[4]),


invert = TRUE), paste, collapse = ""))

dt$Product_SKU<- paste0("SDWS-",as.numeric(as.POSIXct(strptime(Sys.time(), "%Y-%m-


%d"))), row.names(dt))

dt <- dt[,c(1:162,164,163)]

dt$Name <- gsub("A-Line", "A_Line", dt$Name)


dt$Name <- gsub("A-line", "A_Line", dt$Name)
dt$Name <- gsub("a-line", "A_Line", dt$Name)
dt$Name <- gsub("a-Line", "A_Line", dt$Name)

dt$Name <- gsub("A-LINE", "A_Line", dt$Name)


dt$Name <- gsub("A-LINE", "A_Line", dt$Name)
dt$Name <- gsub("a-LINE", "A_Line", dt$Name)
dt$Name <- gsub("a-LINE", "A_Line", dt$Name)

dt$Name <- gsub("V-Neck", "V_Neck", dt$Name)


dt$Name <- gsub("v-Neck", "V_Neck", dt$Name)
dt$Name <- gsub("v-neck", "V_Neck", dt$Name)
dt$Name <- gsub("v-ncck", "V_Neck", dt$Name)
dt$Name <- gsub("V-neck", "V_Neck", dt$Name)
dt$Name <- gsub("O-Neck", "O_Neck", dt$Name)
dt$Name <- gsub("O-neck", "O_Neck", dt$Name)
dt$Name <- gsub("o-Neck", "O_Neck", dt$Name)
dt$Name <- gsub("o-neck", "O_Neck", dt$Name)

dt$Name <- gsub("E-girl", "girl", dt$Name)


dt$Name <- gsub("E-girl", "E_girl", dt$Name)
dt$Name <- gsub("e-girl", "E_girl", dt$Name)
dt$Name <- gsub("e-girl", "E_girl", dt$Name)
dt$Name <- gsub("Button-Up", "Button_Up", dt$Name)
dt$Name <- gsub("Button-up", "Button_Up", dt$Name)
dt$Name <- gsub("button-Up", "Button_Up", dt$Name)
dt$Name <- gsub("button-up", "Button_Up", dt$Name)

dt$Name <- gsub("Low-Cut", "Low_Cut", dt$Name)


dt$Name <- gsub("Low-cut", "Low_Cut", dt$Name)
dt$Name <- gsub("low-Cut", "Low_Cut", dt$Name)
dt$Name <- gsub("low-cut", "Low_Cut", dt$Name)

dt$Name <- gsub("E-Neck", "E_Neck", dt$Name)


dt$Name <- gsub("e-neck", "E_Neck", dt$Name)
dt$Name <- gsub("e-neck", "E_Neck", dt$Name)

dt$Name <- gsub("Single-Breasted", "Single_Breasted", dt$Name)


dt$Name <- gsub("Single-breasted", "Single_Breasted", dt$Name)
dt$Name <- gsub("single-Breasted", "Single_Breasted", dt$Name)
dt$Name <- gsub("single-breasted", "Single_Breasted", dt$Name)

dt$Name <- gsub("Turn-Down", "Turn_down", dt$Name)


dt$Name <- gsub("Turn-down", "Turn_down", dt$Name)
dt$Name <- gsub("Calf-length", "Calf_length", dt$Name)
dt$Name <- gsub("Calf-Length", "Calf_length", dt$Name)
dt$Name <- gsub("calf-length", "Calf_length", dt$Name)
dt$Name <- gsub("Mid-Length", "Mid_Length", dt$Name)
dt$Name <- gsub("mid-Length", "Mid_Length", dt$Name)
dt$Name <- gsub("Mid-length", "Mid_Length", dt$Name)
dt$Name <- gsub("mid-length", "Mid_Length", dt$Name)

dt$Name <- gsub("Mid-Calf", "Mid_Calf", dt$Name)


dt$Name <- gsub("Mid-calf", "Mid_Calf", dt$Name)
dt$Name <- gsub("mid-Calf", "Mid_Calf", dt$Name)
dt$Name <- gsub("mid-calf", "Mid_Calf", dt$Name)

dt$Name <- gsub("See-Through", "See_Through", dt$Name)


dt$Name <- gsub("See-through", "See_Through", dt$Name)
dt$Name <- gsub("see-Through", "See_Through", dt$Name)
dt$Name <- gsub("see-through", "See_Through", dt$Name)

dt$Name <- gsub("Short-Sleeved", "Short_Sleeved", dt$Name)


dt$Name <- gsub("Short-sleeved", "Short_Sleeved", dt$Name)
dt$Name <- gsub("short-Sleeved", "Short_Sleeved", dt$Name)
dt$Name <- gsub("short-sleeved", "Short_Sleeved", dt$Name)

dt$Name <- gsub("S-XL", "S_XL", dt$Name)

openxlsx::write.xlsx(dt, file = "everdresses 19k-3 - everdresses 19k-3_v1.xlsx",


colNames = TRUE)

setwd("D:/R/convert")
name <- list.files(".", "*.csv", full.names = F, recursive = F)

You might also like