-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add script for new project from JSON
- Loading branch information
Showing
1 changed file
with
64 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import argparse | ||
from datetime import datetime | ||
from os import getenv | ||
from json import load, dumps | ||
from string import ascii_letters,digits | ||
from random import choice | ||
|
||
import requests | ||
from bson.objectid import ObjectId | ||
|
||
import common | ||
from functions import new_project | ||
|
||
|
||
lettersdigits=ascii_letters+digits | ||
|
||
def random_string(n): | ||
my_list = [choice(lettersdigits) for _ in range(n)] | ||
my_str = ''.join(my_list) | ||
return my_str | ||
|
||
help_desc = ("Create a test project in Microreact using a JSON file as input. " | ||
"A data table with fake metadata will be generated automatically. " | ||
"The script is intended to be use directly from a command shell and has not been tested from inside a Docker container." | ||
) | ||
parser = argparse.ArgumentParser(description=help_desc) | ||
parser.add_argument( | ||
"json_file", | ||
help=( | ||
"A JSON file that defines a Microreact project" | ||
) | ||
) | ||
parser.add_argument( | ||
"--project_name", | ||
help="Project name (can be changed later in web interface)", | ||
default=common.USERNAME + '_' + str(datetime.now().isoformat(timespec='seconds')) | ||
) | ||
parser.add_argument( | ||
"--noverify", | ||
help="Do not verify SSL certificate of Microreact host ", | ||
action="store_true" | ||
) | ||
args = parser.parse_args() | ||
|
||
with open(args.json_file, 'r') as f: | ||
json_data = load(f) | ||
|
||
mr_access_token=common.MICROREACT_ACCESS_TOKEN | ||
mr_base_url=common.MICROREACT_BASE_URL | ||
verify = not args.noverify | ||
|
||
url = mr_base_url + '/api/projects/create/?access=private' | ||
rest_response = requests.post( | ||
url, | ||
headers= { | ||
'Content-Type': 'application/json; charset=utf-8', | ||
'Access-Token': mr_access_token | ||
}, | ||
json=json_data, | ||
verify=verify | ||
) | ||
|
||
print(f"HTTP response code: {str(rest_response)}") | ||
print(f"HTTP response content: {rest_response.content}") |