-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtasks.py
More file actions
executable file
·44 lines (36 loc) · 1.38 KB
/
tasks.py
File metadata and controls
executable file
·44 lines (36 loc) · 1.38 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
from pathlib import Path
from robocorp import workitems
from robocorp.tasks import get_output_dir, task
from RPA.Excel.Files import Files as Excel
@task
def producer():
"""Split Excel rows into multiple output Work Items for the next step."""
output = get_output_dir() or Path("output")
filename = "orders.xlsx"
for item in workitems.inputs:
path = item.get_file(filename, output / filename)
excel = Excel()
excel.open_workbook(path)
rows = excel.read_worksheet_as_table(header=True)
for row in rows:
payload = {
"Name": row["Name"],
"Zip": row["Zip"],
"Product": row["Item"],
}
workitems.outputs.create(payload)
@task
def consumer():
"""Process all the produced input Work Items from the previous step."""
for item in workitems.inputs:
try:
name = item.payload["Name"]
zipcode = item.payload["Zip"]
product = item.payload["Product"]
print(f"Processing order: {name}, {zipcode}, {product}")
assert 1000 <= zipcode <= 9999, "Invalid ZIP code"
item.done()
except AssertionError as err:
item.fail("BUSINESS", code="INVALID_ORDER", message=str(err))
except KeyError as err:
item.fail("APPLICATION", code="MISSING_FIELD", message=str(err))