From 8fd2ea5dbd4fdef68b54a492607998f761bbc129 Mon Sep 17 00:00:00 2001 From: Carson Fleming Date: Sun, 17 Sep 2017 17:44:10 -0400 Subject: [PATCH] This is the code used on club night (minor tweaks) --- .gitignore | 2 ++ README.md | 29 +++++++++++++++++++++++++++++ collect.js | 38 ++++++++++++++++++++++++++++++++++++++ validate.js | 18 ++++++++++++++++++ 4 files changed, 87 insertions(+) create mode 100644 .gitignore create mode 100644 README.md create mode 100644 collect.js create mode 100644 validate.js diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..bd6d055 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +*.swp +*.txt diff --git a/README.md b/README.md new file mode 100644 index 0000000..27f56ab --- /dev/null +++ b/README.md @@ -0,0 +1,29 @@ +# ECC Club Night Tool +This is the program we used to do club night sign-ups for 2017-18. It may or +may not be used in the future but I just wanted to leave it here in case +anyone wants to use it in the future. Written in NodeJS. + +## Dependencies +Use: +```shell +npm install [package] +``` +Packages: +- readline +- fs (usually built-in) +- colors + +## Usage +This tool runs in the console. +```shell +clear +node collect.js [list file] +``` + +## Validation +To make sure nobody trolled you on the signups, validate.js tests for valid +Exeter email addresses, and prints any offending text with the line number +attached. +```shell +node validate.js [list file] +``` diff --git a/collect.js b/collect.js new file mode 100644 index 0000000..b65e1ac --- /dev/null +++ b/collect.js @@ -0,0 +1,38 @@ +const readline = require('readline'); +const fs = require('fs'); +const colors = require('colors'); +const opts = { + input: process.stdin, + output: process.stdout, + prompt: 'Exeter Email > '.magenta.bold, +}; +const fname = (process.argv.length > 2) ? process.argv[2] : 'ecc-list.txt'; + +let rl = readline.createInterface(opts); +let motd = []; +motd.push('###########################################'); +motd.push('# #'); +motd.push('# Welcome to Exeter Computing Club 2017 #'); +motd.push('# Check out our GitHub: #'); +motd.push('# https://github.com/exeter #'); +motd.push('# #'); +motd.push('###########################################'); +motd.push(''); + +console.log(motd.join('\n').white.bold); +rl.prompt(); + +rl.on('line', (input) => { + let eml = input.trim().toLowerCase(); + if (eml.indexOf('@') == -1) eml += '@exeter.edu'; + fs.appendFileSync(fname, eml+'\n'); + console.log('Thanks! We\'ll send you an email announcing our first meeting.'); + rl.prompt(); +}); +rl.on('close', function () { + console.log('Bye!'); +}); +rl.on('SIGINT', function () { + rl.clearLine(); + rl.prompt(); +}); diff --git a/validate.js b/validate.js new file mode 100644 index 0000000..d05744a --- /dev/null +++ b/validate.js @@ -0,0 +1,18 @@ +const fs = require('fs'); +const colors = require('colors'); +const fname = (process.argv.length > 2) ? process.argv[2] : 'ecc-list.txt'; + +try { + data = fs.readFileSync(fname, 'utf-8'); + let dlist = data.trimRight().split('\n'); + for (let i = 0; i < dlist.length; i++) { + if (!dlist[i].trim().match(/^([a-z0-9]+)@exeter.edu$/i)) { + console.log( + ((i+1) + ': ').red.bold + + dlist[i].trim() + ); + } + } +} catch(e) { + console.error(e.stack); +}