-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate-orders-from-schedule.py
More file actions
75 lines (58 loc) · 2.85 KB
/
create-orders-from-schedule.py
File metadata and controls
75 lines (58 loc) · 2.85 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
import random
import sys
import time
from colorama import Back, Fore, Style, init
import config
from fastems.job import job_factory
from fastems.order import PlannedOrder
from schedule import Schedule
fail = {
'Success':'False',
'Message': {
'Text':'Order number {1} was not created for {0}'
}
}
success = {
'Success': 'True'
}
def fprint(s):
print(s, flush=True)
if __name__ == '__main__':
init(strip=False)
fprint(Back.BLUE+Fore.BLACK)
fprint(' _________ ___________________ ________ ____ ____ ____ __________ __________ _________ __________ ____ ')
fprint(' / ____/ | / ___/_ __/ ____/ |/ / ___/ / __ \/ __ \/ __ \/ ____/ __ \ / ____/ __ \/ ____/ |/_ __/ __ \/ __ \ ')
fprint(' / /_ / /| | \__ \ / / / __/ / /|_/ /\__ \ / / / / /_/ / / / / __/ / /_/ / / / / /_/ / __/ / /| | / / / / / / /_/ / ')
fprint(' / __/ / ___ |___/ // / / /___/ / / /___/ / / /_/ / _, _/ /_/ / /___/ _, _/ / /___/ _, _/ /___/ ___ |/ / / /_/ / _, _/ ')
fprint(' /_/ /_/ |_/____//_/ /_____/_/ /_//____/ \____/_/ |_/_____/_____/_/ |_| \____/_/ |_/_____/_/ |_/_/ \____/_/ |_| ')
fprint(' ')
fprint(Style.RESET_ALL + '')
try:
fprint(Fore.CYAN+'[INFO] Reading and parsing schedule CSV...')
access_schedule = Schedule(config.SCHEDULE_CSV_PATH)
except PermissionError as e:
fprint(Fore.RED+'There was an error when reading the from %s' % config.SCHEDULE_CSV_PATH)
fprint('[ERROR] %s' % str(e))
sys.exit()
fprint(Fore.GREEN+'...Done!')
fprint('')
for job_details in access_schedule.get_all():
fprint('')
fprint(Fore.CYAN+'[INFO] Creating job from schedule details for %s' % job_details['part_number'])
try:
job = job_factory(**job_details)
fprint(Fore.BLUE+'[FASTEMS] The GID for %s is %s' % (job.part_number, job.gid))
fprint(Fore.CYAN+'[INFO] Created Order %s for %s' % (job.order_number, job.description))
fprint('[INFO] Submitting Order to Fastems....')
order = PlannedOrder(job)
response = order.submit()
# response = random.choice([success, fail])
if response['Success']:
msg = Fore.GREEN+'[SUCCESS] Order created successfully!'
else:
msg = Fore.RED+'[ERROR] %s' % response['Message']['Text']
msg = msg.format(job_details['part_number'], job_details['order_number'])
fprint(msg)
time.sleep(.5)
except KeyError as e:
fprint(Fore.RED+'[ERROR] Fastems did not return a GID for %s; Skipping...' % job_details['part_number'])