Skip to content

Commit

Permalink
Merge pull request #1237 from mullwar/master
Browse files Browse the repository at this point in the history
Update "People in Space" plugin to v1.1
  • Loading branch information
gingerbeardman committed Jun 14, 2019
2 parents 95de1fd + 476c076 commit 42d775d
Showing 1 changed file with 38 additions and 26 deletions.
64 changes: 38 additions & 26 deletions Science/people-in-space.6h.js
Original file line number Diff line number Diff line change
@@ -1,39 +1,45 @@
#!/usr/bin/env /usr/local/bin/node

// <bitbar.title>People In Space</bitbar.title>
// <bitbar.version>v1.0</bitbar.version>
// <bitbar.version>v1.1</bitbar.version>
// <bitbar.author>Mullwar</bitbar.author>
// <bitbar.author.github>mullwar</bitbar.author.github>
// <bitbar.desc>How many people are in Space right now?</bitbar.desc>
// <bitbar.image>http://i.imgur.com/i9biB3R.png</bitbar.image>
// <bitbar.dependencies>node</bitbar.dependencies>
// <bitbar.abouturl>https://github.com/mullwar/my-bitbar-plugins</bitbar.abouturl>
// <bitbar.abouturl>https://github.com/mullwar/bitbar-plugins</bitbar.abouturl>

"use strict";

/* jshint -W100 */
/* jshint esversion: 6 */

const https = require('https');

const ENDPOINT = 'https://www.howmanypeopleareinspacerightnow.com/peopleinspace.json';

var http = require('http');

function request(host, path) {
return new Promise(function(resolve, reject) {
http.request({
host: host,
path: path,
method: 'GET'
}, function(resp) {
var body = '';
resp.setEncoding('utf8');
resp.on('data', function(chunk) {
body += chunk;
function request(endpoint) {
return new Promise((resolve, reject) => {
https.get(endpoint, (res) => {
const body = [];
res.setEncoding('utf8');
res.on('data', (data) => body.push(data));
res.on('end', () => {
try {
resolve(JSON.parse(body.join()));
} catch (error) {
reject(error);
}
});
resp.on('end', function() {
resolve(JSON.parse(body));
res.on('error', (error) => {
reject(error);
});
}).end();
});
});
}

function flag(name) {
switch(name.toLowerCase()) {
function getEmojiFlag(name) {
switch (name.toLowerCase()) {
case 'russia': return '๐Ÿ‡ท๐Ÿ‡บ';
case 'usa': return '๐Ÿ‡บ๐Ÿ‡ธ';
case 'italy': return '๐Ÿ‡ฎ๐Ÿ‡น';
Expand All @@ -48,11 +54,17 @@ function flag(name) {
}
}

request('www.howmanypeopleareinspacerightnow.com', '/space.json').then(function(body) {
console.log('๐Ÿ‘จ๐Ÿปโ€๐Ÿš€ ' + body.number + '\n---');
body.people.map(function(person) {
console.log(flag(person.country) + ' ' + person.name + '| href=${person.bio} color=black');
console.log(person.title + ' โ€“ ' + person.launchdate.split('-').reverse().join('.'));
console.log('---');
request(ENDPOINT).then((json) => {
console.log(`๐Ÿ‘จ๐Ÿปโ€๐Ÿš€ ${json.number}`);
console.log(`---`);
json.people.forEach((person) => {
console.log(`${getEmojiFlag(person.country)} ${person.name} | href=${person.biolink} color=black`);
console.log(`${person.title} โ€“ ${person.launchdate.split('-').reverse().join('.')}`);
console.log(`---`);
});
}).catch((error) => {
console.log(`๐Ÿ‘จ๐Ÿปโ€๐Ÿš€ ?\n---`);
console.log(`Houston, we have an error! | color=red`);
console.log(`---`);
console.log(error);
});

0 comments on commit 42d775d

Please sign in to comment.