Skip to content

Instantly share code, notes, and snippets.

@smeschke
Created October 28, 2016 16:07
Show Gist options
  • Save smeschke/23062d7bc0038c6018489d2d0002dafc to your computer and use it in GitHub Desktop.
Save smeschke/23062d7bc0038c6018489d2d0002dafc to your computer and use it in GitHub Desktop.
Creates Catalog
article_path = 'furniture/furniture_invintory' #path to the article
article = open(article_path, 'r') #open the article
products = []
while True:
line = article.readline()
if line[:-1] == 'end_furniture': break
if line[:-1] == 'start_product':
product_key = article.readline()
product_name = article.readline()
banner_line_one = article.readline()
banner_line_two = article.readline()
image_path = article.readline()
description = article.readline()
finish = article.readline()
dimensions = article.readline()
price = article.readline()
products.append((product_key[13:-1],
product_name[14:-1],
banner_line_one[17:-1],
banner_line_two[17:-1],
image_path[12:-1],
description[13:-1],
finish[8:-1],
dimensions[12:-1],
price[7:-1]))
for i in products[-1]: print i
for product in products:
#get the previous product and the next product in the list fo products
#so that at the bottom of the page, there can be a back and next button
product_position = products.index(product)
if product_position == 0:
previous_product_position = -1
next_product_position = 1
elif product == products[-1]:
previous_product_position = -2
next_product_position = 0
else:
previous_product_position = product_position-1
next_product_position = product_position+1
#make banner
import cv2
font = cv2.FONT_HERSHEY_SIMPLEX
img = cv2.imread('raw_images/banner.png')
cv2.putText(img,'Good Years Woodworking',(10,40), font, 1.5,(0,0,0),3)
cv2.putText(img,product[2],(550,200), font, .8,(0,0,0),2)
cv2.putText(img,product[3],(550,230), font, .8,(0,0,0),2)
cv2.imwrite('furniture/images/' + product[0] + '_banner.png', img)
#cv2.imwrite('new_images/' + product[0] + '_banner.png', img)
#start writing html - html head and banner
html = '<!DOCTYPE html><head></head><html><body align="center"><img src="images/'
html += product[0] + '_banner.png"><br>'
#write product name has headline
html += '<h1>'+product[1]+'</h1><br>'
#insert the image
html += '<img src="images/furniture_' + product[4][:-4] + '_autoresize.png"><br>'
#insert description
html += product[5] + '<br>'
#insert price, dimesntions and finish
html += 'Finish Options: ' + product[6] + '<br>' + 'Dimensions: ' + product[7] + '<br>' + 'Price: ' + product[8]
html += '<br><br>All furniture is made to order.<br>Request custom sizes, inlays, and carvings.<br>'
html += '<img src="images/name_image.png" align="center"><br>'
#add previous and next peices of furniture
previous_product = products[previous_product_position][0]+'.html' #link to previous product
previous_product_thumb = 'images/'+ previous_product[:-5]+'_thumb.png' #linke to previous product thumb
previous_product_name = products[previous_product_position][1]#plain text previous product name
next_product = products[next_product_position][0]+'.html'
next_product_thumb = 'images/'+ next_product[:-5]+'_thumb.png'
next_product_name = products[next_product_position][1]
left_cell = '<a href="'+previous_product+'">Previous Product<br><img src="'+previous_product_thumb+'"><br>'+previous_product_name+'</a>'
right_cell = '<a href="'+next_product+'">Next Product<br><img src="'+next_product_thumb+'"><br>'+next_product_name+'</a>'
html+= '<br><br><br><table align="center"><tr>'
html+= '<td>' + left_cell + '</td>'
html+= '<td>' + right_cell + '</td>'
html+= '</tr></table>'
#add back to home line
html+='<br><br><a href="http://goodyearsww.com/">Good Years Woodworking Home</a>'
f = open('furniture/' + product[0]+'.html', 'w')
print 'Finished Writing .html Document for ', product[0]
for i in html: f.write(i)
f.close()
import os
for img_path in os.listdir('furniture/raw_furniture_images'):
print 'Currently resizing ', img_path, '. Please Wait...'
path = 'furniture/raw_furniture_images/'+img_path
print path
img = cv2.imread(path)
#scale image down for '4 sale' page
w,h = 800,555
img_scale = cv2.resize(img,(w,h),interpolation = cv2.INTER_CUBIC)
save_path = 'furniture/images/furniture_'+img_path[:-4]+'_autoresize.png'
cv2.imwrite(save_path, img_scale)
#scale image down for thumb
w,h = 150,100
img_scale = cv2.resize(img,(w,h),interpolation = cv2.INTER_CUBIC)
save_path = 'furniture/images/furniture_'+img_path[:-4]+'_thumb.png'
cv2.imwrite(save_path, img_scale)
print 'Finished Resizing Images'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment