Added try/except so paths work on windows and linux.

This commit is contained in:
dan
2021-06-10 01:11:41 -04:00
parent 6fbb5a9dd3
commit 135a1c474b

15
main.py
View File

@@ -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)
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')
try:
pdf.output(name='./static/barcodes.pdf')
except:
pdf.output(name='.\\static\\barcodes.pdf')
return {'Barcodes': 'Ready'}
except:
return {'Barcodes': 'Failed'}