Skip to content

Instantly share code, notes, and snippets.

@5263
Created January 9, 2013 23:05
Show Gist options
  • Save 5263/4497836 to your computer and use it in GitHub Desktop.
Save 5263/4497836 to your computer and use it in GitHub Desktop.
thingiverse api experiments
token_type='Bearer'
access_token=''
baseurl='https://api.thingiverse.com/'
meurl='https://api.thingiverse.com/users/me'
import urllib2, base64
import json
def isfiletype(name,suffixes=('fcstd','scad','brep','brp')):
return any([name.lower().endswith(suffix) for suffix in suffixes])
def hasfiletype(lst1,suffixes=('fcstd','scad','brep','brp')):
return any([isfiletype(file1['name'],suffixes)for file1 in lst1])
def get2json(url):
request = urllib2.Request(url)
request.add_header("Authorization", "%s %s" % (token_type,access_token))⋅⋅⋅
result = urllib2.urlopen(request)
return json.loads(result.read())
def checkthingforfiles(dict1):
tid=dict1['id']
tname=dict1['name']
files=get2json(baseurl+'/things/%s/files'%tid)
if hasfiletype(files):
print tid,tname
print [f['name'] for f in files]
print gettags(tid)
def gettags(tid):
return [tag['name'] for tag in get2json(baseurl+'/things/%s/tags'%tid)]
newest=get2json(baseurl+'/newest/')
for thing in newest:
checkthingforfiles(thing)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment