Ejemplo n.º 1
0
def send_data_all(pieces):
    groupby_semesters = {}
    for piece in pieces:
        groupby_semesters.setdefault(piece['semester'], []).append(piece)

    box_client = DevelopmentClient()

    for semester, pieces in groupby_semesters.items():
        box_input_folder_id = BOX_FOLDER_ID_DICT[semester]
        send_data(pieces, box_input_folder_id, semester, semester, box_client=box_client)
Ejemplo n.º 2
0
def send_data(pieces, box_input_folder_id, collection_name, semester_tag, box_client=None):
    kwargs = {}
    print('BOX', end=' ')
    kwargs['pieces'] = pieces
    kwargs['semester_tag'] = semester_tag
    kwargs['box_folder_id'] = box_input_folder_id
    kwargs['box_client'] = box_client or DevelopmentClient()
    coll = get_or_make_collection(collection_name)
    kwargs['coll_id'] = coll['key']

    kwargs.update(sort_box_folders(**kwargs))
    kwargs.update(meta_to_zot(**kwargs))
    kwargs.update(files_to_zot(**kwargs))
Ejemplo n.º 3
0
def get_auth_box_client():
    with open('private.json', 'r') as f:
        auth = json.loads(f.read())['box']

    option = input(
        'Type "1" to pass a developer token, or anything else to authenticate with OAUTH 2\n>'
    )
    if option == "1":
        token = input("Developer token:\n>")
        oauth = RedisManagedOAuth2(client_id=auth['client-id'],
                                   client_secret=auth['client-secret'],
                                   access_token=token,
                                   unique_id='foo')
        return DevelopmentClient(oauth=oauth)
    else:
        oauth = RedisManagedOAuth2(client_id=auth['client-id'],
                                   client_secret=auth['client-secret'],
                                   unique_id='foo')
        auth_url, csrf = oauth.get_authorization_url('http://localhost')
        print("URL:\n" + auth_url)
        code = input('Provide the Authorization Code\n>')
        return Client(oauth)
Ejemplo n.º 4
0
            return ""
        return list(
            filter(
                None,
                list(map(lambda step: step.carbon_source,
                         sample.growing_steps))))[0]
    else:
        return ""


# Get a handle to MDF Client Connect
mdfcc = MDFConnectClient(test=True, service_instance="dev")

# This will prompt for a developer Token from Box
# See https://developer.box.com/docs/authenticate-with-developer-token
client = DevelopmentClient()

# Download a hardcoded, specific folder from box for now
mdf_folder = client.folder("50410951565").get()

staging_folder = client.folder("59557678760").get()

filepath = "../data"
var_map = pd.read_csv(os.path.join(filepath, 'varmap2.csv')).to_dict()
data = pd.read_csv(os.path.join(filepath,
                                'recipe_2018_11_26.csv')).iloc[:-1, :]

col_names = data.columns

for i in range(data.shape[0]):
    s = sample()
Ejemplo n.º 5
0
from boxsdk import DevelopmentClient
import requests

client = DevelopmentClient()

file_path = r'D:\Jos\Bureaublad\Jonas\Projects\Github\Python\Note Automation\box api key.txt'
file_name = 'Test file'
folder_id = '90792190620'

box_file = client.folder(folder_id).upload(file_path, file_name)
Ejemplo n.º 6
0
import requests
import boxsdk
from boxsdk import DevelopmentClient
import xlrd
from boxsdk import OAuth2, Client
import pickle
import os
import json
import sys
client = DevelopmentClient()
user = client.user().get()
#mapwYH46MYdvRR47j3YmtxhN1V7tdbTA

entrada = sys.argv[1:]
workbook = xlrd.open_workbook(entrada[0])
Folha1 = workbook.sheet_by_index(0)
ABSOLUTE_PATH = os.getcwd()
os.mkdir(ABSOLUTE_PATH + '\\Resultados')
for i in range(1, Folha1.nrows):
    nomeArq = Folha1.cell_value(i, 0)
    nomeArq.replace(' ', '')
    items = client.search().query(query='"' + nomeArq + '"',
                                  file_extensions=['pdf'],
                                  content_types='name',
                                  ancestor_folder_ids=31436627801,
                                  type='file')
    data_temp = ''
    idanterior = ''
    idRecente = ''
    for item in items:
        if ((nomeArq + '-' in item.name) or (nomeArq + '-' in item.name)):
Ejemplo n.º 7
0
def list_all_files(folder, delete_empty=True):
    out = []
    items = folder.get_items()
    for item in items:
        if item._item_type == 'file':
            out.append(item)
        elif item._item_type == 'folder':
            out.extend(list_all_files(item))
    if len(out) == 0:
        folder.delete(recursive=False)
    return out


if __name__ == '__main__':
    client = DevelopmentClient()
    folder = client.folder(FOLDER_ID)

    files = list_all_files(folder)
    files_dict = {f.name: f for f in files}
    # Ignore zip files..
    files_names = [f.name for f in files if not f.name.endswith('.zip')]

    subfolders_dict = {
        f.name: f
        for f in folder.get_items() if f._item_type == 'folder'
    }

    # matched_files = defaultdict(lambda: [])
    # for f in files:
    #     sha1 = f.file_version.sha1
Ejemplo n.º 8
0
from boxsdk import DevelopmentClient

client = DevelopmentClient()
filename = input("What file do you wish to upload?")

folder_id = '118025580874'
new_file = client.folder(folder_id).upload(filename)
print('File "{0}" uploaded to Box with file ID {1}'.format(
    new_file.name, new_file.id))