Created
October 20, 2016 00:08
-
-
Save 5nyper/18cf0891e8c00ff2d7cbfdbfdca83e26 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) { | |
var exits = fs.existsAsync('users/' + email + '/' + userid).then(function(exists) { | |
var mkdir = fs.mkdirAsync('users/' + email + '/' + userid).catch(function(error) { | |
console.log(error) | |
}) | |
var readData = fs.readFileAsync("data/data.json", "utf-8").then(function(contents) { | |
var writeNew = fs.writeFileAsync('users/' + email + '/' + userid + '/instagram.json', contents).then(() => { | |
initInsta(email, userid) | |
}).catch(function(error) { | |
return new Error(error) | |
}) | |
console.log("insta folder created"); | |
}); | |
}).catch(() => { | |
console.log("File Exists") | |
}) | |
} | |
function initInsta(email, userid) { | |
console.log("Initializing Data") | |
fs.readFileAsync('users/' + email + '/' + userid + '/instagram.json', "utf-8").then(function(data) { | |
data = JSON.parse(data); | |
request(("https://instagram.com/" + userid + "/?__a=1")).then(function(response) { | |
var res = JSON.parse(response.body); | |
var result = res.user.followed_by.count | |
console.log(result) | |
data.STARTING_COUNTS[0].DAY = result; | |
data.STARTING_COUNTS[0].WEEK = result; | |
data.STARTING_COUNTS[0].MONTH = result; | |
console.log("TEST1: ") | |
console.log(data) | |
fs.writeFileAsync('users/' + email + '/' + userid + '/instagram.json', JSON.stringify(data)).then(() => { | |
fs.readFileAsync('users/' + email + '/' + userid + '/instagram.json', "utf-8").then(function(contents) { | |
console.log("TEST2: ") | |
console.log(JSON.parse(contents)) | |
}).catch(function(error) { | |
console.log(error) | |
}) | |
}).catch(function(error) { | |
console.log(error) | |
}) | |
}) | |
}).catch(function (error) { | |
console.log(error) | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment