From 096cb8a93f96a424aae56f8dfb9f993abf7bfa59 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Daniel=20Ca=C3=B1on=20Carrero?= Date: Tue, 23 Apr 2019 03:09:38 -0300 Subject: [PATCH] TODO: test implementation --- src/igservice.ts | 7 +++-- src/index.ts | 76 ++++++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 75 insertions(+), 8 deletions(-) diff --git a/src/igservice.ts b/src/igservice.ts index 70bc0c3..9d31310 100644 --- a/src/igservice.ts +++ b/src/igservice.ts @@ -47,7 +47,10 @@ export class IGService { return data.map(e => { return { 'parent': parent, 'child': e.id } }); } - public dataStorage(keyMap: any, data: Array, collectionName: string) { + public dataStorage(keyMap: any = {}, data: Array, collectionName: string) { + return IGService.dataStorage(keyMap, data, collectionName); + } + public static dataStorage(keyMap: any = {}, data: Array, collectionName: string) { return collection(collectionName) .then(collection => collection.insertMany( [...removeKey(data.map(e => Object.assign(e._params, keyMap)), "_session", "account")]) @@ -65,7 +68,7 @@ export class IGService { public login() { return Promise.resolve(IG.Session.create(device, storage, credentials.email, credentials.password)) } - public static login(){ + public static login() { return Promise.resolve(IG.Session.create(device, storage, credentials.email, credentials.password)) } } \ No newline at end of file diff --git a/src/index.ts b/src/index.ts index 7575232..7eb994b 100644 --- a/src/index.ts +++ b/src/index.ts @@ -19,25 +19,57 @@ function handleWithDelay(delayProcess: number = 500, dataSet: Array, han return outData.values } -// let userMedia = user.search('luna2d').then(tempUser => user.userMedia(tempUser.id)) -// userMedia.then(tempMedia => console.log(tempMedia[0])) -// let account = user -// user.account().then((account:any) => user.getAccount(account.id)).then(console.log) +let userMedia = user.search('luna2d').then(tempUser => user.userMedia(tempUser.id)) +userMedia.then(tempMedia => tempMedia.forEach((media: any) => IGService.getEventEmiter().emit("media", media))) +let account = user.account().then((account: any) => + user.getAccount(account.id).then(account => IGService.getEventEmiter().emit("media", account)) +) let followers = user.search("luna2d") .then((account: any) => user.getUserFollowers(account.id)) + +followers.then((accounts: Array) => + accounts.forEach(account => IGService.getEventEmiter().emit("user", account)) +) + + + + +let fullFollwers = followers + .then((accounts: Array) => handleWithDelay(2000, accounts.map(_ => _.id), user.getAccount)) + +fullFollwers.then(array => array.forEach(element => { + element.then((account: any) => account._params).then((value: any) => IGService.getEventEmiter().emit("user", value)) + +})) + + // let fullFollwers = followers // .then((accounts: Array) => Promise.all(accounts.map(account => user.getAccount(account.id)))) // followers.then(_ => console.log(_.length)) // console.log(user.getAccount) - // fullFollwers.then(value => console.log("all has been Processed" + value.length)) let following = user.account() .then((account: any) => user.getUserFollowing(account.id)) + +following.then((accounts: Array) => + accounts.forEach(account => IGService.getEventEmiter().emit("user", account)) +) + + + + +let fullFollowin = following + .then((accounts: Array) => handleWithDelay(2000, accounts.map(_ => _.id), user.getAccount)) + +fullFollowin.then(array => array.forEach(element => { + element.then((account: any) => account._params).then((value: any) => IGService.getEventEmiter().emit("user", value)) + +})) // let fullFollowin = following // .then((accounts: Array) => Promise.all(accounts.map(account => user.getAccount(account.id)))) @@ -47,4 +79,36 @@ let following = user.account() // let mediaLikers = userMedia.map((_: any) => _.id) // .then((ids: Array) => Promise.all(ids.map(id => media.getMediaLikersHandler(id)))) -// followers.then((dataSet => dataSet.slice(2))).then(console.log) \ No newline at end of file +// followers.then((dataSet => dataSet.slice(2))).then(console.log) + + + + + + +let mediaComments = userMedia.map((_: any) => _.id) + .then((ids: Array) => Promise.all(ids.map(id => media.getMediaCommentsHandler(id)))) + +let mediaLikers = userMedia.map((_: any) => _.id) + .then((ids: Array) => Promise.all(ids.map(id => media.getMediaLikersHandler(id)))) + +followers.then((dataSet => dataSet.slice(2))).then(console.log) +let keyMedia = "media" +IGService.getEventEmiter().on(keyMedia, (data:any)=>{ + IGService.dataStorage({}, data, keyMedia) +}) +let keyUser = "user" +IGService.getEventEmiter().on(keyUser, (data:any)=>{ + IGService.dataStorage({}, data, keyUser) + +}) +let keyFollowing = "following" +IGService.getEventEmiter().on(keyFollowing, (data:any)=>{ + IGService.dataStorage({}, data, keyFollowing) + +}) +let keyFollower = "follower" +IGService.getEventEmiter().on(keyFollowing, (data:any)=>{ + IGService.dataStorage({}, data, keyFollower) + +}) \ No newline at end of file