====Write Values to an ARDI Asset==== ===Description=== This script updates the value of a property in ARDI itself. This is useful if you have //last modified date// or //last maintained by// information inside ARDI properties. You can also interrogate information from ARDI in the same script, so if you were interested in storing the //next// time maintenance is required, you could query the asset for it's maintenance frequency first. In the example below, //two// properties are being set. The date of the last inspection, and the username of the person who completed it. ===Full Script=== import requests from datetime import datetime import os import sys import traceback import warnings #Set default details server="servername/s/sitename" username="username" password="password" datepropertyid=[ID of the date property in ARDI]] userpropertyid=[[ID of the user property in ARDI]] asset = "Unknown Asset" checklist = "Unknown Checklist" user = "Unknown User" assetid = "1" tm = datetime.now().strftime("%Y/%m/%d %H:%M:%S") #Get submission details from environment variables try: asset = os.environ["assetname"] except: print "No Asset Provided" sys.exit(0) try: assetid = os.environ["assetid"] except: print "No Asset ID Provided" sys.exit(0) try: checklist = os.environ["checklist"] except: print "No Checklist Provided" sys.exit(0) try: user = os.environ["user"] except: print "No User Provided" sys.exit(0) def Sub(st,ass,chk,usr,dt): return st.replace("{checklist}",chk).replace("{asset}",ass).replace("{user}",usr).replace("{date}",dt) #Get auth key from ARDI server.... url = "http://" + server + "/api/auth?username=" + username + "&password=" + password resp = requests.get(url) data = resp.content #Extract the auth-key from the response (quick and dirty - real solutions might do more exception handling and error checking here... ind = data.find("") if ind > 0: indx = data.find("") totaloffset = ind + 10 authcode = data[totaloffset:indx] #Submit date url = "http://" + server + "/api/asset/property" payload = [('id',assetid),('property',datepropertyid),('node','text'),('value',tm),('auth',authcode)] resp = requests.post(url,data=payload) #Submit username payload = [('id',assetid),('property',userpropertyid),('node','text'),('value',user),('auth',authcode)] requests.post(url,data=payload) #If everything worked out, send the word 'OK'. print 'OK'