Select to view content in your preferred language

Assignment Monitor Python Script not working

1956
8
Jump to solution
11-15-2018 10:44 AM
LaneHartman
Emerging Contributor

I am configuring the assignment monitor python script and it seems to be hanging up on my organization URL.  I've tried at least 5 different versions of my URL (with https://, without https://, with a / at the end, without, etc).  The error I keep getting is below:

(arcgispro-clone-new) C:\xxxx\assignment_monitor>python assignment_monitor.py
[2018-11-15 13:12:42,869] [ assignment_monitor.py: 155 - <module>()] [MainThread] [ root] [ INFO] Authenticating with ArcGIS Online...
Traceback (most recent call last):
File "assignment_monitor.py", line 159, in <module>
verify_cert=False)
File "C:\Users\Lane\AppData\Local\ESRI\conda\envs\arcgispro-clone-new\lib\site-packages\arcgis\gis\__init__.py", line 273, in __init__
raise Exception("Malformed url provided: %s" % url)
Exception: Malformed url provided: <https://xxxx.maps.arcgis.com>

Any ideas?

0 Kudos
1 Solution

Accepted Solutions
by Anonymous User
Not applicable

Oh sorry, there also shouldn't be any quotes around it.

Here is my example:

# workforce/agol project id
[WORKFORCE]
PROJECT = 7dc1bd9bdffe4adeb5adcafXXXXXXXXX

# slack webhook
[SLACK]
WEBHOOK = https://hooks.slack.com/services/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

# AGOL auth info
[AGOL]
ORG = https://arcgis.com
USERNAME = workforce_scripts
PASSWORD = password

# log file
[LOG]
LOGFILE = log.txt

[DB]
DATABASE = assignments.db

View solution in original post

0 Kudos
8 Replies
by Anonymous User
Not applicable

It looks like you might be putting the url inside the angle brackets. Try "https://arcgis.com" instead of <"https://arcgis.com">. The angle brackets are just meant to denote that it's a template that needs to be filled in. Hope that helps.

0 Kudos
LaneHartman
Emerging Contributor

Aaron,

I tried that, but still get the same error. It just replaces the angle brackets with the double quotes. Here is the full config.ini file for the assignment monitor Script in case I’m missing something else.

# workforce/agol project id
[WORKFORCE]
PROJECT = xxxxxxxxxxxxxxxxxxxxxxxxx

# slack webhook
[SLACK]
WEBHOOK = https://hooks.slack.com/services/xxxxxxxxxxx/xxxxxxxx

# AGOL auth info
[AGOL]
ORG = "https://xxxx.maps.arcgis.com"
USERNAME = xxxxx
PASSWORD = xxxxx

# log file
[LOG]
LOGFILE = log.txt

[DB]
DATABASE = assignments.db

0 Kudos
by Anonymous User
Not applicable

Oh sorry, there also shouldn't be any quotes around it.

Here is my example:

# workforce/agol project id
[WORKFORCE]
PROJECT = 7dc1bd9bdffe4adeb5adcafXXXXXXXXX

# slack webhook
[SLACK]
WEBHOOK = https://hooks.slack.com/services/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

# AGOL auth info
[AGOL]
ORG = https://arcgis.com
USERNAME = workforce_scripts
PASSWORD = password

# log file
[LOG]
LOGFILE = log.txt

[DB]
DATABASE = assignments.db
0 Kudos
LaneHartman
Emerging Contributor

Yes, the script works fine now. Is there a way to change the fields that appear in Slack?  I'd like to have the assignment type in there also. 

0 Kudos
by Anonymous User
Not applicable

Awesome. Glad you got it working. You can modify the function in the script here: workforce-scripts/assignment_monitor.py at master · Esri/workforce-scripts · GitHub  

I believe this would show the assignment type (haven't actually tested it).

def post_to_slack(slack_webhook, assignment):
    """
    Posts a message to slack
    :param slack_webhook: (string) The url of the slack webhook
    :param assignment: (Feature) The feature to use
    :return:
    """
    # create the message to send
    message = """
    *Assignment Completed*:
    *Assignment Type:* {}
    *Location*: {}
    *Description*: {}
    *Notes*: {}
    *Worker*: {}
    *Time*: {}
    *Link*: {}
    """.format(
        assignment.assignment_type.name,
        assignment.location,
        assignment.description,
        assignment.notes,
        assignment.worker.name,
        assignment.completed_date.strftime("%Y-%m-%d %H:%M"),
        "https://workforce.arcgis.com/projects/{}/dispatch/assignments/{}".format(
            assignment.project.id,
            assignment.object_id
        )
    )
    logging.getLogger().info("Posting: {} to slack".format(inspect.cleandoc(message)))
    response = requests.post(slack_webhook, json={"text": inspect.cleandoc(message)})
    logging.getLogger().info("Status code: {}".format(response.status_code))
LaneHartman
Emerging Contributor

Yes, that works perfect.  I had just dug into the schema of the feature class and found the domain name when you replied.

Thanks!

0 Kudos
LaneHartman
Emerging Contributor

Also, the time field is 5 hours later than my current time in the Eastern Time zone which I assume is UTC.  Is there a way to display the time stamp in Slack as the Eastern time zone by modifying the assignment_monitor.py script? I tried to modify Line 63 as shown below, but that didn't seem to have any effect on the output.

assignment.completed_date.strftime("%Y-%m-%d %I:%M %p")

0 Kudos
by Anonymous User
Not applicable

You could try using the arrow module (you'll have to install it with pip/conda). This should handle daylight saving and what not.

Arrow: better dates and times for Python — Arrow 0.11.0 documentation 

Then you could do something like:

d = arrow.get(assignment.completed_date)

eastern_date = d.to('US/Eastern')

eastern_date_string = eastern_date.strftime("%Y-%m-%d %H:%M")

0 Kudos