From 135a1c474bb275bc0539078821d39f83f585c2e9 Mon Sep 17 00:00:00 2001 From: dan Date: Thu, 10 Jun 2021 01:11:41 -0400 Subject: [PATCH] Added try/except so paths work on windows and linux. --- main.py | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/main.py b/main.py index 87a0de4..3167a36 100644 --- a/main.py +++ b/main.py @@ -90,7 +90,6 @@ async def lookup(isbn: str = Form(...)): @app.post('/AddLocation/') async def checkin(BookCase: str = Form(...), Shelf: str = Form(...)): - location = [] session.add(Location(userid=1, Bookcase=BookCase, Shelf=Shelf)) session.commit() @@ -101,14 +100,13 @@ async def checkin(BookCase: str = Form(...), Shelf: str = Form(...)): @app.post('/barcodes') async def barcodes(userid: int = Form(...)): - - temp = [] - barcode = {'CheckIn': 'Check In', 'CheckOut': 'Check Out'} pdf = FPDF() - # pdf.add_font('barcode', '', '.\\static\\barcodeFont\\LibreBarcode128-Regular.ttf', uni=True) - # pdf.add_font('barcode', '', '.\\static\\barcodeFont\\LibreBarcode39-Regular.ttf', uni=True) - pdf.add_font('barcode', '', './static/barcodeFont/LibreBarcode39-Regular.ttf', uni=True) + + try: + pdf.add_font('barcode', '', './static/barcodeFont/LibreBarcode39-Regular.ttf', uni=True) + except: + pdf.add_font('barcode', '', '.\\static\\barcodeFont\\LibreBarcode39-Regular.ttf', uni=True) pdf.add_page() @@ -118,7 +116,6 @@ async def barcodes(userid: int = Form(...)): code = (each.Bookcase + each.Shelf).replace(' ','') display = each.Bookcase + ' - ' + each.Shelf barcode['Loc.' + code] = display - temp.append(code) for each in barcode: pdf.set_font('barcode', '', 25) @@ -131,8 +128,10 @@ async def barcodes(userid: int = Form(...)): pdf.ln() try: - # pdf.output(name='.\\static\\barcodes.pdf') - pdf.output(name='./static/barcodes.pdf') + try: + pdf.output(name='./static/barcodes.pdf') + except: + pdf.output(name='.\\static\\barcodes.pdf') return {'Barcodes': 'Ready'} except: return {'Barcodes': 'Failed'} @@ -140,4 +139,4 @@ async def barcodes(userid: int = Form(...)): async def getMeta(isbn): info = meta(isbn, service='wiki') - return info \ No newline at end of file + return info