Repository navigation
Expand file tree
/
Copy pathcreate_project_doc_download_external_url_custom_script.py
More file actions
90 lines (80 loc) · 2.54 KB
/
Copy pathcreate_project_doc_download_external_url_custom_script.py
File metadata and controls
90 lines (80 loc) · 2.54 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
81
82
83
84
85
86
87
88
89
90
import requests
from oauthlib.oauth2 import BackendApplicationClient
from requests_oauthlib import OAuth2Session
import os
import json
import sys
os.environ['OAUTHLIB_INSECURE_TRANSPORT'] = '1'
baseUrl = sys.argv[1]
client_id = sys.argv[2]
client_secret = sys.argv[3]
teamId = sys.argv[4]
documentSize = int(sys.argv[5])
url = baseUrl + "/graphql"
client = BackendApplicationClient(client_id=client_id)
oauth = OAuth2Session(client=client)
token = oauth.fetch_token(token_url= baseUrl + '/api/oauth/token', client_id=client_id,
client_secret=client_secret)
with open('options-simple.json', 'r') as file:
optionsString = file.read()
options = json.loads(optionsString)
with open('create_project_doc.json', 'r') as file:
operationsString = file.read()
operations = json.loads(operationsString)
operations["variables"]["input"]["teamId"] = str(teamId)
# externalImportableUrl will allow datasaur to download the files from specified url
for x in range(documentSize):
idx = x + 1
if x == 0:
document = {
"name": "littleprince.txt",
"fileName": "littleprince.txt",
"externalImportableUrl": "https://vulcan-prod.s3.amazonaws.com/files/gitbook/littleprince.txt",
"docFileOptions": {
"customHeaderColumns": [
{
"name": "Document",
"displayed": True,
"labelerRestricted": False,
}
],
"firstRowAsHeader": True
},
"settings" : {
"questions" : {
"name": "Q1",
"label": "Question 1",
"required": False,
"type": "HIERARCHICAL_DROPDOWN",
"config" : {
"multiple": False,
"options": options,
},
}
}
}
else:
document = {
"name": "littleprince" + str(idx) + ".txt",
"fileName": "littleprince" + str(idx) + ".txt",
"externalImportableUrl": "https://vulcan-prod.s3.amazonaws.com/files/gitbook/littleprince.txt",
"docFileOptions": {
"customHeaderColumns": [
{
"name": "Document",
"displayed": True,
"labelerRestricted": False,
}
],
"firstRowAsHeader": True
},
}
operations["variables"]["input"]["documents"].append(document)
payload = json.dumps(operations)
headers = {
'Authorization': 'Bearer ' + token['access_token'],
'Content-Type': 'application/json'
}
response = requests.request("POST", url, headers=headers, data = payload)
jsonResponse = json.loads(response.text.encode('utf8'))
print(json.dumps(jsonResponse, indent=1))