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
ce49fc38
Commit
ce49fc38
authored
Aug 11, 2021
by
soheib
Browse files
add controllers
parent
8c6a77d0
Changes
9
Hide whitespace changes
Inline
Side-by-side
src/app.module.ts
View file @
ce49fc38
...
...
@@ -5,13 +5,33 @@ import { AppService } from './app.service';
import
{
InstagramModule
}
from
'
./instagram/instagram.module
'
;
import
{
LotteryModule
}
from
'
./lottery/lottery.module
'
;
import
{
InstagramService
}
from
'
./instagram/instagram.service
'
;
import
{
UserSchema
}
from
'
./instagram/models/user.schema
'
import
{
FollowerSchema
}
from
'
./instagram/models/follower.schema
'
import
{
LikeSchema
}
from
'
./instagram/models/like.schema
'
import
{
CommentSchema
}
from
'
./instagram/models/comment.schema
'
import
{
LottoryResultSchema
}
from
'
./instagram/models/LottoryResult.schema
'
@
Module
({
imports
:
[
MongooseModule
.
forRoot
(
'
mongodb://instagram:wcD3B5sGw0yQ@185.231.180.248:27017/instagram-lottry?serverSelectionTimeoutMS=5000&connectTimeoutMS=10000&authSource=admin
'
,
),
MongooseModule
.
forFeature
([
{
name
:
'
User
'
,
schema
:
UserSchema
},
]),
MongooseModule
.
forFeature
([
{
name
:
'
Follower
'
,
schema
:
FollowerSchema
},
]),
MongooseModule
.
forFeature
([
{
name
:
'
Like
'
,
schema
:
LikeSchema
},
]),
MongooseModule
.
forFeature
([
{
name
:
'
Comment
'
,
schema
:
CommentSchema
},
]),
MongooseModule
.
forFeature
([
{
name
:
'
LottryResult
'
,
schema
:
LottoryResultSchema
},
]),
InstagramModule
,
LotteryModule
,
],
...
...
src/instagram/dto/get-comments-dto.ts
0 → 100644
View file @
ce49fc38
export
class
GetCommentsDto
{
username
:
string
password
:
string
profile
:
string
post_short_code
:
string
}
\ No newline at end of file
src/instagram/dto/get-followers-dto.ts
0 → 100644
View file @
ce49fc38
export
class
GetFollowersDto
{
username
:
string
password
:
string
profile
:
string
}
\ No newline at end of file
src/instagram/dto/get-likes-dto.ts
0 → 100644
View file @
ce49fc38
export
class
GetLikesDto
{
username
:
string
password
:
string
profile
:
string
post_short_code
:
string
}
\ No newline at end of file
src/instagram/instagram.controller.ts
View file @
ce49fc38
import
{
Controller
}
from
'
@nestjs/common
'
;
import
{
Body
,
Controller
,
Get
,
Param
,
Post
}
from
'
@nestjs/common
'
;
import
{
GetCommentsDto
}
from
'
./dto/get-comments-dto
'
import
{
GetFollowersDto
}
from
'
./dto/get-followers-dto
'
import
{
GetLikesDto
}
from
'
./dto/get-likes-dto
'
import
{
InstagramService
}
from
'
./instagram.service
'
@
Controller
(
'
instagram
'
)
export
class
InstagramController
{}
export
class
InstagramController
{
constructor
(
private
instagramService
:
InstagramService
)
{
}
@
Get
(
'
get-json-followers
'
)
async
getJsonDataFollowers
()
{
await
this
.
instagramService
.
getFollowersFromJsonData
()
return
"
proccess started successfully
"
}
@
Post
(
'
get-followers
'
)
async
getFollowers
(@
Body
()
getFollowers
:
GetFollowersDto
)
{
return
await
this
.
instagramService
.
getFollowersFromInstaLoader
(
getFollowers
.
username
,
getFollowers
.
password
,
getFollowers
.
profile
)
}
@
Post
(
'
get-likes
'
)
async
getLikes
(@
Body
()
getLikes
:
GetLikesDto
)
{
return
this
.
instagramService
.
getLikesFromInstaLoader
(
getLikes
.
username
,
getLikes
.
password
,
getLikes
.
post_short_code
,
getLikes
.
profile
)
}
@
Post
(
'
get-comments
'
)
async
getComments
(@
Body
()
getComments
:
GetCommentsDto
)
{
return
await
this
.
instagramService
.
getCommentsFromInstaLoader
(
getComments
.
username
,
getComments
.
password
,
getComments
.
post_short_code
,
getComments
.
profile
)
}
}
src/instagram/instagram.service.ts
View file @
ce49fc38
...
...
@@ -48,29 +48,42 @@ export class InstagramService implements OnApplicationBootstrap {
})
}
}
console
.
log
(
'
end of proccess...
'
);
console
.
log
(
'
end of proccess...
'
)
return
{
message
:
"
successfull
"
}
}
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
}
`
,]);
getLikesProccess
.
stdout
.
on
(
'
data
'
,
function
(
data
)
{
console
.
log
(
'
start collecting likes from python script ...
'
);
console
.
log
(
data
.
toString
())
});
getLikesProccess
.
on
(
'
error
'
,
(
err
)
=>
{
console
.
log
(
`child process has error
${
err
}
`
);
return
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
}
`
);
return
"
successfull
"
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
}
`
]);
getCommentsProccess
.
stdout
.
on
(
'
data
'
,
function
(
data
)
{
...
...
@@ -80,16 +93,25 @@ export class InstagramService implements OnApplicationBootstrap {
getCommentsProccess
.
on
(
'
error
'
,
(
err
)
=>
{
console
.
log
(
`child process has error
${
err
}
`
);
return
err
status
=
"
error
"
err_message
=
err
.
message
});
getCommentsProccess
.
on
(
'
close
'
,
(
code
)
=>
{
console
.
log
(
`child process close all stdio with code
${
code
}
`
);
return
"
successfull
"
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
}
`
]);
getFollowersProccess
.
stdout
.
on
(
'
data
'
,
function
(
data
)
{
...
...
@@ -99,13 +121,20 @@ export class InstagramService implements OnApplicationBootstrap {
getFollowersProccess
.
on
(
'
error
'
,
(
err
)
=>
{
console
.
log
(
`child process has error
${
err
}
`
);
return
err
status
=
"
error
"
err_message
=
err
.
message
});
getFollowersProccess
.
on
(
'
close
'
,
(
code
)
=>
{
console
.
log
(
`child process close all stdio with code
${
code
}
`
);
return
"
successfull
"
status
=
"
successfull
"
});
if
(
status
===
"
error
"
){
return
{
message
:
err_message
}
}
if
(
status
===
"
successfull
"
){
return
{
message
:
"
successfull
"
}
}
}
async
findOrCreateUser
(
username
:
string
)
{
...
...
src/lottery/dto/calculate-score-dto.ts
0 → 100644
View file @
ce49fc38
export
class
CalculateScoreDto
{
profile_username
:
string
post_array
:
string
[]
}
\ No newline at end of file
src/lottery/dto/weekly-search-dto.ts
View file @
ce49fc38
export
class
WeeklySearchDto
{
username
:
string
profile_username
:
string
post_array
:
string
[]
}
\ No newline at end of file
src/lottery/lottery.controller.ts
View file @
ce49fc38
import
{
Body
,
Query
,
Controller
,
Get
,
Post
}
from
'
@nestjs/common
'
;
import
{
CalculateScoreDto
}
from
'
./dto/calculate-score-dto
'
import
{
WeeklySearchDto
}
from
'
./dto/weekly-search-dto
'
import
{
LotteryService
}
from
'
./lottery.service
'
;
@
Controller
(
'
lottery
'
)
...
...
@@ -7,19 +9,20 @@ export class LotteryController {
constructor
(
private
lotteryService
:
LotteryService
)
{
}
//weekly lottery apies:
@
Post
(
'
weekly/search
'
)
async
getUserResults
(@
Body
()
username
:
string
)
{
return
await
this
.
lotteryService
.
getUserScore
(
username
);
async
getUserResults
(@
Body
()
searchDto
:
WeeklySearchDto
)
{
return
await
this
.
lotteryService
.
getUserScore
(
searchDto
.
username
,
searchDto
.
profile_username
,
searchDto
.
post_array
)
}
@
Post
(
'
weekly/calculate-score
'
)
async
getFollowers
()
{
return
await
this
.
lotteryService
.
addResultsToDB
();
async
addResultsToDb
(
calculateScoreDto
:
CalculateScoreDto
)
{
return
await
this
.
lotteryService
.
addResultsToDB
(
calculateScoreDto
.
profile_username
,
calculateScoreDto
.
post_array
)
}
@
Get
(
'
weekly/get-lottory-result
'
)
async
getResultDb
()
{
return
await
this
.
lotteryService
.
getResultDb
()
;
return
await
this
.
lotteryService
.
getResultDb
()
}
}
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