Commit 2157bcee authored by Benzakein Jeremy's avatar Benzakein Jeremy

delete unwanted file

parent 6207953c
/*jshint esversion: 6 */
'use strict';
const swapi = require('swapi-node');
const Search = require('azure-cognitiveservices-imagesearch');
const CognitiveServicesCredentials = require('ms-rest-azure').CognitiveServicesCredentials;
exports.getAllPeople = () => {
let peopleCount;
let allpeople = [];
swapi.get('https://swapi.co/api/people/').then((result) => {
peopleCount = result.count;
for (let index = 1; index <= peopleCount + 1; index++) {
swapi.getPerson(index).then((result) => {
allpeople.push(result);
console.log(result.name);
console.log(allpeople.length);
})
.catch(err => {
console.error(index);
console.error(err);
});
}
})
.catch(err => {
console.error(err);
});
return allpeople;
}
exports.getImage = async (query, callback)=>{
const serviceKey = "fedf3a8b769e42c5af770843a2c9746a";
const defaultPic = "https://forums.roku.com/styles/canvas/theme/images/no_avatar.jpg";
let searchTerm = removeAccents(query);
let credentials = new CognitiveServicesCredentials(serviceKey);
let imageSearchClient = new Search.ImageSearchClient(credentials);
let result = defaultPic;
const sendQuery = async () => {
return await imageSearchClient.imagesOperations.search(searchTerm);
};
sendQuery()
.then(imageResults =>{
console.debug(imageResults)
if (imageResults == null || imageResults.value.length == 0) {
console.error("No image results were found.");
}
else {
result = imageResults.value[0].contentUrl;
console.log(result);
}
})
.catch(err => {
console.error(err)
})
.finally(()=> {
return result;
});
};
exports.createRowObject = async (person) => {
let rowObject = {};
const getPic = async (name) =>{
return await getImage(name);
};
getPic(person.name).then(picURL=>{
rowObject.imageURL = picURL;
rowObject.name = person.name;
rowObject.birthYear = person.birth_year;
rowObject.height = person.height;
rowObject.weight = person.mass;
});
return await rowObject;
};
exports.removeAccents = (str)=> {
var accents = 'ÀÁÂÃÄÅàáâãäåÒÓÔÕÕÖØòóôõöøÈÉÊËèéêëðÇçÐÌÍÎÏìíîïÙÚÛÜùúûüÑñŠšŸÿýŽž';
var accentsOut = "AAAAAAaaaaaaOOOOOOOooooooEEEEeeeeeCcDIIIIiiiiUUUUuuuuNnSsYyyZz";
str = str.split('');
var i, x;
for (i = 0; i < str.length; i++) {
if ((x = accents.indexOf(str[i])) != -1) {
str[i] = accentsOut[x];
}
}
return str.join('');
}
\ No newline at end of file
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