Exemplo n.º 1
0
def main():
    conf_path = Path.home().joinpath(gconf.CONFIG_FOLDER)
    conf_file = conf_path.joinpath(CONFIG_FILENAME)

    # create config path
    Path.mkdir(conf_path, exist_ok=True)

    # ask info to user before creating the config file
    server = input(
        "Which elabFTW server will you connect to (e.g. elab.example.org)? "
    )
    token = input(
        "Enter your API access token (create one in user settings on website): "
    )
    verify = input(
        "Verify the certificate? (default: yes) ([yes]/no) "
    )
    veriflag = verify != "no"

    # test the connection
    urlapi = f"https://{server}/api/v1/"
    manager = elabapy.Manager(endpoint=urlapi, token=token, verify=veriflag)
    try:
        manager.get_items_types()
    except HTTPError as e:
        print(e)
        sys.exit(1)

    info = {"endpoint": urlapi, "token": token, "domain_name": server}
    with conf_file.open("w") as f:
        yaml.dump(info, f)
    print(f"Successfully connected, wrote out config file: {conf_file}")
def initialize():
    try:
        with open(configfile) as f:
            config = yaml.load(f, Loader=yaml.FullLoader)
    except Exception:
        print(
            "Unable to find or open config file. Run configure_elabftw first.")
        return

    manager = elabapy.Manager(endpoint=config["endpoint"],
                              token=config["token"])
    return manager
Exemplo n.º 3
0
def initialize():
    try:
        with open(configfile) as f:
            config = yaml.load(f, Loader=yaml.FullLoader)
    except Exception:
        print("Unable to find or open config file. "
              "Run configure_elabftw first.")
        sys.exit(1)
    manager = elabapy.Manager(endpoint=config["endpoint"],
                              token=config["token"])
    try:
        manager.get_items_types()
    except HTTPError as e:
        print(e)
        sys.exit(1)
    return manager
Exemplo n.º 4
0
import sys
import elabapy
import datetime
import operator
import yaml

print("Uploading the .nd file to elabftw. Stay put.")

# add double \ to avoid unicode decode error
workdir = "D:\\Users"
today = datetime.date.today()
kdate = today.strftime('%Y%m%d')
# read config
config = yaml.safe_load(open("config.yml"))
# init manager from elabapy
manager = elabapy.Manager(token=config["token"], endpoint=config["endpoint"])


def getLastNdFile():
    """"
	    Get the path of the latest .nd file saved in Users folder
	"""
    ndFiles = {}
    for dirpath, dirnames, filenames in os.walk(workdir):
        for file in filenames:
            curpath = os.path.join(dirpath, file)
            fileModified = datetime.datetime.fromtimestamp(
                os.path.getmtime(curpath))
            if curpath.endswith('.nd'):
                ndFiles[curpath] = fileModified
    # now we have a dict full of nd files paths
Exemplo n.º 5
0
import elabapy
import datetime

manager = elabapy.Manager(
    endpoint="https://127.0.0.1/api/v1/",
    token=
    "e7bcd146e669745f3918ffde74a7b38910962121a6e67308b71790823ffe2d58beab48e7f2912b05af26",
    verify=False)


def ask(filenames, body=""):
    if (input("Would you like to record this run? [y/N]: ") == 'y'):
        title = input("Enter a title: ")
        make(filenames, title, body)


def make(filenames, title, body):
    response = manager.create_experiment()
    id = int(response['id'])
    print(f"Created experiment with id {id}.")

    params = {
        "title": title,
        "date": datetime.datetime.today().strftime("%Y%m%d"),
        "body": body
    }
    manager.post_experiment(id, params)

    for filename in filenames:
        with open(filename, 'rb') as myfile:
            manager.upload_to_experiment(id, {'file': myfile})