Skip to content

Commit

Permalink
This is the code used on club night (minor tweaks)
Browse files Browse the repository at this point in the history
  • Loading branch information
cflems committed Sep 17, 2017
0 parents commit 8fd2ea5
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*.swp
*.txt
29 changes: 29 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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]
```
38 changes: 38 additions & 0 deletions collect.js
Original file line number Diff line number Diff line change
@@ -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();
});
18 changes: 18 additions & 0 deletions validate.js
Original file line number Diff line number Diff line change
@@ -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);
}

0 comments on commit 8fd2ea5

Please sign in to comment.