markup: add spreadsheet writing
This commit is contained in:
40
markup/spreadsheet.py
Normal file
40
markup/spreadsheet.py
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
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)
|
||||||
@ -20,6 +20,7 @@ os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'procat2.settings')
|
|||||||
django.setup()
|
django.setup()
|
||||||
|
|
||||||
from markup.matching import find_marked_products
|
from markup.matching import find_marked_products
|
||||||
|
from markup.spreadsheet import write_spreadsheet
|
||||||
|
|
||||||
|
|
||||||
def main(argv):
|
def main(argv):
|
||||||
@ -43,7 +44,8 @@ def main(argv):
|
|||||||
catname = re.sub(r'[^\w]', '_', catname)
|
catname = re.sub(r'[^\w]', '_', catname)
|
||||||
|
|
||||||
matches = find_marked_products(fname, subdir, catname, debug=0)
|
matches = find_marked_products(fname, subdir, catname, debug=0)
|
||||||
print(matches)
|
print(f'{len(matches)} product matches')
|
||||||
|
write_spreadsheet(matches, subdir, catname, path.stem)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__': sys.exit(main(sys.argv))
|
if __name__ == '__main__': sys.exit(main(sys.argv))
|
||||||
|
|||||||
@ -13,17 +13,20 @@ django-settings-export==1.2.1
|
|||||||
django-user-accounts==2.1.0
|
django-user-accounts==2.1.0
|
||||||
django-webpack-loader==0.6.0
|
django-webpack-loader==0.6.0
|
||||||
Dumper==1.2.0
|
Dumper==1.2.0
|
||||||
|
et-xmlfile==1.0.1
|
||||||
humanize==0.5.1
|
humanize==0.5.1
|
||||||
importlib-metadata==0.23
|
importlib-metadata==0.23
|
||||||
imutils==0.5.3
|
imutils==0.5.3
|
||||||
ipdb==0.11
|
ipdb==0.11
|
||||||
ipython==7.3.0
|
ipython==7.3.0
|
||||||
ipython-genutils==0.2.0
|
ipython-genutils==0.2.0
|
||||||
|
jdcal==1.4.1
|
||||||
jedi==0.13.3
|
jedi==0.13.3
|
||||||
kombu==4.6.5
|
kombu==4.6.5
|
||||||
more-itertools==7.2.0
|
more-itertools==7.2.0
|
||||||
numpy==1.17.2
|
numpy==1.17.2
|
||||||
opencv-python==4.1.1.26
|
opencv-python==4.1.1.26
|
||||||
|
openpyxl==3.0.0
|
||||||
parso==0.3.4
|
parso==0.3.4
|
||||||
pdfminer==20191010
|
pdfminer==20191010
|
||||||
pexpect==4.6.0
|
pexpect==4.6.0
|
||||||
|
|||||||
Reference in New Issue
Block a user