Skip to content

@dave5 /gist:1630064
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Update node materials - Python
def update_node_materials(node, URL, keydata, verbose=True):
""" for a manufacturing node:
- retrieve the catalog in json format
- convert it to python dictionary and list structures
"""
location = node[u'name']
date = node[u'materials_updated_at']
key = node[u'key']
date = date[:-6] # strip off seconds
recorded_materials = Node_materials[location]
ourdate = datetime.strptime(recorded_materials[0], "%Y/%m/%d %H:%M:%S")
newdate = datetime.strptime(date, "%Y/%m/%d %H:%M:%S")
if verbose: print "Checking: %s vs. %s" % (ourdate, newdate)
if ourdate <= newdate:
# need to update some or all materials
catalog = recorded_materials[1]
catalogURL = "%s%s%s" % (URL, nodesTAG, material_catalogTAG)
request = "%s%s?%s" %(catalogURL, key, keydata)
if verbose: print "Requesting Catalog updates for %s\n %s" % (location, request)
req = Request(request)
result = basic_request(req)
if not result[0]:
# fail
print result[1]
else: # Success
materials = json.loads(result[1][0])
show_materials(materials, location)
# update the local store
#!!!
else: # no need to update
print "No change to materials for %s" % (location)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.