Skip to content

Instantly share code, notes, and snippets.

@patrykorwat
Created March 29, 2014 22:39
Show Gist options
  • Select an option

  • Save patrykorwat/9864205 to your computer and use it in GitHub Desktop.

Select an option

Save patrykorwat/9864205 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from BeautifulSoup import BeautifulSoup
import re, Image
for tr in BeautifulSoup(open('index.html', 'r')).findAll(lambda tag: (tag.name == 'tr' and tag.td and tag.td.attrs and len(tag.td.attrs) ==1) and tag.td.p):
print "INSERT INTO colour (`palette_id`,`photo`,`name`) VALUES (11,'"+re.sub(r'\#+', '', tr.contents[5].span.string)+".jpg','"+re.sub(r' *\n *', ' ', tr.td.p.span.string.replace(' ',' '))+'-'+re.sub(r' *\n *', ' ', tr.contents[9].p.span.string.replace(' ',' '))+"'); "
Image.new('RGB',(29,29), tr.contents[5].span.string.replace('##','#')).save(re.sub(r'\#+', '', tr.contents[5].span.string)+'.jpg', 'JPEG')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment