Skip to content

Commit

Permalink
Scrypt for updating files from datablue to proxymap
Browse files Browse the repository at this point in the history
  • Loading branch information
stanko committed Mar 11, 2020
1 parent 96c7ef0 commit 1b23256
Show file tree
Hide file tree
Showing 7 changed files with 96 additions and 2,596 deletions.
40 changes: 40 additions & 0 deletions fountain_properties.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Create or update fountain_properties JSON file ('src/assets/fountain_properties.json').
// Command: 'npm run fountain_properties'

const writeFileSync = require('fs').writeFileSync;
const axios = require('axios');
const util = require('util');
const exec = util.promisify(require('child_process').exec);

// API URL.
const apiUrlBeta = 'https://api.beta.water-fountains.org/';
const apiUrlStable = 'https://api.water-fountains.org/';
const apiUrlLocal = 'http://localhost:3000/'; // use in development.

// create fountain_properties.JSON
async function createFountainProperties(filename) {

// use travis branch environment variable if available, because in Travis the git branch is called HEAD by default
const branch = process.env.TRAVIS_BRANCH || (await exec('git rev-parse --abbrev-ref HEAD')).stdout.toString().trim();

const apiUrl = (branch === 'stable') ? apiUrlStable : apiUrlBeta;

let metadataUrl = `${apiUrl}api/v1/metadata/fountain_properties`;

// Get fountain_properties data from server and create file.
axios.get(metadataUrl)
.then(function (response) {
// handle success
const locations = JSON.stringify(response.data, null, 4);

writeFileSync(filename, locations, {encoding: 'utf8'});
})
.catch(function (error) {
// handle error
console.log(error);
});

}

// File save path.
createFountainProperties('src/assets/fountain_properties.json');
40 changes: 40 additions & 0 deletions locations.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Create or update location JSON file ('src/assets/locations.json').
// Command: 'npm run location'

const writeFileSync = require('fs').writeFileSync;
const axios = require('axios');
const util = require('util');
const exec = util.promisify(require('child_process').exec);

// API URL.
const apiUrlBeta = 'https://api.beta.water-fountains.org/';
const apiUrlStable = 'https://api.water-fountains.org/';
const apiUrlLocal = 'http://localhost:3000/'; // use in development.

// create location.JSON
async function createLocationFile(filename) {

// use travis branch environment variable if available, because in Travis the git branch is called HEAD by default
const branch = process.env.TRAVIS_BRANCH || (await exec('git rev-parse --abbrev-ref HEAD')).stdout.toString().trim();

const apiUrl = (branch === 'stable') ? apiUrlStable : apiUrlBeta;

let metadataUrl = `${apiUrl}api/v1/metadata/locations`;

// Get location data from server and create file.
axios.get(metadataUrl)
.then(function (response) {
// handle success
const locations = JSON.stringify(response.data, null, 4);

writeFileSync(filename, locations, {encoding: 'utf8'});
})
.catch(function (error) {
// handle error
console.log(error);
});

}

// File save path.
createLocationFile('src/assets/locations.json');
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
{
"name": "proximap",
"version": "1.0.0",
"license": "SEE LICENSE IN 'COPYING'",
Expand All @@ -13,6 +13,8 @@
"start": "ng serve",
"prebuild": "node git.version.js",
"build": "ng build --prod",
"locations": "node locations.js",
"fountain_properties": "node fountain_properties.js",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e",
Expand All @@ -38,6 +40,7 @@
"@ngx-translate/core": "^10.0.2",
"@ngx-translate/http-loader": "^3.0.1",
"@types/js-md5": "^0.4.2",
"axios": "^0.19.2",
"core-js": "^2.6.5",
"font-awesome": "^4.7.0",
"hammerjs": "^2.0.8",
Expand Down
Loading

0 comments on commit 1b23256

Please sign in to comment.