-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsorting_to_order.py
More file actions
117 lines (106 loc) · 3.19 KB
/
sorting_to_order.py
File metadata and controls
117 lines (106 loc) · 3.19 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
112
113
114
115
116
117
import argparse
import logging
import sys
from api_client import APIClient
log = logging.getLogger(__name__)
def sort_to_order(url, token):
log.info("Creating api client")
api = APIClient(url, token)
log.info("Deleting parts marked as reprint")
api.part.delete(id="airplane,knight")
log.info("Updating parts to the next step")
parts = [
{
"id": "widget",
"title": "Widget",
"copies": 1,
"model": "bracket",
"material": "MJF_PA12-BLACK",
"attributes": {
"prev_step": "dye_black",
"next_step": "shipping",
"technology": "MJF",
"order_id": 443,
"tray": "240",
"target_date": "2022-03-18",
},
},
{
"id": "coupling",
"title": "Coupling",
"copies": 1,
"model": "coupling",
"material": "SLS_PA11-BLACK",
"attributes": {
"prev_step": "dye_black",
"next_step": "shipping",
"technology": "SLS",
"order_id": 302,
"tray": "240",
"target_date": "2022-03-18",
},
},
{
"id": "flange",
"title": "Flange",
"copies": 1,
"model": "flange",
"material": "SLS_PA11-RED",
"attributes": {
"prev_step": "dye_red",
"next_step": "shipping",
"technology": "SLS",
"order_id": 201,
"tray": "240",
"target_date": "2022-03-10",
},
},
{
"id": "vase",
"title": "Vase",
"copies": 3,
"model": "vase",
"material": "MJF_PA12-RED",
"attributes": {
"prev_step": "dye_red",
"next_step": "shipping",
"technology": "MJF",
"order_id": 168,
"tray": "240",
"target_date": "2022-07-23",
},
},
]
api.part.put(parts)
log.info("Creating sub-batches")
sub_batches = [
{
"id": "240_no_post_process",
"title": "Tray 240: no post process",
"query": "tray=240&prev_step=printing",
},
{
"id": "240_dye_black",
"title": "Tray 240: Dye black",
"query": "tray=240&prev_step=dye_black",
},
{
"id": "240_dye_red",
"title": "Tray 240: Dye red",
"query": "tray=240&prev_step=dye_red",
},
]
api.batch.put(sub_batches)
log.info("Deleteing original batch")
api.batch(240).delete()
if __name__ == "__main__":
parser = argparse.ArgumentParser(description="AM-Vision API sorting to order")
parser.add_argument("url", type=str, help="API URL")
parser.add_argument("token", type=str, help="API token")
args = parser.parse_args()
logging.basicConfig(
stream=sys.stdout,
level=logging.INFO,
format="[%(asctime)s: %(levelname)s] %(message)s",
)
sort_to_order(args.url, args.token)