View gist:1630069
def show_materials(materials, location):
""" show what's in the materials catalog """
key_superset = []
key_commonset = []
#
key = materials['key']
count = materials['count']
catalog = materials['materials']
if count != len(catalog):
# something not right
View gist:1630064
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]
View gist:1630062
material_catalogTAG = "/material_catalog/" # added onto nodesTAG
from datetime import datetime
from copy import deepcopy
View gist:1630057
Node_materials = {'Ponoko - United States': [u'2010/06/28 20:23:16',
{'6bb50fb04a' :
{u'material_type': u'printed',
u'updated_at': u'2011/06/27 20:23:16 +0000',
u'key': u'6bb500cdb04a',
u'name': u'Durable plastic'}},
{'6b62cdbed4a' :
{u'material_type': u'printed',
u'updated_at': u'2011/06/27 20:23:16 +0000',
u'key': u'6bb9552cdb04a',
View gist:1630037
## main
if __name__ == "__main__":#
keydata = urlencode((app_key, user_access_key))
success, nodes = get_manufacturing_nodes(baseURL, keydata)
if success:
print success, nodes
for i in range(len(nodes)):
update_node_materials(nodes[i], baseURL, keydata)
View gist:1630033
Getting Node catalog
http://sandbox.ponoko.com/services/api/v2/nodes?app_key= abcdefgh &user_access_key= stuvwxyz
Error: ('FAIL - Server could not fulfill request', 401)
View gist:1630026
Getting Node catalog
http://sandbox.ponoko.com/services/api/v2/nodes?app_key=abcdefgh &user_access_key=stuvwxyz
Response:
[{u'materials_updated_at': u'2011/06/27 20:23:16 +0000', u'name': u'Ponoko - United States', u'key': u'2e9d8ccdb04a'}]
Node name Ponoko - United States
Last updated: 2011/06/27 20:23:16 +0000
node_key 2e9d8ccdb04a
View gist:1630008
def basic_request(request, verbose=False):
""" request is in form of a urllib2.Request()
Return (False, error) OR
(True, response, url, info)
"""
error = False
result = []
try:
response = urlopen(request,timeout=100)
except IOError, e:
View gist:1629913
def get_manufacturing_nodes(URL, keydata, verbose=True):
""" Get the nodes from dedicated url.
Uses basic request
"""
URL_full = "%s%s?%s" % (URL, nodesTAG, keydata)
if verbose:
print "Getting Node catalog\n %s" % (URL_full)
req = Request(URL_full)
success, result = basic_request(req)
if not success:
View gist:1629885
# Use live system or Sandbox
#live_or_test = "www"
live_or_test = "sandbox"
baseURL = "http://"+ live_or_test +".ponoko.com/services/api/v2"