Exemple #1
0
def upload_file(filename, email):
	access_token = db_util.fetch_token(email,label)
	val = open(filename, 'rb').read()
	basename = os.path.basename(filename)
	url = 'https://api-content.dropbox.com/1/files_put/dropbox/%(basename)s?access_token=%(access_token)s' % locals()
	r = requests.put(url, data = open(filename, 'rb').read()).json()
	return construct_file_record(r)
Exemple #2
0
def upload_file(filename,email):
    access_token = db_util.fetch_token(email,label)
    url = 'https://upload.box.com/api/2.0/files/content?access_token=%(access_token)s' % locals()
    r = requests.post(url, files={'file': open(filename, 'rb') } ,data = { 'parent_id': '0' }).json()
    try:
        return construct_file_record(r['entries'][0])
    except:
        return {}
def list_files(email,folder):
	access_token = db_util.fetch_token(email,label)
	url = "https://api.dropbox.com/1/metadata/dropbox/%(folder)s?access_token=%(access_token)s" % locals()
	response = requests.get(url).json()
	listFiles = []
	for record in response["contents"]:
		listFiles.append(construct_file_record(record))
	return listFiles
Exemple #4
0
def upload_file(filename, email):
    access_token = db_util.fetch_token(email, label)
    val = open(filename, 'rb').read()
    basename = os.path.basename(filename)
    url = 'https://api-content.dropbox.com/1/files_put/dropbox/%(basename)s?access_token=%(access_token)s' % locals(
    )
    r = requests.put(url, data=open(filename, 'rb').read()).json()
    return construct_file_record(r)
Exemple #5
0
def upload_file(filename,email):
	access_token = db_util.fetch_token(email,label)
	url = 'https://www.googleapis.com/upload/drive/v2/files?uploadType=media&access_token=%(access_token)s' % locals()
	r = requests.post(url, data = open(filename, 'rb').read())
	file_id = json.loads(r.text)['id']
	url = "https://www.googleapis.com/drive/v2/files/%(file_id)s?access_token=%(access_token)s" % locals()
	r = requests.put(url, data = json.dumps({'title': os.path.basename(filename)}), headers = {'Content-Type': "application/json"}).json()
	return construct_file_record(r)
Exemple #6
0
def download_file(file_id,email):
	access_token = db_util.fetch_token(email,label)
	raw_data = requests.get("https://www.googleapis.com/drive/v2/files/%(file_id)s?access_token=%(access_token)s" % locals()).json()
	filename = os.path.join('/tmp', raw_data.get('title', 'file'))
	f = open(filename, 'w')
	data = requests.get('%s&access_token=%s' % (raw_data['downloadUrl'], access_token))
	f.write(data.content)
	f.close()
	return filename
Exemple #7
0
def download_file(file_id, email):
    access_token = db_util.fetch_token(email,label)
    file_id = urllib.unquote_plus(file_id.replace('ZZZZZ', '%'))
    raw_data = requests.get("https://api-content.dropbox.com/1/files/dropbox%(file_id)s?access_token=%(access_token)s" % locals())
    filename = os.path.join('/tmp', os.path.basename(file_id))
    f = open(filename, 'w')
    f.write(raw_data.content)
    f.close()
    return filename
Exemple #8
0
def list_files(email,folder):
	access_token = db_util.fetch_token(email,label)
	folder = folder if folder else '0'
	url = "https://api.box.com/2.0/folders/%(folder)s/items?access_token=%(access_token)s" % locals()
	response = requests.get(url).json()
	files = []
	for record in response["entries"]:
		files.append(construct_file_record(record))
	return files
Exemple #9
0
def list_files(email, folder):
    access_token = db_util.fetch_token(email, label)
    url = "https://api.dropbox.com/1/metadata/dropbox/%(folder)s?access_token=%(access_token)s" % locals(
    )
    response = requests.get(url).json()
    listFiles = []
    for record in response["contents"]:
        listFiles.append(construct_file_record(record))
    return listFiles
Exemple #10
0
def list_files(email, folder):
    access_token = db_util.fetch_token(email, label)
    folder = folder if folder else '0'
    url = "https://api.box.com/2.0/folders/%(folder)s/items?access_token=%(access_token)s" % locals(
    )
    response = requests.get(url).json()
    files = []
    for record in response["entries"]:
        files.append(construct_file_record(record))
    return files
Exemple #11
0
def list_files(email,folder):
	access_token = db_util.fetch_token(email,label)
	folder = folder if folder else 'root'
	query = urllib.quote("\'%(folder)s\' in parents" % locals())
	url = "https://www.googleapis.com/drive/v2/files?access_token=%(access_token)s&q=%(query)s" % locals()
	response = requests.get(url).json()
	files = []
	for record in response["items"]:
		files.append(construct_file_record(record))
	return files
Exemple #12
0
def list_files(email,folder):
	access_token = db_util.fetch_token(email,label)
	url = "https://apis.live.net/v5.0/me/skydrive/files?access_token=%(access_token)s" % locals()
	if folder:
		url = "https://apis.live.net/v5.0/%(folder)s/files?access_token=%(access_token)s" % locals()
	response = requests.get(url).json()
	listFiles = []
	for record in response["data"]:
		listFiles.append(construct_file_record(record))
	return listFiles
Exemple #13
0
def download_file(file_id, email):
    access_token = db_util.fetch_token(email,label)
    file_id = urllib.unquote_plus(file_id.replace('ZZZZZ', '%'))
    raw_data = requests.get("https://apis.live.net/v5.0/%(file_id)s?access_token=%(access_token)s)" % locals()).json()
    filename = os.path.join('/tmp', raw_data.get('name', 'file'))
    data = requests.get('%s&access_token=%s' % (raw_data['source'], access_token))
    f = open(filename, 'w')
    f.write(data.content)
    f.close()
    return filename
