From 9ad4e71992016e912684c551f2cae1c26fe169fa Mon Sep 17 00:00:00 2001 From: Sam Poder <39828164+sampoder@users.noreply.github.com> Date: Wed, 11 Aug 2021 20:39:08 +0800 Subject: [PATCH] Data! Data! Oh the data! --- package.json | 1 + pages/alt.js | 63 +++++++++++++++++++++++++++++++++++++++++++++++----- yarn.lock | 5 +++++ 3 files changed, 63 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index 66b04305..ccc2c66f 100644 --- a/package.json +++ b/package.json @@ -17,6 +17,7 @@ "@mdx-js/loader": "^1.6.22", "@next/mdx": "^11.0.0", "airtable-plus": "^1.0.4", + "country-emoji": "^1.5.6", "framer-motion": "^4.1.17", "globby": "^11.0.4", "lodash": "^4.17.21", diff --git a/pages/alt.js b/pages/alt.js index 1c485117..9c35576d 100644 --- a/pages/alt.js +++ b/pages/alt.js @@ -496,6 +496,7 @@ export default function Page({ dataPieces }) { export async function getStaticProps() { var mojier = require('mojier') + const { flag } = require('country-emoji') let dataPieces = [] let initialBankData = await fetch('https://bank.hackclub.com/stats').then(r => r.json() @@ -620,24 +621,74 @@ export async function getStaticProps() { x => `${packagesText[Math.floor(packagesText.length * Math.random())]} to ${ x.fields['Receiver Country'] - ? (x.fields['Receiver Country'][0]?.split(' ')[0] == 'United' + ? x.fields['Receiver Country'][0]?.split(' ')[0] == 'United' ? 'the ' + x.fields['Receiver Country'][0]?.split('(')[0] - : x.fields['Receiver Country'][0]?.split('(')[0]) + : x.fields['Receiver Country'][0]?.split('(')[0] : 'a hacker' }!` ) .slice(0, 20) - console.log(packagesData) + let clubsData = ( + await fetch( + 'https://api2.hackclub.com/v0.1/Operations/Clubs?select={"sort":[{"field":"Acceptance%20Time","direction":"desc"}]}' + ).then(r => r.json()) + ) + .map( + x => + `${ + flag( + x.fields['Address Country'] + ? x.fields['Address Country'][0] + : 'hgfdhsbuvisulr' + ) === undefined + ? '🚩' + : flag(x.fields['Address Country'][0]) + } New club started ${ + x.fields['Address Country'] + ? x.fields['Address Country'][0]?.split(' ')[0] == 'United' + ? 'in the ' + x.fields['Address Country'][0]?.split('(')[0].trim() + : 'in ' + x.fields['Address Country'][0]?.split('(')[0].trim() + : 'by a hacker' + }!` + ) + .slice(0, 40) + + let meetingsData = ( + await fetch('https://api2.hackclub.com/v0.1/Operations/Clubs').then(r => + r.json() + ) + ) + .map(x => + (x.fields['Meeting sizes'] && x.fields['Address Country']) + ? `📆 A club meeting ${ + x.fields['Address Country'] + ? x.fields['Address Country'][0]?.split(' ')[0] == 'United' + ? 'in the ' + + x.fields['Address Country'][0]?.split('(')[0].trim() + : 'in ' + x.fields['Address Country'][0]?.split('(')[0].trim() + : '' + } of ${ + x.fields['Meeting sizes'][x.fields['Meeting sizes'].length - 1] + } just happened!` + : null + ) + .filter(function (el) { + return el != null + }) + .sort(() => 0.5 - Math.random()) + .slice(0, 8) + + console.log(meetingsData) dataPieces = [ ...newScrapbooks, ...newScrapbookUsers, ...dataPieces, ...reactionsUsed, - ...new Set( - packagesData - ), + ...new Set(packagesData), + ...new Set(clubsData), + ...meetingsData, ...new Set( initialGitHubData.filter(function (el) { return el != null diff --git a/yarn.lock b/yarn.lock index 36aeb20b..33fcab76 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1225,6 +1225,11 @@ cosmiconfig@^6.0.0: path-type "^4.0.0" yaml "^1.7.2" +country-emoji@^1.5.6: + version "1.5.6" + resolved "https://registry.yarnpkg.com/country-emoji/-/country-emoji-1.5.6.tgz#cca1e637f3eac8cd2c3f2f910213d9a521b1307e" + integrity sha512-pSB8OOROfimFc2bcN+H41DuzXYIod/JQ6SgF4pYXkRCm9f8uF1JAJ0vXPhenug6xkpt3Gv33mdypMXB49CJWRA== + create-ecdh@^4.0.0: version "4.0.4" resolved "https://registry.yarnpkg.com/create-ecdh/-/create-ecdh-4.0.4.tgz#d6e7f4bffa66736085a0762fd3a632684dabcc4e"