Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
shahriar
instagram-service
Commits
c67101f4
Commit
c67101f4
authored
Nov 07, 2021
by
shahriar
☹
Browse files
Merge branch 'followers' of
https://git.netware.studio/shahriar/instagram-service
into followers
parents
d316ce7a
2fbe37e5
Changes
10
Hide whitespace changes
Inline
Side-by-side
src/app.module.ts
View file @
c67101f4
...
...
@@ -13,6 +13,7 @@ import { LottoryResultSchema } from './instagram/models/LottoryResult.schema'
import
{
PostSchema
}
from
'
./instagram/models/post.schema
'
import
{
StoryMentionSchema
}
from
'
./instagram/models/storyMention.schema
'
import
{
ScheduleModule
}
from
'
@nestjs/schedule
'
import
{
WebsiteSellSchema
}
from
'
./instagram/models/websiteSell.schema
'
;
@
Module
({
imports
:
[
...
...
@@ -42,6 +43,9 @@ import { ScheduleModule } from '@nestjs/schedule'
MongooseModule
.
forFeature
([
{
name
:
'
StoryMention
'
,
schema
:
StoryMentionSchema
},
]),
MongooseModule
.
forFeature
([
{
name
:
'
WebsiteSell
'
,
schema
:
WebsiteSellSchema
},
]),
InstagramModule
,
...
...
src/instagram/dto/add-website-sell-dto.ts
0 → 100644
View file @
c67101f4
import
{
ApiProperty
}
from
"
@nestjs/swagger
"
export
class
AddWebsiteSellsDto
{
@
ApiProperty
({
example
:
[{
username
:
"
soheib
"
,
value
:
5
},
{
username
:
"
sohasd.eib
"
,
value
:
4
}]
})
website_sells
:
Array
<
{
username
:
string
,
value
:
number
}
>
}
\ No newline at end of file
src/instagram/instagram.controller.ts
View file @
c67101f4
import
{
Body
,
Controller
,
Get
,
Param
,
Post
}
from
'
@nestjs/common
'
import
{
ApiBody
,
ApiTags
}
from
'
@nestjs/swagger
'
import
{
AddStoryDataDto
}
from
'
./dto/add-story-data-dto
'
import
{
AddWebsiteSellsDto
}
from
'
./dto/add-website-sell-dto
'
import
{
GetCommentsDto
}
from
'
./dto/get-comments-dto
'
import
{
GetFollowersDto
}
from
'
./dto/get-followers-dto
'
import
{
GetLikesDto
}
from
'
./dto/get-likes-dto
'
...
...
@@ -11,7 +12,7 @@ export class InstagramController {
constructor
(
private
instagramService
:
InstagramService
)
{
}
@
Get
(
'
get-json-followers
'
)
async
getJsonDataFollowers
()
{
await
this
.
instagramService
.
getFollowersFromJsonData
()
...
...
@@ -50,4 +51,12 @@ export class InstagramController {
async
addStoryMentions
(@
Body
()
addDto
:
AddStoryDataDto
)
{
return
await
this
.
instagramService
.
addStoryData
(
addDto
)
}
@
ApiBody
({
type
:
AddStoryDataDto
})
@
ApiTags
(
'
Instagram
'
)
@
Post
(
'
add-website-sells
'
)
async
addWebSiteSells
(@
Body
()
addDto
:
AddWebsiteSellsDto
)
{
return
await
this
.
instagramService
.
addWebsiteSells
(
addDto
)
}
}
src/instagram/instagram.module.ts
View file @
c67101f4
...
...
@@ -8,6 +8,7 @@ import { LikeSchema } from './models/like.schema';
import
{
LottoryResultSchema
}
from
'
./models/LottoryResult.schema
'
;
import
{
StoryMentionSchema
}
from
'
./models/storyMention.schema
'
import
{
UserSchema
}
from
'
./models/user.schema
'
;
import
{
WebsiteSellSchema
}
from
'
./models/websiteSell.schema
'
;
@
Module
({
imports
:
[
...
...
@@ -29,6 +30,9 @@ import { UserSchema } from './models/user.schema';
MongooseModule
.
forFeature
([
{
name
:
'
StoryMention
'
,
schema
:
StoryMentionSchema
},
]),
MongooseModule
.
forFeature
([
{
name
:
'
WebsiteSell
'
,
schema
:
WebsiteSellSchema
},
]),
],
controllers
:
[
InstagramController
],
providers
:
[
InstagramService
]
...
...
src/instagram/instagram.service.ts
View file @
c67101f4
...
...
@@ -16,6 +16,8 @@ import * as path from "path"
import
{
StoryMentionDocument
}
from
'
./models/storyMention.schema
'
import
{
AddStoryDataDto
}
from
'
./dto/add-story-data-dto
'
import
{
Cron
,
CronExpression
}
from
'
@nestjs/schedule
'
import
{
AddWebsiteSellsDto
}
from
'
./dto/add-website-sell-dto
'
import
{
WebsiteSellDocument
}
from
'
./models/websiteSell.schema
'
@
Injectable
()
export
class
InstagramService
implements
OnApplicationBootstrap
{
...
...
@@ -30,6 +32,8 @@ export class InstagramService implements OnApplicationBootstrap {
private
commentModel
:
Model
<
CommentDocument
>
,
@
InjectModel
(
'
StoryMention
'
)
private
storyMentionModel
:
Model
<
StoryMentionDocument
>
,
@
InjectModel
(
'
WebsiteSell
'
)
private
websiteSellModel
:
Model
<
WebsiteSellDocument
>
,
)
{
}
...
...
@@ -83,7 +87,7 @@ export class InstagramService implements OnApplicationBootstrap {
async
getCommentsFromInstaLoader
(
username
:
string
,
password
:
string
,
post_short_code
:
string
,
profile
:
string
)
{
console
.
log
(
"
start getting comments
"
);
let
paths
=
path
.
resolve
(
"
src
"
,
"
instagram
"
,
"
instaloader-service
"
,
"
getComments.py
"
)
console
.
log
(
`
${
paths
}
`
,
`
${
username
}
`
,
`
${
password
}
`
,
`
${
post_short_code
}
`
,
`
${
profile
}
`
);
const
getCommentsProccess
=
spawn
(
'
python3
'
,
[
`
${
paths
}
`
,
`
${
username
}
`
,
`
${
password
}
`
,
`
${
post_short_code
}
`
,
`
${
profile
}
`
])
...
...
@@ -151,6 +155,41 @@ export class InstagramService implements OnApplicationBootstrap {
count
:
userData
.
count
})
}
}
}
async
addWebsiteSells
(
addDto
:
AddWebsiteSellsDto
)
{
for
await
(
const
userData
of
addDto
.
website_sells
)
{
let
foundUser
=
await
this
.
userModel
.
findOne
({
username
:
userData
.
username
})
if
(
foundUser
)
{
let
foundData
=
await
this
.
websiteSellModel
.
findOne
({
user_id
:
new
Types
.
ObjectId
(
foundUser
.
_id
)
})
if
(
!
foundData
)
{
await
this
.
websiteSellModel
.
create
({
_id
:
new
Types
.
ObjectId
(),
user_id
:
foundUser
.
_id
,
value
:
userData
.
value
})
}
else
{
await
this
.
websiteSellModel
.
findOneAndUpdate
({
user_id
:
new
Types
.
ObjectId
(
foundUser
.
_id
),
},
{
value
:
userData
.
value
})
}
}
else
{
let
newUser
=
await
this
.
userModel
.
create
({
_id
:
new
Types
.
ObjectId
(),
username
:
userData
.
username
,
is_follower
:
false
})
await
this
.
websiteSellModel
.
create
({
_id
:
new
Types
.
ObjectId
(),
user_id
:
newUser
.
_id
,
value
:
userData
.
value
})
}
}
}
...
...
@@ -171,30 +210,30 @@ export class InstagramService implements OnApplicationBootstrap {
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
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
)
@
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
)
}
}
}
}
src/instagram/instaloader-service/getLikes.py
View file @
c67101f4
...
...
@@ -89,8 +89,8 @@ def getLikes(db, post, profile):
x
=
col
.
update
(
temp
,
temp
,
upsert
=
True
)
print
(
like
.
username
,
" like post : "
,
post_short_code
)
except
err
:
print
(
err
)
except
:
print
(
'
err
or'
)
__main__
()
src/instagram/models/websiteSell.schema.ts
0 → 100644
View file @
c67101f4
import
{
Prop
,
Schema
,
SchemaFactory
}
from
'
@nestjs/mongoose
'
;
import
{
Document
,
Types
}
from
'
mongoose
'
;
export
type
WebsiteSellDocument
=
WebsiteSell
&
Document
;
@
Schema
({
timestamps
:
true
})
export
class
WebsiteSell
{
@
Prop
()
_id
:
Types
.
ObjectId
@
Prop
({
type
:
Types
.
ObjectId
,
ref
:
'
User
'
})
user_id
:
Types
.
ObjectId
@
Prop
()
value
:
number
}
export
const
WebsiteSellSchema
=
SchemaFactory
.
createForClass
(
WebsiteSell
)
\ No newline at end of file
src/lottery/lottery.module.ts
View file @
c67101f4
...
...
@@ -7,6 +7,7 @@ import { LottoryResultSchema } from 'src/instagram/models/LottoryResult.schema';
import
{
PostSchema
}
from
'
src/instagram/models/post.schema
'
import
{
StoryMentionSchema
}
from
'
src/instagram/models/storyMention.schema
'
import
{
UserSchema
}
from
'
src/instagram/models/user.schema
'
;
import
{
WebsiteSellSchema
}
from
'
src/instagram/models/websiteSell.schema
'
;
import
{
LotteryController
}
from
'
./lottery.controller
'
;
import
{
LotteryService
}
from
'
./lottery.service
'
;
import
{
ScoreService
}
from
'
./score.service
'
;
...
...
@@ -34,6 +35,9 @@ import { ScoreService } from './score.service';
MongooseModule
.
forFeature
([
{
name
:
'
StoryMention
'
,
schema
:
StoryMentionSchema
},
]),
MongooseModule
.
forFeature
([
{
name
:
'
WebsiteSell
'
,
schema
:
WebsiteSellSchema
},
]),
],
controllers
:
[
LotteryController
],
providers
:
[
LotteryService
,
ScoreService
]
...
...
src/lottery/lottery.service.ts
View file @
c67101f4
...
...
@@ -10,6 +10,7 @@ import { ScoreService } from './score.service'
import
{
StoryMentionDocument
}
from
'
src/instagram/models/storyMention.schema
'
import
{
Cron
,
CronExpression
}
from
'
@nestjs/schedule
'
import
{
PostDocument
}
from
'
src/instagram/models/post.schema
'
import
{
WebsiteSellDocument
}
from
'
src/instagram/models/websiteSell.schema
'
@
Injectable
()
export
class
LotteryService
{
...
...
@@ -27,6 +28,8 @@ export class LotteryService {
private
lotteryResultModel
:
Model
<
LottoryResultDocument
>
,
@
InjectModel
(
'
StoryMention
'
)
private
storyMentionModel
:
Model
<
StoryMentionDocument
>
,
@
InjectModel
(
'
WebsiteSell
'
)
private
websiteSellModel
:
Model
<
WebsiteSellDocument
>
,
)
{
}
async
getUserScore
(
username
:
string
)
{
...
...
@@ -42,7 +45,8 @@ export class LotteryService {
"
azadi.gold
"
,
postArray
,
)
const
addToStoryScore
=
await
this
.
scoreService
.
getTagsScore
(
username
)
const
addToStoryScore
=
await
this
.
scoreService
.
getTagsScore
(
foundUser
.
_id
,)
const
sellScore
=
await
this
.
scoreService
.
getWebsiteSellsScore
(
foundUser
.
_id
)
let
foundIndexes
=
await
this
.
lotteryResultModel
.
find
({
user_id
:
foundUser
.
_id
})
let
chances
=
new
Array
<
string
>
()
foundIndexes
.
forEach
(
result
=>
{
...
...
@@ -52,7 +56,9 @@ export class LotteryService {
likesScore
,
commentScore
,
addToStoryScore
,
totalScore
:
likesScore
+
commentScore
+
addToStoryScore
,
sellScore
,
totalScore
:
likesScore
+
commentScore
+
addToStoryScore
+
sellScore
,
lottry_chances
:
chances
}
}
...
...
src/lottery/score.service.ts
View file @
c67101f4
...
...
@@ -7,6 +7,7 @@ import { LikeDocument } from 'src/instagram/models/like.schema'
import
{
PostDocument
}
from
'
src/instagram/models/post.schema
'
import
{
StoryMentionDocument
}
from
'
src/instagram/models/storyMention.schema
'
import
{
UserDocument
}
from
'
src/instagram/models/user.schema
'
import
{
WebsiteSellDocument
}
from
'
src/instagram/models/websiteSell.schema
'
import
addToStoryData
from
'
../instagram/values/add-to-story-data
'
...
...
@@ -27,6 +28,8 @@ export class ScoreService {
private
postModel
:
Model
<
PostDocument
>
,
@
InjectModel
(
'
StoryMention
'
)
private
storyMentionModel
:
Model
<
StoryMentionDocument
>
,
@
InjectModel
(
'
WebsiteSell
'
)
private
websiteSellModel
:
Model
<
WebsiteSellDocument
>
,
)
{
}
...
...
@@ -102,19 +105,29 @@ export class ScoreService {
let
addToStoryScore
=
0
let
foundUserInStory
=
await
this
.
storyMentionModel
.
findOne
({
user_id
:
new
Types
.
ObjectId
(
user_id
)
})
if
(
foundUserInStory
)
{
addToStoryScore
=
(
foundUserInStory
.
count
*
2
)
addToStoryScore
=
(
foundUserInStory
.
count
*
2
)
}
return
addToStoryScore
}
async
getWebsiteSellsScore
(
user_id
:
string
)
{
let
sellScore
=
0
let
foundUserInSell
=
await
this
.
websiteSellModel
.
findOne
({
user_id
:
new
Types
.
ObjectId
(
user_id
)
})
if
(
foundUserInSell
)
{
sellScore
=
(
foundUserInSell
.
value
/
1000000
)
*
30
}
return
sellScore
}
async
calculateUserScore
(
username
:
string
,
profileUsername
:
string
,
postArray
:
string
[])
{
let
likesScore
=
await
this
.
getUserLikesScore
(
username
,
profileUsername
,
postArray
)
let
commentScore
=
await
this
.
getUserCommentsScore
(
username
,
profileUsername
,
postArray
)
let
addToStoryScore
=
await
this
.
getTagsScore
(
username
)
r
et
urn
likesScore
+
commentScore
+
addToStoryScore
l
et
sellScore
=
await
this
.
getWebsiteSellsScore
(
username
)
return
likesScore
+
commentScore
+
addToStoryScore
+
sellScore
}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment