41 lines
1004 B
Python
41 lines
1004 B
Python
import os
|
|
|
|
from openpyxl import Workbook
|
|
from openpyxl.styles import PatternFill, Border, Side, Alignment, Protection, Font
|
|
|
|
from .utils import ensure_dir, set_file_perms, WORKDIR
|
|
|
|
|
|
def format_season(s):
|
|
if not s or len(s) < 4:
|
|
return s
|
|
|
|
# 'SS20' -> 'S20'
|
|
return s[:1] + s[2:]
|
|
|
|
|
|
def write_spreadsheet(matches, subdir, catname, filename):
|
|
if not matches:
|
|
print('write_spreadsheet: no matches. skipping.')
|
|
return
|
|
|
|
wb = Workbook()
|
|
ws = wb.active
|
|
|
|
ws.append(['Season', 'Gender', 'Name', 'Style Number', 'Color'])
|
|
|
|
for m in matches:
|
|
ws.append([format_season(m['season']), m['gender'], m['name'], m['material'], m['color']])
|
|
|
|
# # Python types will automatically be converted
|
|
# import datetime
|
|
# ws['A2'] = datetime.datetime.now()
|
|
# ws['A2'].style = 'Good'
|
|
|
|
# save
|
|
dir = os.path.join(WORKDIR, subdir, catname)
|
|
ensure_dir(dir)
|
|
path = os.path.join(dir, f"{filename}.xlsx")
|
|
wb.save(path)
|
|
set_file_perms(path)
|