Thanks! We'll email you when the username @<%= username %> becomes available.
12 |├── 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 |Get notified when an Instagram username becomes available.
10 |Thanks! We'll email you when the username @<%= username %> becomes available.
12 |Get notified when an Instagram username becomes available.
10 |Get notified when an Instagram username becomes available.
10 |Enter your email to be notified when it becomes available.
14 | 21 | <% } else { %> 22 |The username <%= username %> is free, so just register it using the app.
23 | <% } %>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 | --------------------------------------------------------------------------------