Last active
October 12, 2020 07:38
-
-
Save seanmars/909d3beaa9b4329011b4322bcf9e43cd to your computer and use it in GitHub Desktop.
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
const express = require('express') | |
const app = express() | |
const port = 3000 | |
const delay = (s) => { | |
return new Promise(resolve => { | |
setTimeout(resolve, s); | |
}); | |
} | |
class Test { | |
async fetchValue(value) { | |
await delay(3000); | |
return `Hello, ${value}`; | |
} | |
} | |
let t = new Test(); | |
app.get('/', async (req, res) => { | |
var v = await t.fetchValue('12345'); | |
res.send(v); | |
}) | |
app.listen(port, () => { | |
console.log(`Example app listening at http://localhost:${port}`) | |
}) |
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
const gis = require("g-i-s"); | |
const generateRandomAnimalName = require("random-animal-name-generator"); | |
const randomCountryName = require("random-country-name"); | |
const download = require("image-downloader"); | |
const asyncGis = (opts) => { | |
return new Promise((resolve, reject) => { | |
gis(opts, (error, result) => { | |
if (error) { | |
reject(); | |
} else { | |
resolve(result); | |
} | |
}); | |
}); | |
}; | |
class webprocess { | |
async grab() { | |
async function logResults(error, results) { | |
if (error) { | |
console.log(error); | |
} else { | |
var rndInt = getRandomInt(3); | |
var imgUrl = results[rndInt].url; | |
console.log(imgUrl); | |
const options = { | |
url: imgUrl, | |
dest: "images", | |
}; | |
await download | |
.image(options) | |
.then(({ filename }) => { | |
console.log("Saved to", filename); // saved to /path/to/dest/image.jpg | |
}) | |
.catch((err) => console.error(err)); | |
var content = { | |
url: imgUrl, | |
caption: rndInt, | |
}; | |
} | |
console.log(content); | |
return content; | |
} | |
function getRandomInt(max) { | |
return Math.floor(Math.random() * Math.floor(max)); | |
} | |
var animalNmae = await generateRandomAnimalName(); | |
console.log(animalNmae); | |
var countryName = await randomCountryName.random(); | |
console.log(countryName); | |
var opts_location = { | |
searchTerm: `pollution ${countryName}`, | |
}; | |
var opts_animal = { | |
searchTerm: `pollution ${animalNmae}`, | |
}; | |
console.log(`start location...`); | |
let result_location = await asyncGis(opts_location).catch(error =>{ | |
console.log(error); | |
}); | |
console.log(result_location); | |
console.log('end opts_location...'); | |
console.log(`start animal...`); | |
let result_animal = await asyncGis(opts_animal).catch(error =>{ | |
console.log(error); | |
}); | |
console.log(result_animal); | |
console.log('end opts_animal...'); | |
} | |
} | |
module.exports = webprocess; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment