Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Workflow_via_CSV/bulk_functions.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# bulk_functions.py
# written and tested in Python 3.6.0
# written and tested in Python 3.6.2
# last updated 10/02/17

import requests
Expand Down
38 changes: 21 additions & 17 deletions Workflow_via_CSV/bulk_initiate.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# bulk_initiate.py
# written and tested in Python 3.6.0
# written and tested in Python 3.6.2
# last updated 10/02/17

"""
This script initiates workflows using field data from a CSV file. The first
row of the CSV should contain field labels, and all other rows should hold
field values (each row will be a separate instance of the workflow). The script
creates a new txt file (in same directory as this) each time it is run, and
writes the result of each workflow instance, including error messages.
This script initiates workflows using data from a CSV file. The first row of
the CSV should contain field labels, and all other rows should hold field
values (each row will be a separate instance of the workflow). The script
creates a txt file (in same directory as this) each time it is run, and writes
the result of each workflow instance, including error messages.

To use, create a workflow, create a CSV based on the workflow, and update the
global variables below. If you find bugs or errors that are not handled,
Expand All @@ -28,12 +28,12 @@
# ---------------- #

# replace tenant, environment, instance with your own
url_root = 'https://tenant.environment.thinksmart.com/instance/'
url_root = 'https://default.stagingtap.thinksmart.com/default/'
# fill in (must be strings)
client_id = ''
client_secret = ''
workflow_name = ''
csv_name = ''
client_id = 'b473d2ace41144bb87d63be7584ecec1'
client_secret = 'Yjr1ZnzMgN58x7H+WlPM6WRTzk1B7RocuYkOEuVhcpw='
workflow_name = 'PyScript Test'
csv_name = '/Users/cameronpierce/Dropbox/thinksmart/api/PyScript.csv'
# enter username and password in command line during runtime
username = input("Username: ")
password = getpass.getpass()
Expand Down Expand Up @@ -126,6 +126,10 @@
# Convert Field Labels to Names #
# ----------------------------- #

# features to add here:
# accept names and labels
# accept labels that meet word-similarity threshold (in event of typo)

# get form info from workflow
r = getFormInfo(url_root, template_id, token)

Expand Down Expand Up @@ -175,12 +179,12 @@
if ((not remainder) and (not csv_labels)):
pass
elif (not remainder):
f.append(mismatch.format(csv_name, workflow_name, "\n".join(csv_labels)))
f.write(mismatch.format(csv_name, workflow_name, "\n".join(csv_labels)))
elif (not csv_labels):
f.append(mismatch.format(workflow_name, csv_name, "\n".join(remainder)))
f.write(mismatch.format(workflow_name, csv_name, "\n".join(remainder)))
else:
f.append(mismatch.format(csv_name, workflow_name, "\n".join(csv_labels)))
f.append(mismatch.format(workflow_name, csv_name, "\n".join(remainder)))
f.write(mismatch.format(csv_name, workflow_name, "\n".join(csv_labels)))
f.write(mismatch.format(workflow_name, csv_name, "\n".join(remainder)))

# ------------------ #
# Initiate Workflows #
Expand All @@ -207,10 +211,10 @@
r = initiateWorkflow(url_root, template_id, token, body)
# empty required field, unmatched dropdown value, etc. causes 400 response
if (r.status_code == 400):
f.write("----------\nRow {}: Error\n----------\n").format(row)
f.write("{0}\nRow {1}: Error\n{0}\n".format("-"*(len(str(row))+11),row))
f.write("{}\n\n".format(r.text))
else:
f.write("----------\nRow {}: Submitted\n----------\n").format(row)
f.write("{0}\nRow {1}: Submitted\n{0}\n".format("-"*(len(str(row))+15),row))
for i, val in enumerate(body):
f.write("{} : {}\n".format(labels[i], body[val]))
f.write("\n")
Expand Down