Skip to content

Instantly share code, notes, and snippets.

@pierreant-p
Created February 1, 2014 18:48
Show Gist options
  • Save pierreant-p/8756736 to your computer and use it in GitHub Desktop.
Save pierreant-p/8756736 to your computer and use it in GitHub Desktop.
# easy_install poster
import datetime
import threading
from poster.encode import multipart_encode
from poster.streaminghttp import register_openers
import urllib2
import json
import base64
register_openers()
def upload():
path="./"
filename="airboat.obj"
description="Test of the api with a simple model"
token_api="TOKEN"
title="A big object"
tags="test collada glasses"
private=0
password=""
url="https://api.sketchfab.com/v1/models"
data = {
'title': title ,
'description': description,
'fileModel': open(path+filename),
'filenameModel': filename,
'tags': tags,
'token': token_api,
'private': private,
'password': password
}
datamulti, headers = multipart_encode(data)
request = urllib2.Request(url, datamulti, headers)
try:
print urllib2.urlopen(request).read()
except urllib2.HTTPError as e:
print 'an error occured :('
print e.code
print e.read()
# upload in the background using multi-threading
# to upload in the same thread just call upload()
class AsyncUpload(threading.Thread):
def __init__(self):
threading.Thread.__init__(self)
def run(self):
upload()
for i in range(0, 1):
AsyncUpload().start()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment