Commit dbfe9be0 authored by soheib's avatar soheib
Browse files

add cron jobs

parent c480e103
...@@ -1058,6 +1058,15 @@ ...@@ -1058,6 +1058,15 @@
} }
} }
}, },
"@nestjs/schedule": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/@nestjs/schedule/-/schedule-1.0.1.tgz",
"integrity": "sha512-EU2tB4rxuEgum8JlorAFvXkU982EYZm/IBa7n6kgkyps5BbxQSFf7iR1CLkP9zODO9ApZTWk5z3q9L3O7vrkoQ==",
"requires": {
"cron": "1.7.2",
"uuid": "8.3.2"
}
},
"@nestjs/schematics": { "@nestjs/schematics": {
"version": "7.3.1", "version": "7.3.1",
"resolved": "https://registry.npmjs.org/@nestjs/schematics/-/schematics-7.3.1.tgz", "resolved": "https://registry.npmjs.org/@nestjs/schematics/-/schematics-7.3.1.tgz",
...@@ -1356,6 +1365,16 @@ ...@@ -1356,6 +1365,16 @@
"integrity": "sha512-t73xJJrvdTjXrn4jLS9VSGRbz0nUY3cl2DMGDU48lKl+HR9dbbjW2A9r3g40VA++mQpy6uuHg33gy7du2BKpog==", "integrity": "sha512-t73xJJrvdTjXrn4jLS9VSGRbz0nUY3cl2DMGDU48lKl+HR9dbbjW2A9r3g40VA++mQpy6uuHg33gy7du2BKpog==",
"dev": true "dev": true
}, },
"@types/cron": {
"version": "1.7.3",
"resolved": "https://registry.npmjs.org/@types/cron/-/cron-1.7.3.tgz",
"integrity": "sha512-iPmUXyIJG1Js+ldPYhOQcYU3kCAQ2FWrSkm1FJPoii2eYSn6wEW6onPukNTT0bfiflexNSRPl6KWmAIqS+36YA==",
"dev": true,
"requires": {
"@types/node": "*",
"moment": ">=2.14.0"
}
},
"@types/eslint": { "@types/eslint": {
"version": "7.28.0", "version": "7.28.0",
"resolved": "https://registry.npmjs.org/@types/eslint/-/eslint-7.28.0.tgz", "resolved": "https://registry.npmjs.org/@types/eslint/-/eslint-7.28.0.tgz",
...@@ -3062,6 +3081,14 @@ ...@@ -3062,6 +3081,14 @@
"integrity": "sha512-dcKFX3jn0MpIaXjisoRvexIJVEKzaq7z2rZKxf+MSr9TkdmHmsU4m2lcLojrj/FHl8mk5VxMmYA+ftRkP/3oKQ==", "integrity": "sha512-dcKFX3jn0MpIaXjisoRvexIJVEKzaq7z2rZKxf+MSr9TkdmHmsU4m2lcLojrj/FHl8mk5VxMmYA+ftRkP/3oKQ==",
"dev": true "dev": true
}, },
"cron": {
"version": "1.7.2",
"resolved": "https://registry.npmjs.org/cron/-/cron-1.7.2.tgz",
"integrity": "sha512-+SaJ2OfeRvfQqwXQ2kgr0Y5pzBR/lijf5OpnnaruwWnmI799JfWr2jN2ItOV9s3A/+TFOt6mxvKzQq5F0Jp6VQ==",
"requires": {
"moment-timezone": "^0.5.x"
}
},
"cross-spawn": { "cross-spawn": {
"version": "7.0.3", "version": "7.0.3",
"resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.3.tgz", "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.3.tgz",
...@@ -6166,6 +6193,19 @@ ...@@ -6166,6 +6193,19 @@
"minimist": "^1.2.5" "minimist": "^1.2.5"
} }
}, },
"moment": {
"version": "2.29.1",
"resolved": "https://registry.npmjs.org/moment/-/moment-2.29.1.tgz",
"integrity": "sha512-kHmoybcPV8Sqy59DwNDY3Jefr64lK/by/da0ViFcuA4DH0vQg5Q6Ze5VimxkfQNSC+Mls/Kx53s7TjP1RhFEDQ=="
},
"moment-timezone": {
"version": "0.5.33",
"resolved": "https://registry.npmjs.org/moment-timezone/-/moment-timezone-0.5.33.tgz",
"integrity": "sha512-PTc2vcT8K9J5/9rDEPe5czSIKgLoGsH8UNpA4qZTVw0Vd/Uz19geE9abbIOQKaAQFcnQ3v5YEXrbSc5BpshH+w==",
"requires": {
"moment": ">= 2.9.0"
}
},
"mongodb": { "mongodb": {
"version": "3.6.10", "version": "3.6.10",
"resolved": "https://registry.npmjs.org/mongodb/-/mongodb-3.6.10.tgz", "resolved": "https://registry.npmjs.org/mongodb/-/mongodb-3.6.10.tgz",
......
...@@ -12,9 +12,11 @@ import { CommentSchema } from './instagram/models/comment.schema' ...@@ -12,9 +12,11 @@ import { CommentSchema } from './instagram/models/comment.schema'
import { LottoryResultSchema } from './instagram/models/LottoryResult.schema' import { LottoryResultSchema } from './instagram/models/LottoryResult.schema'
import { PostSchema } from './instagram/models/post.schema' import { PostSchema } from './instagram/models/post.schema'
import { StoryMentionSchema } from './instagram/models/storyMention.schema' import { StoryMentionSchema } from './instagram/models/storyMention.schema'
import { ScheduleModule } from '@nestjs/schedule'
@Module({ @Module({
imports: [ imports: [
ScheduleModule.forRoot(),
MongooseModule.forRoot( MongooseModule.forRoot(
'mongodb://instagram:wcD3B5sGw0yQ@185.231.180.248:27017/instagram-lottry?authSource=admin&authMechanism=SCRAM-SHA-256&connectTimeoutMS=10000&readPreference=primary&serverSelectionTimeoutMS=5000&appname=MongoDB%20Compass&directConnection=true&ssl=false', 'mongodb://instagram:wcD3B5sGw0yQ@185.231.180.248:27017/instagram-lottry?authSource=admin&authMechanism=SCRAM-SHA-256&connectTimeoutMS=10000&readPreference=primary&serverSelectionTimeoutMS=5000&appname=MongoDB%20Compass&directConnection=true&ssl=false',
), ),
......
This diff is collapsed.
...@@ -15,6 +15,7 @@ import { spawn } from 'child_process' ...@@ -15,6 +15,7 @@ import { spawn } from 'child_process'
import * as path from "path" import * as path from "path"
import { StoryMentionDocument } from './models/storyMention.schema' import { StoryMentionDocument } from './models/storyMention.schema'
import { AddStoryDataDto } from './dto/add-story-data-dto' import { AddStoryDataDto } from './dto/add-story-data-dto'
import { Cron, CronExpression } from '@nestjs/schedule'
@Injectable() @Injectable()
export class InstagramService implements OnApplicationBootstrap { export class InstagramService implements OnApplicationBootstrap {
...@@ -170,4 +171,30 @@ export class InstagramService implements OnApplicationBootstrap { ...@@ -170,4 +171,30 @@ export class InstagramService implements OnApplicationBootstrap {
return user return user
} }
@Cron(CronExpression.EVERY_3_HOURS)
async cronGetLikes() {
console.log('start cron ======> get daily Likes');
let username = "kakasrm"
let password = "kaka1374"
let postArray = ["CSlqcUEAZsU"]
let account = "azadi.gold"
for await (const post_short_code of postArray) {
await this.getLikesFromInstaLoader(username, password, post_short_code, account )
}
}
@Cron(CronExpression.EVERY_3_HOURS)
async cronGetComments() {
console.log('start cron ======> calculate daily comments');
let username = "kakasrm"
let password = "kaka1374"
let postArray = ["CSlqcUEAZsU"]
let account = "azadi.gold"
for await (const post_short_code of postArray) {
await this.getCommentsFromInstaLoader(username, password, post_short_code, account )
}
}
} }
...@@ -17,8 +17,6 @@ export class LottoryResult { ...@@ -17,8 +17,6 @@ export class LottoryResult {
@Prop() @Prop()
status: string status: string
@Prop()
date: Date
} }
export const LottoryResultSchema = SchemaFactory.createForClass(LottoryResult); export const LottoryResultSchema = SchemaFactory.createForClass(LottoryResult);
...@@ -10,6 +10,7 @@ import addToStoryData from '../instagram/values/add-to-story-data' ...@@ -10,6 +10,7 @@ import addToStoryData from '../instagram/values/add-to-story-data'
import { ChangeStatusDto } from './dto/change-status-dto' import { ChangeStatusDto } from './dto/change-status-dto'
import { ScoreService } from './score.service' import { ScoreService } from './score.service'
import { StoryMentionDocument } from 'src/instagram/models/storyMention.schema' import { StoryMentionDocument } from 'src/instagram/models/storyMention.schema'
import { Cron, CronExpression } from '@nestjs/schedule'
@Injectable() @Injectable()
export class LotteryService { export class LotteryService {
...@@ -64,6 +65,8 @@ export class LotteryService { ...@@ -64,6 +65,8 @@ export class LotteryService {
profileUsername, profileUsername,
postArray, postArray,
) )
console.log('=========',userScore);
const foundUserLastCount = await this.lotteryResultModel.countDocuments({ const foundUserLastCount = await this.lotteryResultModel.countDocuments({
user_id: new Types.ObjectId(user_id), user_id: new Types.ObjectId(user_id),
}) })
...@@ -137,12 +140,12 @@ export class LotteryService { ...@@ -137,12 +140,12 @@ export class LotteryService {
async getUserList() { async getUserList() {
const foundUsernameInComment = await this.commentModel.distinct('user_id') const foundUsernameInComment = await this.commentModel.distinct('user_id')
const foundUsernameInLike = await this.likeModel.distinct('user_id') const foundUsernameInLike = await this.likeModel.distinct('user_id')
const foundUsernameInStoryMentions = await this.storyMentionModel.distinct('user_id') const foundUsernameInStoryMentions = await this.storyMentionModel.distinct('user_id')
const foundUsernamesInStoryData = new Array<string>() const foundUsernamesInStoryData = new Array<string>()
foundUsernameInStoryMentions.forEach(user_id=>{ foundUsernameInStoryMentions.forEach(user_id => {
foundUsernamesInStoryData.push(user_id.toString()) foundUsernamesInStoryData.push(user_id.toString())
}) })
const userListTemp = foundUsernameInComment.concat(foundUsernameInLike) const userListTemp = foundUsernameInComment.concat(foundUsernameInLike)
const array = new Array<string>() const array = new Array<string>()
userListTemp.forEach((user) => { userListTemp.forEach((user) => {
...@@ -152,4 +155,12 @@ export class LotteryService { ...@@ -152,4 +155,12 @@ export class LotteryService {
const userList = [...new Set(userListTemp2)] const userList = [...new Set(userListTemp2)]
return userList return userList
} }
@Cron(CronExpression.EVERY_3_HOURS)
async cronCalculateScore() {
console.log('start cron ======> calculate daily score');
let postArray = ["CSlqcUEAZsU"]
let account = "azadi.gold"
await this.addResultsToDB(account, postArray)
}
} }
...@@ -113,8 +113,6 @@ export class ScoreService { ...@@ -113,8 +113,6 @@ export class ScoreService {
let likesScore = await this.getUserLikesScore(username, profileUsername, postArray) let likesScore = await this.getUserLikesScore(username, profileUsername, postArray)
let commentScore = await this.getUserCommentsScore(username, profileUsername, postArray) let commentScore = await this.getUserCommentsScore(username, profileUsername, postArray)
let addToStoryScore = await this.getTagsScore(username) let addToStoryScore = await this.getTagsScore(username)
console.log("=======", likesScore, commentScore, addToStoryScore)
return likesScore + commentScore + addToStoryScore return likesScore + commentScore + addToStoryScore
} }
......
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