Commit 63d01258 authored by soheib's avatar soheib
Browse files

add pointer

parent 627ed44d
...@@ -23,8 +23,13 @@ export class AppController { ...@@ -23,8 +23,13 @@ export class AppController {
return await this.appService.calculateUserScore(getUserScoreDto.username); return await this.appService.calculateUserScore(getUserScoreDto.username);
} }
@Get('result') @Get('calculate-result')
async getResults() { async calculateResult() {
return await this.appService.getResults(); return await this.appService.getResults()
} }
@Get('get-results')
async getResults() {
return await this.appService.getFinalResults();
}
} }
...@@ -31,7 +31,7 @@ export class AppService implements OnApplicationBootstrap { ...@@ -31,7 +31,7 @@ export class AppService implements OnApplicationBootstrap {
} }
async onApplicationBootstrap() { async onApplicationBootstrap() {
this.client = await this.login("jangomangoss", "kaka7701") this.client = await this.login("sohe.ibs", "kaka1374")
} }
private async login(username, password) { private async login(username, password) {
...@@ -52,8 +52,6 @@ export class AppService implements OnApplicationBootstrap { ...@@ -52,8 +52,6 @@ export class AppService implements OnApplicationBootstrap {
} }
async getFollowers(account_username: string = 'azadi.gold') { async getFollowers(account_username: string = 'azadi.gold') {
try { try {
let hasNextPage: boolean = true let hasNextPage: boolean = true
let requestCount = 0 let requestCount = 0
let followersCount = 0 let followersCount = 0
...@@ -70,7 +68,7 @@ export class AppService implements OnApplicationBootstrap { ...@@ -70,7 +68,7 @@ export class AppService implements OnApplicationBootstrap {
while (hasNextPage) { while (hasNextPage) {
console.log("seted cursor", cursor) console.log("seted cursor", cursor)
console.log("sending request....") console.log("sending request....")
let collectedFollower = await this.sendFollowerRequest(this.client, account_username, cursor) let collectedFollower = await this.sendFollowerRequest(this.client, account_username, '')
console.log("request sended. request count:", requestCount); console.log("request sended. request count:", requestCount);
requestCount++ requestCount++
...@@ -80,7 +78,7 @@ export class AppService implements OnApplicationBootstrap { ...@@ -80,7 +78,7 @@ export class AppService implements OnApplicationBootstrap {
hasNextPage = collectedFollower.hasNextPage hasNextPage = collectedFollower.hasNextPage
for await (const follower of collectedFollower.followers.reverse()) { for await (const follower of collectedFollower.followers) {
let check = await this.followerModel.findOne({ let check = await this.followerModel.findOne({
$and: [ $and: [
{ bussines_username: account_username }, { bussines_username: account_username },
...@@ -100,6 +98,9 @@ export class AppService implements OnApplicationBootstrap { ...@@ -100,6 +98,9 @@ export class AppService implements OnApplicationBootstrap {
}) })
followersCount += 1 followersCount += 1
} }
else{
return "already updated"
}
} }
console.log("================next request info=================="); console.log("================next request info==================");
console.log("nextCursor:", cursor) console.log("nextCursor:", cursor)
...@@ -108,6 +109,7 @@ export class AppService implements OnApplicationBootstrap { ...@@ -108,6 +109,7 @@ export class AppService implements OnApplicationBootstrap {
console.log("================ end of this Request Proccess =================="); console.log("================ end of this Request Proccess ==================");
} }
return { return {
status: "successfull", status: "successfull",
totalAdded: followersCount totalAdded: followersCount
...@@ -147,7 +149,7 @@ export class AppService implements OnApplicationBootstrap { ...@@ -147,7 +149,7 @@ export class AppService implements OnApplicationBootstrap {
await this.requestModel.create({ _id: new Types.ObjectId(), cursor: cursor, type: "comment", post_short_code: postShortCode }) await this.requestModel.create({ _id: new Types.ObjectId(), cursor: cursor, type: "comment", post_short_code: postShortCode })
hasNextPage = collectedComments.hasNextPage hasNextPage = collectedComments.hasNextPage
for await (const comment of collectedComments.comments.reverse()) { for await (const comment of collectedComments.comments) {
let check = await this.commentModel.findOne({ let check = await this.commentModel.findOne({
comment_id: comment.comment_id comment_id: comment.comment_id
}) })
...@@ -163,6 +165,9 @@ export class AppService implements OnApplicationBootstrap { ...@@ -163,6 +165,9 @@ export class AppService implements OnApplicationBootstrap {
}) })
commentCount += 1 commentCount += 1
} }
else{
return "already updated"
}
} }
console.log("================nex request info=================="); console.log("================nex request info==================");
...@@ -265,7 +270,7 @@ export class AppService implements OnApplicationBootstrap { ...@@ -265,7 +270,7 @@ export class AppService implements OnApplicationBootstrap {
} }
return { return {
followers: Infollowers, followers: Infollowers,
cursor: pointer, cursor: '',
hasNextPage: followers.page_info.has_next_page hasNextPage: followers.page_info.has_next_page
} }
} }
...@@ -414,7 +419,9 @@ export class AppService implements OnApplicationBootstrap { ...@@ -414,7 +419,9 @@ export class AppService implements OnApplicationBootstrap {
invalid_mentions, invalid_mentions,
pending_mentions, pending_mentions,
score: valid_mentions + 1, score: valid_mentions + 1,
valid_users,inValid_users,pending_users valid_users:valid_users
,inValid_users:inValid_users,
pending_users: pending_users
}) })
} else { } else {
await this.resultModel.updateOne(foundUser._id, { await this.resultModel.updateOne(foundUser._id, {
...@@ -423,7 +430,9 @@ export class AppService implements OnApplicationBootstrap { ...@@ -423,7 +430,9 @@ export class AppService implements OnApplicationBootstrap {
invalid_mentions, invalid_mentions,
pending_mentions, pending_mentions,
score: valid_mentions + 1, score: valid_mentions + 1,
valid_users,inValid_users,pending_users valid_users:valid_users
,inValid_users:inValid_users,
pending_users: pending_users
}) })
} }
} }
...@@ -473,6 +482,10 @@ export class AppService implements OnApplicationBootstrap { ...@@ -473,6 +482,10 @@ export class AppService implements OnApplicationBootstrap {
return follower_objectResult return follower_objectResult
} }
async getFinalResults(){
return await this.resultModel.find()
}
} }
This diff is collapsed.
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment