Created
October 19, 2016 01:32
-
-
Save 5nyper/2f6b0f42136f92499c2ddc42c9a8dc1b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function createInsta(email, userid, cb) { | |
ensureExists(function (error) { | |
if (error) return cb(error); | |
getData(function (error) { | |
if (error) return cb(error); | |
}); | |
}); | |
function ensureExists(cb) { | |
fs.exists('users/' + email + '/' + userid, function (exists) { | |
if (!exists) { | |
fs.mkdir('users/' + email + '/' + userid, function (error) { | |
if (error) return cb(error); | |
fs.readFile("data/data.json", "utf-8",function (error, contents) { | |
if (error) return cb(error); | |
fs.writeFile('users/' + email + '/' + userid + '/instagram.json', contents, function (error) { | |
if (error) return cb(error); | |
console.log("insta folder created"); | |
return cb(); | |
}); | |
}); | |
}); | |
} else { | |
return cb(); | |
} | |
}) | |
} | |
function getData(cb) { | |
console.log("Initializing Data") | |
fs.readFile('users/' + email + '/' + userid + '/instagram.json', "utf-8", function (error, data) { | |
if (error) return cb(error); | |
data = JSON.parse(data); | |
request(("https://instagram.com/" + userid + "/?__a=1"), function(error, response, body) { | |
if (error) return cb(error); | |
var res = JSON.parse(body); | |
var result = res.user.followed_by.count | |
data.STARTING_COUNTS[0].DAY = result; | |
data.STARTING_COUNTS[0].WEEK = result; | |
data.STARTING_COUNTS[0].MONTH = result; | |
console.log(data) | |
fs.writeFile('users/' + email + '/' + userid + '/instagram.json', JSON.stringify(data), function(error) { | |
if (error) return cb(error); | |
console.log("File changed") | |
return cb(null); | |
}); | |
}); | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment