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/') @app.post('/AddLocation/')
async def checkin(BookCase: str = Form(...), Shelf: str = Form(...)): async def checkin(BookCase: str = Form(...), Shelf: str = Form(...)):
location = [] location = []
session.add(Location(userid=1, Bookcase=BookCase, Shelf=Shelf)) session.add(Location(userid=1, Bookcase=BookCase, Shelf=Shelf))
session.commit() session.commit()
@@ -101,14 +100,13 @@ async def checkin(BookCase: str = Form(...), Shelf: str = Form(...)):
@app.post('/barcodes') @app.post('/barcodes')
async def barcodes(userid: int = Form(...)): async def barcodes(userid: int = Form(...)):
temp = []
barcode = {'CheckIn': 'Check In', 'CheckOut': 'Check Out'} barcode = {'CheckIn': 'Check In', 'CheckOut': 'Check Out'}
pdf = FPDF() 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) 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() pdf.add_page()
@@ -118,7 +116,6 @@ async def barcodes(userid: int = Form(...)):
code = (each.Bookcase + each.Shelf).replace(' ','') code = (each.Bookcase + each.Shelf).replace(' ','')
display = each.Bookcase + ' - ' + each.Shelf display = each.Bookcase + ' - ' + each.Shelf
barcode['Loc.' + code] = display barcode['Loc.' + code] = display
temp.append(code)
for each in barcode: for each in barcode:
pdf.set_font('barcode', '', 25) pdf.set_font('barcode', '', 25)
@@ -131,8 +128,10 @@ async def barcodes(userid: int = Form(...)):
pdf.ln() pdf.ln()
try: try:
# pdf.output(name='.\\static\\barcodes.pdf') try:
pdf.output(name='./static/barcodes.pdf') pdf.output(name='./static/barcodes.pdf')
except:
pdf.output(name='.\\static\\barcodes.pdf')
return {'Barcodes': 'Ready'} return {'Barcodes': 'Ready'}
except: except:
return {'Barcodes': 'Failed'} return {'Barcodes': 'Failed'}