Last active
December 17, 2015 05:19
-
-
Save qcom/5557172 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Program | |
{ | |
static string connString = "Data Source=ZACH7-PC;Initial Catalog=Products;Integrated Security=True"; | |
static string query = String.Empty; | |
static string header = "TemplateType=HomeImprovement Version=2012.0913 This row for Amazon.com use only. Do not modify or delete. Offer Information - These attributes are required to make your item buyable for customers on the site "; | |
static string schema = "sku,standard-product-id,product-id-type,product-name,brand,manufacturer,manufacturer-part-number,merchant-catalog-number,bullet-point1,bullet-point2,bullet-point3,bullet-point4,bullet-point5,description,product_type,item-price,currency,condition-type,condition-note,quantity,msrp,map,launch-date,release-date,leadtime-to-ship,restock-date,max-aggregate-ship-quantity,product-tax-code,warranty-type,seller-warranty-description,prop-65,cpsia-warning1,cpsia-warning2,cpsia-warning3,cpsia-warning4,cpsia-warning-description,sale-price,sale-start-date,sale-end-date,item-type,used-for1,used-for2,used-for3,used-for4,used-for5,target-audience1,target-audience2,target-audience3,other-item-attributes1,other-item-attributes2,other-item-attributes3,other-item-attributes4,other-item-attributes5,subject-content1,subject-content2,subject-content3,subject-content4,subject-content5,search-terms1,search-terms2,search-terms3,search-terms4,search-terms5,platinum-keywords1,platinum-keywords2,platinum-keywords3,platinum-keywords4,platinum-keywords5,main-image-url,swatch-image-url,other-image-url1,other-image-url2,other-image-url3,other-image-url4,other-image-url5,other-image-url6,other-image-url7,other-image-url8,parentage,parent-sku,relationship-type,variation-theme,size,color,color-map,style,finish,material,pattern,shape,thickness,thickness-unit-of-measure,horsepower,power-source,voltage,wattage,amperage-capacity ,included-components1,included-components2,included-components3,item-package-quantity,special-features1,special-features2,special-features3,special-features4,special-features5,usage,temperature-range,temperature-range-unit-of-measure,flow-rate,flow-rate-unit-of-measure,water-consumption ,water-consumption-unit-of-measure,installation-method,air-flow-capacity ,maximum-weight-capacity ,maximum-weight-capacity-unit-of-measure,maximum-pressure,capacity-description,sound-level,sound-level-unit-of-measure,number-of-pieces,extension-length,extension-length-unit-of-measure,hose-length,hose-length-unit-of-measure,cord-length,cord-length-unit-of-measure,handle-lever-placement,number-of-handles,certification1,certification2,certification3,head-style,center-length,center-length-unit-of-measure,bulb-type,brightness,minimum-efficiency-reporting-values ,number-of-basins,number-of-holes,spout-height,spout-height-unit-of-measure,spout-reach,spout-reach-unit-of-measure,flush-type,rough-in,rough-in-unit-of-measure,inside-diameter,inside-diameter-unit-of-measure,outside-diameter,outside-diameter-unit-of-measure,thread-size,handle-material,blade-length,blade-length-unit-of-measure,folded-knife-size,blade-edge ,teeth-per-inch,speed,performance-description,maximum-power,maximum-power-unit-of-measure,torque ,torque-unit-of-measure,cutting-diameter,cutting-diameter-unit-of-measure,tool-tip-description,measurement-system,accessory-connection-type,compatible-fastener-range,laser-beam-color,measurement-accuracy,viewing-area,uv-protection,grit-rating,grit-description,coverage,r-value,switch-type,display-style,plug-profile,plug-format,switch-style,fulfillment-center-id,assembled-height,assembled-length,assembled-width ,assembled-diameter ,assembled-unit-of-measure,weight,weight-unit-of-measure,shipping-weight,ppu-count,ppu-count-type,are-batteries-included,batteries-required,battery-cell-type,battery-description,battery-life ,battery-life-unit-of-measure,lithium-battery-energy-content,lithium-battery-packaging,lithium-battery-voltage,lithium-battery-weight,number-of-lithium-ion-cells,number-of-lithium-metal-cells,is-gift-message-available,is-giftwrap-available,is-discontinued-by-manufacturer,registered-parameter,update-delete"; | |
static string[] attributes = schema.Split(','); | |
static string filePath = "C:\\Users\\Zachary\\Desktop\\output.txt"; | |
static DataTable table = new DataTable(); | |
static StringBuilder builder = new StringBuilder(header + '\n'); | |
static Dictionary<string, string> amazon = new Dictionary<string, string>() | |
{ | |
{"sku","SKU"}, | |
{"standard-product-id","StandardID"}, | |
{"product-id-type","StandardIDType"}, | |
{"product-name","Name"}, | |
{"brand","Brand"}, | |
{"manufacturer","Manufacturer"}, | |
{"manufacturer-part-number","SKU"}, | |
{"bullet-point1","Feature1"}, | |
{"bullet-point2","Feature2"}, | |
{"bullet-point3","Feature3"}, | |
{"bullet-point4","Feature4"}, | |
{"bullet-point5","Feature5"}, | |
{"description","Description"}, | |
{"product_type","ProductType"}, | |
{"item-price","Price"}, | |
{"currency","Currency"}, | |
{"condition-type","Condition"}, | |
{"quantity","Quantity"}, | |
{"msrp","MSRP"}, | |
{"leadtime-to-ship","LeadTime"}, | |
{"product-tax-code","TaxCode"}, | |
{"item-type","AmazonCategory"}, | |
{"main-image-url","ImageURL"} | |
}; | |
static void Main(string[] args) | |
{ | |
using (SqlConnection conn = new SqlConnection(connString)) | |
{ | |
conn.Open(); | |
query = "select * from Products where AmazonDepartment = 'Industrial';"; | |
using (SqlDataAdapter adapter = new SqlDataAdapter(query, conn)) | |
{ | |
adapter.Fill(table); | |
string s = schema.Replace(',','\t'); | |
builder.AppendLine(s).AppendLine(s); | |
int count = 0; | |
int total = table.Rows.Count; | |
foreach (DataRow row in table.Rows) | |
{ | |
foreach (string attribute in attributes) | |
{ | |
if (amazon.ContainsKey(attribute)) | |
{ | |
string value = row[amazon[attribute]].ToString(); | |
builder.AppendFormat("{0}\t", value.Replace("\n", "").Replace(Environment.NewLine, "")); | |
} | |
else | |
{ | |
builder.Append("\t"); | |
} | |
} | |
if (++count != total) | |
builder.AppendLine(); | |
} | |
} | |
string output = builder.ToString(); | |
File.WriteAllText(filePath, output); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment