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
c670bdce
Commit
c670bdce
authored
Aug 14, 2021
by
soheib
Browse files
update services
parent
18cf3ef6
Changes
9
Hide whitespace changes
Inline
Side-by-side
src/app.module.ts
View file @
c670bdce
...
...
@@ -14,7 +14,7 @@ import { LottoryResultSchema } from './instagram/models/LottoryResult.schema'
@
Module
({
imports
:
[
MongooseModule
.
forRoot
(
'
mongodb://instagram:wcD3B5sGw0yQ@185.231.180.248:27017/instagram-lottry?
serverSelection
TimeoutMS=
5
000&
connect
TimeoutMS=
1
000
0&authSource=admin
'
,
'
mongodb://instagram:wcD3B5sGw0yQ@185.231.180.248:27017/instagram-lottry?
authSource=admin&authMechanism=SCRAM-SHA-256&connect
TimeoutMS=
10
000&
readPreference=primary&serverSelection
TimeoutMS=
5
000
&appname=MongoDB%20Compass&directConnection=true&ssl=false
'
,
),
MongooseModule
.
forFeature
([
{
name
:
'
User
'
,
schema
:
UserSchema
},
...
...
src/instagram/instagram.service.ts
View file @
c670bdce
...
...
@@ -12,6 +12,7 @@ import { LikeDocument } from './models/like.schema';
import
{
UserDocument
}
from
'
./models/user.schema
'
;
import
FollowrData
from
'
./values/followers _data
'
import
{
spawn
}
from
'
child_process
'
import
*
as
path
from
"
path
"
@
Injectable
()
export
class
InstagramService
implements
OnApplicationBootstrap
{
...
...
@@ -54,9 +55,8 @@ export class InstagramService implements OnApplicationBootstrap {
async
getLikesFromInstaLoader
(
username
:
string
,
password
:
string
,
post_short_code
:
string
,
profile
:
string
)
{
let
status
:
string
=
""
let
err_message
:
string
const
getLikesProccess
=
spawn
(
'
python3
'
,
[
'
src/service/getLikes.py
'
,
`
${
username
}
`
,
`
${
password
}
`
,
`
${
post_short_code
}
`
,
`
${
profile
}
`
,]);
let
paths
=
path
.
resolve
(
"
src
"
,
"
instagram
"
,
"
instaloader-service
"
,
"
getLikes.py
"
)
const
getLikesProccess
=
spawn
(
'
python3
'
,
[
`
${
paths
}
`
,
`
${
username
}
`
,
`
${
password
}
`
,
`
${
post_short_code
}
`
,
`
${
profile
}
`
,]);
getLikesProccess
.
stdout
.
on
(
'
data
'
,
function
(
data
)
{
console
.
log
(
'
start collecting likes from python script ...
'
);
...
...
@@ -65,26 +65,18 @@ export class InstagramService implements OnApplicationBootstrap {
getLikesProccess
.
on
(
'
error
'
,
(
err
)
=>
{
console
.
log
(
`child process has error
${
err
}
`
)
status
=
"
error
"
err_message
=
err
.
message
});
getLikesProccess
.
on
(
'
close
'
,
(
code
)
=>
{
console
.
log
(
`child process close all stdio with code
${
code
}
`
);
status
=
"
successfull
"
});
if
(
status
===
"
error
"
){
return
{
message
:
err_message
}
}
if
(
status
===
"
successfull
"
){
return
{
message
:
"
successfull
"
}
}
}
async
getCommentsFromInstaLoader
(
username
:
string
,
password
:
string
,
post_short_code
:
string
,
profile
:
string
)
{
let
status
:
string
=
""
let
err_message
:
string
const
getCommentsProccess
=
spawn
(
'
python3
'
,
[
'
src/service/getComments.py
'
,
`
${
username
}
`
,
`
${
password
}
`
,
`
${
post_short_code
}
`
,
`
${
profile
}
`
]);
let
paths
=
path
.
resolve
(
"
src
"
,
"
instagram
"
,
"
instaloader-service
"
,
"
getComments.py
"
)
const
getCommentsProccess
=
spawn
(
'
python3
'
,
[
`'
${
paths
}
`
,
`
${
username
}
`
,
`
${
password
}
`
,
`
${
post_short_code
}
`
,
`
${
profile
}
`
]);
getCommentsProccess
.
stdout
.
on
(
'
data
'
,
function
(
data
)
{
console
.
log
(
'
start collecting comments from python script ...
'
);
...
...
@@ -93,26 +85,16 @@ export class InstagramService implements OnApplicationBootstrap {
getCommentsProccess
.
on
(
'
error
'
,
(
err
)
=>
{
console
.
log
(
`child process has error
${
err
}
`
);
status
=
"
error
"
err_message
=
err
.
message
});
getCommentsProccess
.
on
(
'
close
'
,
(
code
)
=>
{
console
.
log
(
`child process close all stdio with code
${
code
}
`
);
status
=
"
successfull
"
});
if
(
status
===
"
error
"
){
return
{
message
:
err_message
}
}
if
(
status
===
"
successfull
"
){
return
{
message
:
"
successfull
"
}
}
}
async
getFollowersFromInstaLoader
(
username
:
string
,
password
:
string
,
profile
:
string
)
{
let
status
:
string
=
""
let
err_message
:
string
const
getFollowersProccess
=
spawn
(
'
python3
'
,
[
'
src/service/getFollowers.py
'
,
`
${
username
}
`
,
`
${
password
}
`
,
`
${
profile
}
`
]);
let
paths
=
path
.
resolve
(
"
src
"
,
"
instagram
"
,
"
instaloader-service
"
,
"
getFollowers.py
"
)
const
getFollowersProccess
=
spawn
(
'
python3
'
,
[
`
${
paths
}
`
,
`
${
username
}
`
,
`
${
password
}
`
,
`
${
profile
}
`
]);
getFollowersProccess
.
stdout
.
on
(
'
data
'
,
function
(
data
)
{
console
.
log
(
'
start collecting followers from python script ...
'
);
...
...
@@ -121,20 +103,11 @@ export class InstagramService implements OnApplicationBootstrap {
getFollowersProccess
.
on
(
'
error
'
,
(
err
)
=>
{
console
.
log
(
`child process has error
${
err
}
`
);
status
=
"
error
"
err_message
=
err
.
message
});
getFollowersProccess
.
on
(
'
close
'
,
(
code
)
=>
{
console
.
log
(
`child process close all stdio with code
${
code
}
`
);
status
=
"
successfull
"
});
if
(
status
===
"
error
"
){
return
{
message
:
err_message
}
}
if
(
status
===
"
successfull
"
){
return
{
message
:
"
successfull
"
}
}
}
async
findOrCreateUser
(
username
:
string
)
{
...
...
src/instagram/instaloader-service/getComments.py
View file @
c670bdce
...
...
@@ -2,12 +2,12 @@ import instaloader
import
pymongo
import
sys
username
=
str
(
sys
.
argv
[
1
])
password
=
str
(
sys
.
argv
[
2
])
mongo_connection_string
=
"mongodb://
azadi:azadi%404010
@185.231.180.248:27017/
?serverSelectionTimeoutMS=5000&connectTimeoutMS=10000&
authSource=admin&authMechanism=SCRAM-SHA-256"
database_name
=
"
azadi-gold-backend
"
post_short_code
=
str
(
sys
.
argv
[
3
])
PROFILE
=
str
(
sys
.
argv
[
4
])
username
=
"kakasrm"
password
=
"kaka1374"
mongo_connection_string
=
"mongodb://
instagram:wcD3B5sGw0yQ
@185.231.180.248:27017/
instagram-lottry?
authSource=admin&authMechanism=SCRAM-SHA-256"
database_name
=
"
instagram-lottry
"
post_short_code
=
"CShKEJijy4v"
PROFILE
=
"azadi.gold"
def
__main__
():
...
...
src/instagram/instaloader-service/getFollowers.py
View file @
c670bdce
...
...
@@ -4,8 +4,8 @@ import sys
username
=
str
(
sys
.
argv
[
1
])
password
=
str
(
sys
.
argv
[
2
])
mongo_connection_string
=
"mongodb://
azadi:azadi%404010
@185.231.180.248:27017/
?serverSelectionTimeoutMS=5000&connectTimeoutMS=10000&
authSource=admin&authMechanism=SCRAM-SHA-256"
database_name
=
"
azadi-gold-backend
"
mongo_connection_string
=
"mongodb://
instagram:wcD3B5sGw0yQ
@185.231.180.248:27017/
instagram-lottry?
authSource=admin&authMechanism=SCRAM-SHA-256"
database_name
=
"
instagram-lottry
"
PROFILE
=
str
(
sys
.
argv
[
3
])
...
...
src/instagram/instaloader-service/getLikes.py
View file @
c670bdce
...
...
@@ -5,8 +5,8 @@ import sys
username
=
str
(
sys
.
argv
[
1
])
password
=
str
(
sys
.
argv
[
2
])
mongo_connection_string
=
"mongodb://
azadi:azadi%404010
@185.231.180.248:27017/
?serverSelectionTimeoutMS=5000&connectTimeoutMS=10000&
authSource=admin&authMechanism=SCRAM-SHA-256"
database_name
=
"
azadi-gold-backend
"
mongo_connection_string
=
"mongodb://
instagram:wcD3B5sGw0yQ
@185.231.180.248:27017/
instagram-lottry?
authSource=admin&authMechanism=SCRAM-SHA-256"
database_name
=
"
instagram-lottry
"
post_short_code
=
str
(
sys
.
argv
[
3
])
PROFILE
=
str
(
sys
.
argv
[
4
])
...
...
src/instagram/models/LottoryResult.schema.ts
View file @
c670bdce
...
...
@@ -6,9 +6,13 @@ export type LottoryResultDocument = LottoryResult & Document;
@
Schema
({
timestamps
:
true
})
export
class
LottoryResult
{
@
Prop
()
index
:
number
;
_id
:
Types
.
ObjectId
@
Prop
()
username
:
string
;
index
:
string
;
@
Prop
({
type
:
Types
.
ObjectId
,
ref
:
'
User
'
})
user_id
:
Types
.
ObjectId
// @Prop()
// tagged_user: string;
@
Prop
()
...
...
src/lottery/lottery.controller.ts
View file @
c670bdce
...
...
@@ -29,6 +29,8 @@ export class LotteryController {
@
Post
(
'
weekly/change-status
'
)
async
changeStatus
(@
Body
()
changeStatusDto
:
ChangeStatusDto
)
{
console
.
log
(
'
here
'
);
return
await
this
.
lotteryService
.
changeStatus
(
changeStatusDto
)
}
}
src/lottery/lottery.service.ts
View file @
c670bdce
import
{
HttpException
,
Injectable
}
from
'
@nestjs/common
'
;
import
{
InjectModel
}
from
'
@nestjs/mongoose
'
;
import
{
Model
}
from
'
mongoose
'
;
import
{
Model
,
Types
}
from
'
mongoose
'
;
import
{
of
}
from
'
rxjs
'
import
{
CommentDocument
}
from
'
src/instagram/models/comment.schema
'
;
import
{
FollowerDocument
}
from
'
src/instagram/models/follower.schema
'
;
...
...
@@ -39,52 +39,55 @@ export class LotteryService {
async
addResultsToDB
(
profileUsername
:
string
,
postArray
:
string
[])
{
await
this
.
lotteryResultModel
.
deleteMany
({})
let
foundUsernameInComment
=
await
this
.
commentModel
.
distinct
(
'
owner_username
'
)
let
foundUsernameInLike
=
await
this
.
likeModel
.
distinct
(
'
username
'
)
let
foundUsernames
=
new
Array
<
string
>
()
foundUsernameInComment
.
forEach
((
username
)
=>
{
if
(
!
foundUsernames
.
includes
(
username
))
{
foundUsernames
.
push
(
username
)
let
foundPost
let
foundUsernameInComment
=
await
this
.
commentModel
.
distinct
(
'
user_id
'
)
let
foundUsernameInLike
=
await
this
.
likeModel
.
distinct
(
'
user_id
'
)
let
foundUser_id
=
new
Array
<
any
>
()
foundUsernameInComment
.
forEach
((
user_id
)
=>
{
if
(
!
foundUser_id
.
includes
(
user_id
))
{
foundUser_id
.
push
(
user_id
)
}
})
foundUsernameInLike
.
forEach
((
user
name
)
=>
{
if
(
!
foundUser
names
.
includes
(
user
name
))
{
foundUser
names
.
push
(
user
name
)
foundUsernameInLike
.
forEach
((
user
_id
)
=>
{
if
(
!
foundUser
_id
.
includes
(
user
_id
))
{
foundUser
_id
.
push
(
user
_id
)
}
})
console
.
log
(
foundUser
names
);
console
.
log
(
foundUser
_id
);
const
comptitionArray
=
new
Array
<
any
>
();
let
index
=
1000
;
let
totalItems
=
foundUser
names
.
length
let
totalItems
=
foundUser
_id
.
length
let
count
=
0
for
await
(
const
user
name
of
foundUser
names
)
{
let
userScore
=
await
this
.
scoreService
.
calculateUserScore
(
user
name
,
profileUsername
,
postArray
)
for
await
(
const
user
_id
of
foundUser
_id
)
{
let
userScore
=
await
this
.
scoreService
.
calculateUserScore
(
user
_id
,
profileUsername
,
postArray
)
for
(
let
u
=
0
;
u
<
userScore
;
u
++
)
{
comptitionArray
.
push
({
index
,
username
:
username
,
await
this
.
lotteryResultModel
.
create
({
_id
:
new
Types
.
ObjectId
(),
index
:
`LT_
${
index
}
`
,
user_id
:
user_id
,
status
:
'
valid
'
})
index
++
;
console
.
log
(
`user
name
:
${
user
name
}
, index:
${
index
}
, score:
${
userScore
}
`
);
console
.
log
(
`user
_id
:
${
user
_id
}
, index:
${
index
}
, score:
${
userScore
}
`
);
}
console
.
log
(
`user index:
${
count
}
, total items:
${
totalItems
}
`
);
count
++
}
await
this
.
lotteryResultModel
.
insertMany
(
comptitionArray
);
return
'
successfull
'
;
}
async
getResultDb
()
{
return
await
this
.
lotteryResultModel
.
find
()
.
find
()
.
populate
(
"
user_id
"
,{
"
username
"
:
1
},
"
User
"
).
sort
({
"
status
"
:
1
})
.
select
({
username
:
1
,
index
:
1
,
status
:
1
});
}
async
changeStatus
(
changeStatus
:
ChangeStatusDto
){
let
foundUser
=
await
this
.
userModel
.
findOne
({
username
:
changeStatus
.
username
})
let
foundLottryResults
=
await
this
.
lotteryResultModel
.
find
({
user
name
:
changeStatus
.
username
user
_id
:
foundUser
.
_id
})
for
await
(
const
result
of
foundLottryResults
)
{
result
.
status
=
"
online
"
...
...
src/lottery/score.service.ts
View file @
c670bdce
...
...
@@ -24,25 +24,15 @@ export class ScoreService {
)
{
}
async
getUserLikesScore
(
username
:
string
,
profileUsername
:
string
,
postArray
:
string
[])
{
let
foundUser
=
await
this
.
userModel
.
findOne
({
username
})
let
foundProfile
=
await
this
.
userModel
.
findOne
({
username
:
profileUsername
})
let
foundFollower
=
await
this
.
followerModel
.
findOne
({
$and
:
[
{
user_id
:
foundUser
.
_id
},
{
account_id
:
foundProfile
.
_id
}
]
})
if
(
foundFollower
)
{
let
foundLikes
=
await
this
.
likeModel
.
find
({
username
})
return
foundLikes
.
length
}
else
{
return
0
}
async
getUserLikesScore
(
user_id
:
string
,
profileUsername
:
string
,
postArray
:
string
[])
{
let
foundLikes
=
await
this
.
likeModel
.
find
({
user_id
:
new
Types
.
ObjectId
(
user_id
)
})
return
foundLikes
.
length
}
async
getUserCommentsScore
(
user
name
:
string
,
profileUsername
:
string
,
postArray
:
string
[])
{
async
getUserCommentsScore
(
user
_id
:
string
,
profileUsername
:
string
,
postArray
:
string
[])
{
let
userCommentScore
=
new
Array
<
{
post_id
:
string
,
post_score
:
number
}
>
()
...
...
@@ -53,7 +43,7 @@ export class ScoreService {
})
})
let
foundUserComments
=
await
this
.
commentModel
.
find
({
owner_username
:
username
})
let
foundUserComments
=
await
this
.
commentModel
.
find
({
user_id
:
new
Types
.
ObjectId
(
user_id
)
})
for
await
(
const
comment
of
foundUserComments
)
{
...
...
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