Skip to content

Instantly share code, notes, and snippets.

@vikingmute
Created December 23, 2013 03:29
Show Gist options
  • Save vikingmute/8091306 to your computer and use it in GitHub Desktop.
Save vikingmute/8091306 to your computer and use it in GitHub Desktop.
from PIL import Image
from StringIO import StringIO
import xlrd, urllib, os, requests, zipfile
def zipdir(path, zip):
for root, dirs, files in os.walk(path):
for file in files:
zip.write(os.path.join(root, file))
#read the file in
book = xlrd.open_workbook('1234.xlsx')
#for in each sheet
for sheet in book.sheets():
for row in range(sheet.nrows):
item = {}
#read the link , name , and folder name
name = sheet.cell_value(row,1).encode('utf8')
link = sheet.cell_value(row,3).encode('utf8')
link = urllib.quote(link,'')
fname = sheet.cell_value(row,2).encode('utf-8')
path = "./imgs/" + fname
if not os.path.isdir(path):
os.makedirs(path)
print "Creating folder for shop id:" + fname + "\n"
print "Starting generate pic for" + name + "\n"
r = requests.get('http://chart.apis.google.com/chart?cht=qr&chs=280x280&chl=' + link + '&choe=UTF-8&chld=L|4')
i = Image.open(StringIO(r.content))
i.save('./imgs/'+ fname + '/' +name.decode('utf8').encode('gbk') + '.png')
print "The image for link : " + link + "is saved \n"
print "all images has been generated, zipping file now...\n"
if __name__ == '__main__':
zipf = zipfile.ZipFile('imgs.zip', 'w')
zipdir('./imgs', zipf)
zipf.close()
@vikingmute
Copy link
Author

读取excel表格 然后用表格链接访问google服务保存二维码图片 按表格新建文件夹并保存

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment