-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapplication.py
More file actions
111 lines (101 loc) · 4.21 KB
/
application.py
File metadata and controls
111 lines (101 loc) · 4.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
import os
import logging
from savanna.CreateBarcode import CreateBarcode
from savanna.FDARecall import FDARecall
from savanna.UPCLookup import UPCLookup
from savanna.SavannaAPI import SavannaAPI
def display_title_bar():
os.system('cls' if os.name == 'nt' else 'clear')
SavannaAPI.APIKey = ""
print("\t**************************************************")
print("\t*** Commandline Savanna-Python-SDK sample tool ***")
print("\t**************************************************")
print("\t[1] CreateBarcode")
print("\t[2] FDARecall")
print("\t[3] UPCLookup")
def run_CreateBarcode():
print("\tCreateBarcode:")
print("\tinput should follow:")
print("\tsymbology, text (code39, HELLO-WORLD) or ")
print("\tsymbology, text, scale, rotation, includeText (code39, HELLO-WORLD, 1, N, true) or")
print("\tsymbology, text, scaleX, scaleY, rotation, includeText (code39, HELLO-WORLD, 1, 1, N, true)")
command = input("\tcommand: ")
if(checkCommand(command)):
params = command.split(', ')
params_length = len(params)
if(params_length == 2):
fileBytes = CreateBarcode.create_symbology_text(params[0], params[1])
if(params_length == 5):
fileBytes = CreateBarcode.create_symbology_text_scale_rotation_includeText(params[0], params[1], params[2], params[3], params[4])
if(params_length == 6):
fileBytes = CreateBarcode.create_symbology_text_scaleX_scaleY_rotation_includeText(params[0], params[1], params[2], params[3], params[4], params[5])
try:
barcodeFile = open("barcode.png", "wb")
barcodeFile.write(fileBytes)
print("File saved to Savanna-Python-Samples/barcode.png")
except RuntimeError as error:
logging.error("Unable to write byte array to file\nError: {}".format(RuntimeError))
def run_FDARecall():
print("\tFDARecall:")
print("\tinput should follow:")
print("\tdeviceSearch, search (deviceSearch, Device) or ")
print("\tdeviceSearch, search, limit (deviceSearch, Device, 1) or")
print("\tdrugSearch, search (drugSearch, Food)")
print("\tdrugSearch, search, limit (drugSearch, Food, 1)")
print("\tfoodUpc, upc (foodUpc, 820267662041775209)")
print("\tfoodUpc, upc, limit (foodUpc, 820267662041775209, 1)")
print("\tdrugUpc, upc (drugUpc, 820267662041775209)")
print("\tdrugUpc, upc, limit (drugUpc, 820267662041775209, 1)")
command = input("\tcommand: ")
if(checkCommand(command)):
params = command.split(', ')
params_length = len(params)
if(params_length == 2):
if(params[0] == "deviceSearch"):
FDARecall.deviceSearch(params[1])
if(params[0] == "drugSearch"):
FDARecall.drugSearch(params[1])
if(params[0] == "foodUpc"):
FDARecall.foodUpc(params[1])
if(params[0] == "drugUpc"):
FDARecall.drugUpc(params[1])
if(params_length == 3):
if(params[0] == "deviceSearch"):
FDARecall.deviceSearch_limit(params[1], params[2])
if(params[0] == "drugSearch"):
FDARecall.drugSearch_limit(params[1], params[2])
if(params[0] == "foodUpc"):
FDARecall.foodUpc_limit(params[1], params[2])
if(params[0] == "drugUpc"):
FDARecall.drugUpc_limit(params[1], params[2])
def run_UPCLookup():
print("\tUPCLookup:")
print("\tinput should follow:")
print("\tupc (9781483922973)")
command = input("\tcommand: ")
UPCLookup.lookup(command)
def checkCommand(command):
if(command.find(',') == -1):
logging.error("Please separate inputs by comma")
return False
else:
return True
def checkKey():
if(SavannaAPI.APIKey == ""):
logging.error(" APIKEY is empty, read the README.md" +
" for instructions on how to obtain an APIKEY")
return False
else:
return True
def main():
display_title_bar()
if(checkKey() == False):
return
prompt = input("\tEnter number 1 through 3: ")
if(prompt == '1'):
run_CreateBarcode()
if(prompt == '2'):
run_FDARecall()
if(prompt == '3'):
run_UPCLookup()
main()