-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathcreate_document.py
More file actions
executable file
·80 lines (72 loc) · 2.4 KB
/
Copy pathcreate_document.py
File metadata and controls
executable file
·80 lines (72 loc) · 2.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#!/usr/bin/env python3
from __future__ import print_function
import os
import rspace_client
# Parse command line parameters
client = rspace_client.utils.createELNClient()
# Creating a new Basic document in Api Inbox folder
new_document = client.create_document(
name="Python API Example Basic Document",
tags=["Python", "API", "example"],
fields=[{"content": "Some example text"}],
)
print(
"New document was successfully created with global ID {}".format(
new_document["globalId"]
)
)
# Creating a document in a specific Workspace folder:
folder = client.create_folder("subfolder")
new_document2 = client.create_document(
name="Basic Document in subfolder",
parent_folder_id=folder["id"],
fields=[{"content": "Some example text"}],
)
print(
"Created document id [{}] in folder id [{}]".format(
new_document2["id"], folder["id"]
)
)
# Uploading a file to the gallery
with open(os.sep.join(["resources", "2017-05-10_1670091041_CNVts.csv"]), "rb") as f:
new_file = client.upload_file(f, caption="some caption")
print(
'File "{}" was uploaded as {} ({})'.format(
f.name, new_file["name"], new_file["globalId"]
)
)
with open(
os.sep.join(["resources", "2017-05-10_1243111032_GT_DetailedTS_E.csv"]), "rb"
) as f2:
print("updating file with a new version")
updatedFile = client.update_file(f2, new_file["id"])
print(
'File "{}" has replaced "{}" and is now version {}'.format(
updatedFile["name"], new_file["name"], updatedFile["version"]
)
)
# Editing the document to link to the uploaded file
updated_document = client.update_document(
new_document["id"],
fields=[
{
"content": "Some example text. Link to the uploaded file: <fileId={}>".format(
new_file["id"]
)
}
],
)
print("Document has been updated to link to the uploaded file.")
# Creating a document to show deletion
print("Creating a new document which will be deleted")
new_document2 = client.create_document(
name="Python API Document for deletion",
tags=["Python", "API", "example"],
fields=[{"content": "Some example text"}],
)
deletedDoc = client.delete_document(new_document2["id"])
print("Document {} was deleted".format(new_document2["id"]))
print(
"You can see or restore the deleted document in web application in MyRSpace->Deleted Items"
)
print("Finished")