Commit 41eeb938 authored by soheib's avatar soheib
Browse files

comment check user is follower

parent 447e96bd
...@@ -36,12 +36,12 @@ import { StoryMentionSchema } from './instagram/models/storyMention.schema' ...@@ -36,12 +36,12 @@ import { StoryMentionSchema } from './instagram/models/storyMention.schema'
MongooseModule.forFeature([ MongooseModule.forFeature([
{ name: 'Post', schema: PostSchema }, { name: 'Post', schema: PostSchema },
]), ]),
MongooseModule.forFeature([ MongooseModule.forFeature([
{ name: 'StoryMention', schema: StoryMentionSchema }, { name: 'StoryMention', schema: StoryMentionSchema },
]), ]),
InstagramModule, InstagramModule,
LotteryModule, LotteryModule,
], ],
......
...@@ -59,6 +59,8 @@ export class InstagramService implements OnApplicationBootstrap { ...@@ -59,6 +59,8 @@ export class InstagramService implements OnApplicationBootstrap {
async getLikesFromInstaLoader(username: string, password: string, post_short_code: string, profile: string) { async getLikesFromInstaLoader(username: string, password: string, post_short_code: string, profile: string) {
console.log('start getting likes');
let paths = path.resolve("src", "instagram", "instaloader-service", "getLikes.py") let paths = path.resolve("src", "instagram", "instaloader-service", "getLikes.py")
const getLikesProccess = spawn('python3', [`${paths}`, `${username}`, `${password}`, `${post_short_code}`, `${profile}`,]) const getLikesProccess = spawn('python3', [`${paths}`, `${username}`, `${password}`, `${post_short_code}`, `${profile}`,])
...@@ -79,6 +81,7 @@ export class InstagramService implements OnApplicationBootstrap { ...@@ -79,6 +81,7 @@ export class InstagramService implements OnApplicationBootstrap {
} }
async getCommentsFromInstaLoader(username: string, password: string, post_short_code: string, profile: string) { async getCommentsFromInstaLoader(username: string, password: string, post_short_code: string, profile: string) {
let paths = path.resolve("src", "instagram", "instaloader-service", "getComments.py") let paths = path.resolve("src", "instagram", "instaloader-service", "getComments.py")
console.log(paths);
const getCommentsProccess = spawn('python3', [`'${paths}`, `${username}`, `${password}`, `${post_short_code}`, `${profile}`]) const getCommentsProccess = spawn('python3', [`'${paths}`, `${username}`, `${password}`, `${post_short_code}`, `${profile}`])
......
...@@ -31,76 +31,76 @@ export class ScoreService { ...@@ -31,76 +31,76 @@ export class ScoreService {
async getUserLikesScore(user_id: string, profileUsername: string, postArray: string[]) { async getUserLikesScore(user_id: string, profileUsername: string, postArray: string[]) {
let foundAccount = await this.userModel.findOne({ username: profileUsername }) // let foundAccount = await this.userModel.findOne({ username: profileUsername })
let isfollowerValid = await this.followerModel.findOne({ // let isfollowerValid = await this.followerModel.findOne({
$and: [ // $and: [
{ user_id: new Types.ObjectId(user_id) }, // { user_id: new Types.ObjectId(user_id) },
{ account_id: foundAccount._id } // { account_id: foundAccount._id }
] // ]
}) // })
if (isfollowerValid) { // if (isfollowerValid) {
let score = 0 let score = 0
for await (const post of postArray) { for await (const post of postArray) {
let foundPost = await this.postModel.findOne({ url: post }) let foundPost = await this.postModel.findOne({ url: post })
let foundLike = await this.likeModel.findOne({ let foundLike = await this.likeModel.findOne({
$and: [ $and: [
{ {
user_id: new Types.ObjectId(user_id) user_id: new Types.ObjectId(user_id)
}, },
{ {
post_id: new Types.ObjectId(foundPost._id) post_id: new Types.ObjectId(foundPost._id)
} }
] ]
}) })
if (foundLike) { if (foundLike) {
score++ score++
}
} }
return score
}
else {
return 0
} }
return score
// }
// else {
// return 0
// }
} }
async getUserCommentsScore(user_id: string, profileUsername: string, postArray: string[]) { async getUserCommentsScore(user_id: string, profileUsername: string, postArray: string[]) {
let foundAccount = await this.userModel.findOne({ username: profileUsername }) // let foundAccount = await this.userModel.findOne({ username: profileUsername })
let isfollowerValid = await this.followerModel.findOne({ // let isfollowerValid = await this.followerModel.findOne({
$and: [{ user_id: new Types.ObjectId(user_id) } // $and: [{ user_id: new Types.ObjectId(user_id) }
, { account_id: foundAccount._id }] // , { account_id: foundAccount._id }]
}) // })
if (isfollowerValid) { // if (isfollowerValid) {
let userCommentScore = new Array<{ post_id: string, post_score: number }>() let userCommentScore = new Array<{ post_id: string, post_score: number }>()
for await (const post of postArray) { for await (const post of postArray) {
let foundPost = await this.postModel.findOne({ url: post }) let foundPost = await this.postModel.findOne({ url: post })
userCommentScore.push({ userCommentScore.push({
post_id: foundPost._id, post_id: foundPost._id,
post_score: 0 post_score: 0
})
}
let foundUserComments = await this.commentModel.find({ user_id: new Types.ObjectId(user_id) })
for await (const comment of foundUserComments) {
userCommentScore.forEach(element => {
if (comment.post_id.toString() === element.post_id.toString() && element.post_score < 3) {
element.post_score++
}
})
}
let score = 0
userCommentScore.forEach(element => {
score += element.post_score
}) })
return score
} }
else { let foundUserComments = await this.commentModel.find({ user_id: new Types.ObjectId(user_id) })
return 0 for await (const comment of foundUserComments) {
userCommentScore.forEach(element => {
if (comment.post_id.toString() === element.post_id.toString() && element.post_score < 3) {
element.post_score++
}
})
} }
let score = 0
userCommentScore.forEach(element => {
score += element.post_score
})
return score
// }
// else {
// return 0
// }
} }
async getTagsScore(user_id: string) { async getTagsScore(user_id: string) {
let addToStoryScore = 0 let addToStoryScore = 0
let foundUserInStory = await this.storyMentionModel.findOne({user_id: new Types.ObjectId(user_id)}) let foundUserInStory = await this.storyMentionModel.findOne({ user_id: new Types.ObjectId(user_id) })
if (foundUserInStory) { if (foundUserInStory) {
addToStoryScore = foundUserInStory.count addToStoryScore = foundUserInStory.count
} }
......
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