Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
crawler.vmusicchart.vn
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Phạm Văn Đoan
crawler.vmusicchart.vn
Commits
7a715767
Commit
7a715767
authored
Jun 23, 2020
by
Phạm Văn Đoan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
xóa phần xử lý thừa
parent
9a529814
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
10 additions
and
124 deletions
+10
-124
CrawlerNctTrackListenCommand.php
app/Console/Commands/CrawlerNctTrackListenCommand.php
+0
-118
Kernel.php
app/Console/Kernel.php
+0
-4
TrackRepository.php
app/Repositories/TrackRepository.php
+10
-2
No files found.
app/Console/Commands/CrawlerNctTrackListenCommand.php
deleted
100644 → 0
View file @
9a529814
<?php
namespace
App\Console\Commands
;
use
App\Models\CrawlerListenNct
;
use
App\Repositories\TrackRepository
;
use
Carbon\Carbon
;
use
Illuminate\Console\Command
;
class
CrawlerNctTrackListenCommand
extends
Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected
$signature
=
'crawler:get-nct-listen {limit?}'
;
/**
* The console command description.
*
* @var string
*/
protected
$description
=
'Lấy lượt nghe ở DOM từ trang của NCT'
;
protected
$trackRepository
;
/**
* Create a new command instance.
*
* CrawlerNctTrackListenCommand constructor.
* @param TrackRepository $trackRepository
*/
public
function
__construct
(
TrackRepository
$trackRepository
)
{
parent
::
__construct
();
ini_set
(
'max_execution_time'
,
-
1
);
$this
->
trackRepository
=
$trackRepository
;
}
/**
* Execute the console command.
*
* @return mixed
*/
public
function
handle
()
{
$from_page
=
'nct'
;
$limit
=
100
;
$yesterday
=
Carbon
::
yesterday
()
->
format
(
'Y-m-d'
);
$crawlered
=
CrawlerListenNct
::
groupBy
(
'track_id'
)
->
where
(
'date_chart'
,
'='
,
$yesterday
)
->
pluck
(
'track_id'
)
->
all
();
echo
"
\n
Tổng số bài hát đã lấy lượt nghe hôm nay: "
.
count
(
$crawlered
);
// Lấy mảng bài hát theo từng hệ thống nhạc
$inserted
=
$this
->
trackRepository
->
getTrackBySource
(
$from_page
,
$crawlered
,
$limit
);
$total
=
count
(
$inserted
);
echo
"
\n
Tổng số bài hát cần lấy lượt nghe: "
.
$total
;
$listen
=
[];
foreach
(
$inserted
as
$key
=>
$track
)
{
$listen
[]
=
$this
->
privateGetListen
(
$from_page
,
$track
);
echo
"
\n
"
.
(
$key
+
1
)
.
"/"
.
$total
.
": Đã lấy lịch sử lượt nghe bài hát có ID= "
.
$track
[
'id'
];
}
if
(
count
(
$listen
)
>
0
)
{
foreach
(
$listen
as
$key
=>
$array_listen
)
{
if
(
count
(
$array_listen
)
>
0
)
{
foreach
(
$array_listen
as
$val
)
{
CrawlerListenNct
::
updateOrCreate
(
[
'track_id'
=>
$val
[
'track_id'
],
'date_chart'
=>
$val
[
'date_chart'
]
],
[
'cumu_chart'
=>
$val
[
'cumu_chart'
],
'daily_chart'
=>
$val
[
'daily_chart'
],
'created_at'
=>
Carbon
::
now
(),
'updated_at'
=>
Carbon
::
now
()
]
);
}
}
}
}
echo
"
\n
Kết thúc.
\n
"
;
}
private
function
privateGetListen
(
$src
,
$track
)
{
$listen
=
[];
/* Xử lý mới sau khi bị chặn */
$url
=
getNctUrlGetCounterForChart
(
$track
[
'id_nct'
]);
$curl
=
cURL
(
$url
);
$response
=
json_decode
(
$curl
);
if
(
isset
(
$response
->
status
)
&&
$response
->
status
==
'Success'
)
{
if
(
isset
(
$response
->
dailyChart
)
&&
isset
(
$response
->
dateChart
)
&&
isset
(
$response
->
cumuChart
)
&&
is_array
(
$response
->
dailyChart
)
&&
is_array
(
$response
->
dateChart
)
&&
is_array
(
$response
->
cumuChart
))
{
foreach
(
$response
->
dailyChart
as
$key
=>
$val
)
{
$listen
[
$key
][
'track_id'
]
=
$track
[
'id'
];
$listen
[
$key
][
'daily_chart'
]
=
$val
;
$listen
[
$key
][
'date_chart'
]
=
date
(
'Y-m-d'
,
strtotime
(
str_replace
(
'/'
,
'-'
,
$response
->
dateChart
[
$key
])));
$listen
[
$key
][
'cumu_chart'
]
=
$response
->
cumuChart
[
$key
];
}
}
}
return
$listen
;
}
}
app/Console/Kernel.php
View file @
7a715767
...
@@ -4,7 +4,6 @@ namespace App\Console;
...
@@ -4,7 +4,6 @@ namespace App\Console;
use
App\Console\Commands\CalculateDailyListenCommand
;
use
App\Console\Commands\CalculateDailyListenCommand
;
use
App\Console\Commands\CalculateReportCommand
;
use
App\Console\Commands\CalculateReportCommand
;
use
App\Console\Commands\CrawlerNctTrackListenCommand
;
use
App\Console\Commands\CrawlerTrackListenCommand
;
use
App\Console\Commands\CrawlerTrackListenCommand
;
use
App\Console\Commands\CrontjobCommand
;
use
App\Console\Commands\CrontjobCommand
;
use
App\Console\Commands\ExportRankingCommand
;
use
App\Console\Commands\ExportRankingCommand
;
...
@@ -52,9 +51,6 @@ class Kernel extends ConsoleKernel
...
@@ -52,9 +51,6 @@ class Kernel extends ConsoleKernel
SendWarningCommand
::
class
,
SendWarningCommand
::
class
,
CrawlerNctTrackListenCommand
::
class
,
];
];
/**
/**
...
...
app/Repositories/TrackRepository.php
View file @
7a715767
...
@@ -292,6 +292,8 @@ class TrackRepository extends BaseRepository
...
@@ -292,6 +292,8 @@ class TrackRepository extends BaseRepository
* Lấy ds bài hát chưa lấy lượt nghe trong ngày theo từng hệ thống nhạc
* Lấy ds bài hát chưa lấy lượt nghe trong ngày theo từng hệ thống nhạc
* Bài nào đã lấy rồi thì sẽ ko lấy nữa
* Bài nào đã lấy rồi thì sẽ ko lấy nữa
* Mỗi lần quét 500 bài cho đến hết
* Mỗi lần quét 500 bài cho đến hết
* Các bài chỉ lấy ở Zing: 1198,1700,1954,3223,3334,3357,3529,3688
* Các bài chỉ lấy ở NCT: 1139,3835
*
*
* @param string $src
* @param string $src
* @param $crawlered
* @param $crawlered
...
@@ -308,9 +310,15 @@ class TrackRepository extends BaseRepository
...
@@ -308,9 +310,15 @@ class TrackRepository extends BaseRepository
}
}
switch
(
$src
)
{
switch
(
$src
)
{
case
'zing'
:
$query
->
whereNotNull
(
'id_zing'
)
->
where
(
'id_zing'
,
'<>'
,
''
);
break
;
case
'zing'
:
$query
->
whereNotNull
(
'id_zing'
)
->
where
(
'id_zing'
,
'<>'
,
''
)
->
whereNotIn
(
'id'
,
[
1139
,
3835
]);
break
;
case
'nct'
:
case
'nct'
:
$query
->
whereNotNull
(
'id_nct'
)
->
where
(
'id_nct'
,
'<>'
,
''
);
$query
->
whereNotNull
(
'id_nct'
)
->
where
(
'id_nct'
,
'<>'
,
''
)
->
whereNotIn
(
'id'
,
[
1198
,
1700
,
1954
,
3223
,
3334
,
3357
,
3529
,
3688
]);
if
(
$is_update_composer
)
{
if
(
$is_update_composer
)
{
$query
->
whereNull
(
'composer_list'
);
$query
->
whereNull
(
'composer_list'
);
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a 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