├── README.md ├── Procfile ├── .gitignore ├── app.json ├── public └── stylesheets │ └── main.css ├── views ├── pages │ ├── thanks.ejs │ ├── index.ejs │ └── response.ejs └── partials │ └── header.ejs ├── package.json └── index.js /README.md: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /Procfile: -------------------------------------------------------------------------------- 1 | web: node index.js 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | .env 3 | Dockerfile 4 | docker-compose.yml 5 | -------------------------------------------------------------------------------- /app.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Name Grabber", 3 | "description": "Helps you get Instagram usernames" 4 | } 5 | -------------------------------------------------------------------------------- /public/stylesheets/main.css: -------------------------------------------------------------------------------- 1 | body { 2 | text-align: center; 3 | background-color: #EFF4FF; 4 | font-size: 16px; 5 | } 6 | 7 | .main { 8 | margin: 40px auto; 9 | max-width: 500px; 10 | } 11 | 12 | input { 13 | text-align: center; 14 | } 15 | 16 | .prompt { 17 | } 18 | -------------------------------------------------------------------------------- /views/pages/thanks.ejs: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | <% include ../partials/header.ejs %> 5 | 6 | 7 |
8 |

Name Grabber

9 |

Get notified when an Instagram username becomes available.

10 |
11 |

Thanks! We'll email you when the username @<%= username %> becomes available.

12 |
13 |
14 | 15 | 16 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "name-grabber", 3 | "version": "0.0.1", 4 | "description": "Helps you get Instagram usernames.", 5 | "main": "index.js", 6 | "scripts": { 7 | "start": "node index.js" 8 | }, 9 | "dependencies": { 10 | "body-parser": "^1.14.1", 11 | "ejs": "2.3.3", 12 | "express": "4.13.3", 13 | "mongodb": "^2.0.46", 14 | "mongoskin": "^2.0.3", 15 | "nodemailer": "^1.8.0", 16 | "nodemon": "^1.7.1", 17 | "request": "^2.65.0" 18 | }, 19 | "engines": { 20 | "node": "0.12.7" 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /views/pages/index.ejs: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | <% include ../partials/header.ejs %> 5 | 6 | 7 |
8 |

Name Grabber

9 |

Get notified when an Instagram username becomes available.

10 |
11 |
12 |

Enter your desired username:

13 |
14 | 15 |
16 | 17 |
18 |
19 |
20 | 21 | 22 | -------------------------------------------------------------------------------- /views/pages/response.ejs: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | <% include ../partials/header.ejs %> 5 | 6 | 7 |
8 |

Name Grabber

9 |

Get notified when an Instagram username becomes available.

10 |
11 | <% if (exists) { %> 12 |

The username @<%= username %> is taken.

13 |

Enter your email to be notified when it becomes available.

14 |
15 |
16 | 17 |
18 | 19 | 20 |
21 | <% } else { %> 22 |

The username <%= username %> is free, so just register it using the app.

23 | <% } %>
24 |
25 | 26 | 27 | -------------------------------------------------------------------------------- /views/partials/header.ejs: -------------------------------------------------------------------------------- 1 | Name Grabber 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 14 | 16 | 17 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | var config = { 2 | checkInterval: (12*60) // Interval to ping Instagram for usernames, in minutes 3 | } 4 | 5 | var express = require('express'); 6 | var request = require('request'); 7 | var bodyParser = require('body-parser'); 8 | var db = require('mongoskin').db(process.env.DATABASE_URL); 9 | var nodemailer = require('nodemailer'); 10 | var app = express(); 11 | 12 | app.set('port', (process.env.PORT || 5000)); 13 | 14 | app.use(express.static(__dirname + '/public')); 15 | 16 | // for parsing POST requests 17 | app.use(bodyParser.json()); // support json encoded bodies 18 | app.use(bodyParser.urlencoded({ extended: true })); // support encoded bodies 19 | 20 | // views is directory for all template files 21 | app.set('views', __dirname + '/views'); 22 | app.set('view engine', 'ejs'); 23 | 24 | var transporter = nodemailer.createTransport({ 25 | service: 'gmail', 26 | auth: { 27 | user: process.env.NODEMAILER_ADR, 28 | pass: process.env.NODEMAILER_PWD 29 | } 30 | }); 31 | 32 | app.get('/', function (req, res, next) { 33 | // If this is a user query, check for user 34 | if (req.query.username) { 35 | checkForUsername(req.query.username, function(exists) { 36 | res.render('pages/response', { 37 | exists: exists, 38 | username: req.query.username 39 | }); 40 | }); 41 | // or just load the home page 42 | } else { 43 | res.render('pages/index'); 44 | } 45 | }); 46 | 47 | // Handles email submissions 48 | app.post('/email', function(req, res, next) { 49 | // Add email to database 50 | db.collection('users').insertOne( { 51 | username: req.body.username, 52 | email: req.body.email 53 | } ); 54 | // Confirm registration via email 55 | transporter.sendMail({ 56 | from: 'willthefirst@gmail.com', 57 | to: req.body.email, 58 | subject: "Name Grabber is now watching @" + req.body.username + " for you", 59 | html: "

Yo,

You just registered the username @" + req.body.username + " with Name Grabber. I'll send you an email when it becomes available.

Thanks,

Will

" 60 | }, function(err, info) { 61 | if (err) { 62 | console.log(err); 63 | throw err; 64 | } 65 | }); 66 | res.render('pages/thanks', { 67 | username: req.body.username 68 | }); 69 | }); 70 | 71 | // Check Instagram to see if user exists 72 | function checkForUsername(username, cb) { 73 | var url = "https://www.instagram.com/" + username; 74 | var exists = false; 75 | request(url, function(err, res, body) { 76 | if (res.statusCode === 200) { 77 | // If the unsername is taken, update message and ask for user's email 78 | exists = true; 79 | } 80 | cb(exists); 81 | }); 82 | } 83 | 84 | // Checks database 85 | function checkDatabase() { 86 | db.collection('users').find().toArray(function(err, result) { 87 | if (err) { 88 | throw err; 89 | } 90 | var current; 91 | for (var i = 0; i < result.length; i++) { 92 | current = result[i]; 93 | checkForUsername(current.username, function(exists) { 94 | if(!exists) { 95 | // Notify the user via his email 96 | transporter.sendMail({ 97 | from: 'willthefirst@gmail.com', 98 | to: current.email, 99 | subject: '@' + current.username + ' is now available on Instagram!', 100 | html: '

Yo,

The username @' + current.username + ' is now available on Instagram! Claim it using the Instagram app.

Thanks,

Will

' 101 | }, function(err, info) { 102 | if (err) { 103 | console.log(err); 104 | throw err; 105 | } 106 | }); 107 | // Remove this user from the DB 108 | db.collection('users').remove( { username : current.username } ) 109 | } else { 110 | // User still unavailable; 111 | } 112 | }) 113 | } 114 | }); 115 | } 116 | 117 | // Check stuff every 60 minutes 118 | var checkStuff = setInterval(function(str1, str2) { 119 | checkDatabase(); 120 | }, (config.checkInterval * 60 * 1000) ); 121 | 122 | app.listen(app.get('port'), function() { 123 | console.log('Node app is running on port', app.get('port')); 124 | }); 125 | --------------------------------------------------------------------------------