|
@@ -10,6 +10,12 @@ import getpass
|
|
|
import json
|
|
|
import re
|
|
|
|
|
|
+MICE_TOILET_TEMPLATE = 'http://parts.shimatta.net/api/v1/parts/storages/075acbaf-ed60-47b9-9bd5-98bfbc3a79ea/'
|
|
|
+
|
|
|
+def char_range(c1, c2):
|
|
|
+ """Generates the characters from `c1` to `c2`, exclusive."""
|
|
|
+ for c in range(ord(c1), ord(c2)):
|
|
|
+ yield chr(c)
|
|
|
|
|
|
def handle_storage_qr_code(base_url, token, uuid):
|
|
|
storage_query_url = urllib.parse.urljoin(base_url, 'api/v1/parts/storages/')
|
|
@@ -19,7 +25,7 @@ def handle_storage_qr_code(base_url, token, uuid):
|
|
|
sys.exit(-3)
|
|
|
|
|
|
print('Storage found: ')
|
|
|
- storage_json = json.loads(query_res.content)
|
|
|
+ storage_json = query_res.json()
|
|
|
if storage_json['count'] != 1:
|
|
|
print('Storage json does not contain correct amount of storage entries')
|
|
|
sys.exit(-1)
|
|
@@ -28,10 +34,54 @@ def handle_storage_qr_code(base_url, token, uuid):
|
|
|
print(f'ID: {storage["id"]}')
|
|
|
print(f'Path: {storage["full_path"]}')
|
|
|
|
|
|
- label = shimatta_label.storage_label.StorageLabel()
|
|
|
- label.put_content(f'[stor_uuid]{uuid}', storage['full_path'])
|
|
|
+ labels = []
|
|
|
+
|
|
|
+ if storage['template'] == MICE_TOILET_TEMPLATE:
|
|
|
+
|
|
|
+ row = input('Select which row shall be printed [1..3]:')
|
|
|
+ if row not in char_range('1', '4'):
|
|
|
+ print('Error - invalid row')
|
|
|
+ return None
|
|
|
+ row = int(row)
|
|
|
+
|
|
|
+ side = input('Select which side shall be printed [t,b]:')
|
|
|
+ if side not in ['t', 'b']:
|
|
|
+ print('Error - invalid side')
|
|
|
+ return None
|
|
|
+
|
|
|
+ # get children
|
|
|
+ query_res = requests.get(storage_query_url, headers={'Authorization': f'Token {token}'}, params={'parent_storage':uuid})
|
|
|
+ if query_res.status_code != 200:
|
|
|
+ print('Request for children unsuccessful')
|
|
|
+ sys.exit(-3)
|
|
|
+
|
|
|
+ storage_json = query_res.json()
|
|
|
+ if storage_json['count'] != 24:
|
|
|
+ print('Storage json does not contain correct amount of storage entries')
|
|
|
+ sys.exit(-1)
|
|
|
+
|
|
|
+ # pagination
|
|
|
+ storage_list = storage_json['results']
|
|
|
+ while storage_json['next']:
|
|
|
+ query_res = requests.get(storage_json['next'], headers={'Authorization': f'Token {token}'}, params={'parent_storage':uuid})
|
|
|
+ storage_json = query_res.json()
|
|
|
+ storage_list.extend(storage_json['results'])
|
|
|
+
|
|
|
+ storage_dict = {storage['name']: storage for storage in storage_list}
|
|
|
|
|
|
- return label
|
|
|
+ if side == 'b':
|
|
|
+
|
|
|
+ for column in char_range('a','i'):
|
|
|
+ label = shimatta_label.storage_label.StorageLabelSmdMiceToiletBottomQR()
|
|
|
+ field_uuid = storage_dict[f'{column}{row}']['id']
|
|
|
+ label.put_content(f'[stor_uuid]{field_uuid}')
|
|
|
+ labels.append(label)
|
|
|
+ else:
|
|
|
+ label = shimatta_label.storage_label.StorageLabel()
|
|
|
+ label.put_content(f'[stor_uuid]{uuid}', storage['full_path'], storage['verbose_name'])
|
|
|
+ labels.append(label)
|
|
|
+
|
|
|
+ return labels
|
|
|
|
|
|
def handle_component_qr_code(base_url, token, uuid):
|
|
|
query_url = urllib.parse.urljoin(base_url, 'api/v1/parts/components/')
|
|
@@ -54,12 +104,14 @@ def handle_component_qr_code(base_url, token, uuid):
|
|
|
manufacturer = ''
|
|
|
|
|
|
print(f'Component found: Name: {name}, Package: {pkg}, Manufacturer: {manufacturer}')
|
|
|
- label = shimatta_label.component_label.ComponentLabel()
|
|
|
+
|
|
|
+ labels = []
|
|
|
+ label = shimatta_label.component_label.ComponentLabelSmall()
|
|
|
label.put_content(f'[comp_uuid]{uuid}', component['name'], manufacturer, pkg)
|
|
|
- return label
|
|
|
+ labels.append(label)
|
|
|
+
|
|
|
+ return labels
|
|
|
|
|
|
-printer_model = 'QL-800'
|
|
|
-printer_connection = 'usb://0x04f9:0x209b'
|
|
|
if len(sys.argv) < 2:
|
|
|
print(f'Usage: {sys.argv[0]} <shimatta kenkyusho url>')
|
|
|
sys.exit(-1)
|
|
@@ -88,18 +140,12 @@ while True:
|
|
|
|
|
|
matches = qr_re.match(qr)
|
|
|
if matches.group('prefix') == 'stor_uuid' :
|
|
|
- label = handle_storage_qr_code(kenkyusho_url, login_token, matches.group('uuid'))
|
|
|
+ labels = handle_storage_qr_code(kenkyusho_url, login_token, matches.group('uuid'))
|
|
|
elif matches.group('prefix') == 'comp_uuid':
|
|
|
- label = handle_component_qr_code(kenkyusho_url, login_token, matches.group('uuid'))
|
|
|
+ labels = handle_component_qr_code(kenkyusho_url, login_token, matches.group('uuid'))
|
|
|
else:
|
|
|
print('Invalid QR code!')
|
|
|
continue
|
|
|
|
|
|
-
|
|
|
-
|
|
|
- printer = ql_wrapper.BrotherQlPrinter(model=printer_model, printer_connection=printer_connection, label_format='29x90')
|
|
|
- printer.print_image(label.get_pillow_image(), rotation=90, cut=True)
|
|
|
-
|
|
|
- cont = input('Printed! Continue? [Y/n] ')
|
|
|
- if cont.lower() == 'n':
|
|
|
- sys.exit(0)
|
|
|
+ if labels:
|
|
|
+ ql_wrapper.print_labels(labels)
|