Exemple #14
0
def download_file(file_id, email):
    access_token = db_util.fetch_token(email,label)
    file_id = urllib.unquote_plus(file_id.replace('ZZZZZ', '%'))
    raw_data = requests.get("https://apis.live.net/v5.0/%(file_id)s?access_token=%(access_token)s)" % locals()).json()
    filename = os.path.join('/tmp', raw_data.get('name', 'file'))
    data = requests.get('%s&access_token=%s' % (raw_data['source'], access_token))
    f = open(filename, 'w')
    f.write(data.content)
    f.close()
    return filename
Exemple #15
0
def download_file(file_id, email):
    access_token = db_util.fetch_token(email, label)
    file_id = urllib.unquote_plus(file_id.replace('ZZZZZ', '%'))
    raw_data = requests.get(
        "https://api-content.dropbox.com/1/files/dropbox%(file_id)s?access_token=%(access_token)s"
        % locals())
    filename = os.path.join('/tmp', os.path.basename(file_id))
    f = open(filename, 'w')
    f.write(raw_data.content)
    f.close()
    return filename
Exemple #16
0
def refresh_token(email):
    key = db_util.get_key(label)
    url = 'https://accounts.google.com/o/oauth2/token'
    values = {
            'client_id' :key['client_id'] ,
            'client_secret' : key['client_secret'] ,
            'grant_type' : 'refresh_token' ,
            'refresh_token' : db_util.fetch_token(email,label,"refresh_token")
    }
    response = requests.post(url,data = values).json()
    db_util.save_token(label,'access_token',response['access_token'], email)
Exemple #17
0
def download_file(file_id,email):
	access_token = db_util.fetch_token(email,label,)
	#Get the Raw file content
	response = requests.get("https://api.box.com/2.0/files/%(file_id)s/content?access_token=%(access_token)s" % locals())
	#Get the name of the file
	raw_data = requests.get("https://api.box.com/2.0/files/%(file_id)s?access_token=%(access_token)s" % locals()).json()
	filename = os.path.join('/tmp', raw_data.get('name', 'file'))
	f = open(filename, 'w')
	f.write(response.content)
	f.close()
	return filename
Exemple #18
0
def refresh_token(email):
	key = db_util.get_key(label)
	url = 'https://login.live.com/oauth20_token.srf'
	values = {
		'client_id' :key['client_id'] ,
		'redirect_uri' : key['redirect_uri'] ,
		'client_secret' : key['client_secret'] ,
		'grant_type' : 'refresh_token' ,
		'refresh_token' : db_util.fetch_token(email,label,'refresh_token')
	}
	response = requests.post(url,data = values).json()
	db_util.save_token(label,'access_token',response['access_token'], email)
	db_util.save_token(label,'refresh_token',response['refresh_token'], email)
Exemple #19
0
def refresh_token(email):
	key = db_util.get_key(label)
	url = 'https://login.live.com/oauth20_token.srf'
	values = {
		'client_id' :key['client_id'] ,
		'redirect_uri' : key['redirect_uri'] ,
		'client_secret' : key['client_secret'] ,
		'grant_type' : 'refresh_token' ,
		'refresh_token' : db_util.fetch_token(email,label,'refresh_token')
	}
	response = requests.post(url,data = values).json()
	db_util.save_token(label,'access_token',response['access_token'], email)
	db_util.save_token(label,'refresh_token',response['refresh_token'], email)
Exemple #20
0
def upload_file(filename, email):
    access_token = db_util.fetch_token(email, label)
    url = 'https://upload.box.com/api/2.0/files/content?access_token=%(access_token)s' % locals(
    )
    r = requests.post(url,
                      files={
                          'file': open(filename, 'rb')
                      },
                      data={
                          'parent_id': '0'
                      }).json()
    try:
        return construct_file_record(r['entries'][0])
    except:
        return {}
Exemple #21
0
def download_file(file_id, email):
    access_token = db_util.fetch_token(
        email,
        label,
    )
    #Get the Raw file content
    response = requests.get(
        "https://api.box.com/2.0/files/%(file_id)s/content?access_token=%(access_token)s"
        % locals())
    #Get the name of the file
    raw_data = requests.get(
        "https://api.box.com/2.0/files/%(file_id)s?access_token=%(access_token)s"
        % locals()).json()
    filename = os.path.join('/tmp', raw_data.get('name', 'file'))
    f = open(filename, 'w')
    f.write(response.content)
    f.close()
    return filename
Exemple #22
0
def upload_file(filename, email):
	access_token = db_util.fetch_token(email,label)
	url = 'https://apis.live.net/v5.0/me/skydrive/files?access_token=%(access_token)s' % locals()
	uploaded_file = requests.post(url, files={'file': open(filename, 'rb')}).json()['id']
	r = requests.get("https://apis.live.net/v5.0/%(uploaded_file)s?access_token=%(access_token)s)" % locals()).json()
	return construct_file_record(r)
Exemple #23
0
def upload_file(filename, email):
	access_token = db_util.fetch_token(email,label)
	url = 'https://apis.live.net/v5.0/me/skydrive/files?access_token=%(access_token)s' % locals()
	uploaded_file = requests.post(url, files={'file': open(filename, 'rb')}).json()['id']
	r = requests.get("https://apis.live.net/v5.0/%(uploaded_file)s?access_token=%(access_token)s)" % locals()).json()
	return construct_file_record(r)