Skip to content

Commit

Permalink
https://github.com/water-fountains/datablue/issues/47
Browse files Browse the repository at this point in the history
  • Loading branch information
Ralf Hauser committed Mar 21, 2020
2 parents dd24534 + 1b23256 commit 972138c
Show file tree
Hide file tree
Showing 8 changed files with 11,874 additions and 14,455 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');
Loading

0 comments on commit 972138c

Please sign in to comment.