Commit 9d39d364 authored by Knut Behrends's avatar Knut Behrends
Browse files

improve README and USEGAE.md files

parent 3afae887
......@@ -13,11 +13,17 @@ Take a look at file `src/config.js`.
Update the value for `baseURL` by setting it to the URL of your mDIS that you want to fill with fake-data.
#### Credentials
#### Logging in
Using a Browser, Login via the web interface once.
To use the mDIS REST API, you need credentials.
After successfull login, use the Browser's developer tools (F11 or CTRL+Shift+I) to find the value of the `Authorization` HTTP-header for your login request.
> Do not use a password. Use an "Access Token" instead.
Q: How do I get an Access Token?
A: Using a Browser, Login via the web interface once.
Then, after successful login, use the Browser's developer tools (F11 or CTRL+Shift+I) to find the value of the `Authorization` HTTP-header for your login request.
This will look like this:
`Authorization: "Bearer eQv809NUzP4447eD3Ws4dBwCOFvf0E8I`
......@@ -30,10 +36,13 @@ Enter this into line 1 of `src/config.js`, or export it as a shell environment v
See also "Configuration" section at [bottom of page](#configuration)
TODO: enable login from command-line
## USAGE
### Node v14+ required
Written in Javascript for the Node Platform v14+. You *must* use node v14+, because the JS code internally uses the `?.` 'optional chaining' operator as a shortcut for testing the 'definedness' of nested object properties.
## Using the mDIS REST API
First, look at the `bin/` subdirectory to execute Shell scripts, or enter the `src/` subdirectory to execute Node scripts.
For regular usage, call the scripts from the parent directory.
......@@ -47,7 +56,7 @@ To enable debugging with the Chrome Developer Tools in the shell scripts: Open a
and uncomment line
`#node --inspect-brk --inspect ../src/expedition-inserter.js 1;`
To debug with `.js` files directly, call the node binary on the command line.
To debug the `.js` files directly, call the Node binary on the command line. That means, do not use the `.sh` shellscripts.
-----
......
......@@ -5,17 +5,20 @@
[[ "well" == $(uname -n) ]] && export NODE_PATH=~/code/git/_my/work/dis-datagen/node_modules
# how many expeditions to add
num_expeditions=1 #20
num_expeditions = 1
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" # This loads nvm
nvm use 14
# to connect to mDIS, you must set this env var
# export token="2Wh0EhUH8PSYpF6XeBioK8ddTVuXO4i6"
# or set its value manually, in config.js
for i in $(seq 1 $num_expeditions) ; do
echo expedition $i of $num_expeditions;
# insert 1 expedition synchronously,
# as a copy of the "previous" expedition
#node --inspect-brk --inspect ../src/expedition-inserter.js 1;
node src/expedition-inserter.js 1;
node src/expedition-inserter.js 1;
done
\ No newline at end of file
let token = process.env.token || "Y2riMvNQIO8VNj4Cubv6X4DN-V85bmto"
let token = process.env.token || "vlR4K7hb6YDoQGddGSuVoWe0N2g1VFr8"
let config = {
token: token,
endpoint: {
// baseURL: "https://internal.rundis.com/",
// baseURL: "https://jet.rundis.com/",
//baseURL: "http://172.17.0.1:8888/",
baseURL: "https://data.icdp-online.org/mdis/internal/",
// baseURL: "https://data.icdp-online.org/mdis/internal/",
baseURL: "https://data.icdp-online.org/mdis/generic/",
timeout: 3000,
headers: {
"Authorization": `Bearer ${token}`,
......
......@@ -18,15 +18,46 @@ for (let i = 0; i < num_expeditions_to_insert; i++) {
// ? new Date(Date.parse(prev_expedition.item_ondeck)) // convert string to date
// : new Date()
let prev_expedition_info = {}
const columns = [
"id",
"program_id",
"name",
"expedition",
"acr",
"chief_scientist",
"start_date",
"end_date",
"comment",
"country",
"rock_classification",
"geological_age",
"location_description",
"funding_agency",
"name_alternative",
"scientist_contact",
"objectives",
"keywords"
]
finder
.find_item(expedition_url)
.then((x) => {
prev_expedition_info = x
if (typeof x != "object"){
x = {}
x.item = {
"name" : "E1",
"expedition": 1111,
"acr": "Exp01",
"chief_scientist": "ich",
"start_date": "2020-06-08 10:00:00",
}
}
})
.catch((error) => console.dir(error, { depth: 2 }))
.then((result) => {
//console.dir(prev_expedition, { depth: 2 })
// use prev_expedition as a template for the next record, and overwrite some values
if(! prev_expedition_info.item) prev_expedition_info.item = ""
let prev_expedition = {}
prev_expedition = Object.assign(
prev_expedition,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment