Commit a077d701 by Phạm Văn Đoan

fix lỗi lấy lượt nghe từ zing

parent 4be75d07
...@@ -46,10 +46,12 @@ class CrawlerNctTrackListenCommand extends Command ...@@ -46,10 +46,12 @@ class CrawlerNctTrackListenCommand extends Command
public function handle() public function handle()
{ {
$from_page = 'nct'; $from_page = 'nct';
$limit = 50; $limit = 100;
//$crawlered = $this->trackRepository->getCrawlerListenInserted($from_page, false); $yesterday = Carbon::yesterday()->format('Y-m-d');
$crawlered = CrawlerListenNct::groupBy('track_id')->pluck('track_id')->all(); $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); echo "\n Tổng số bài hát đã lấy lượt nghe hôm nay: " . count($crawlered);
...@@ -59,6 +61,7 @@ class CrawlerNctTrackListenCommand extends Command ...@@ -59,6 +61,7 @@ class CrawlerNctTrackListenCommand extends Command
echo "\n Tổng số bài hát cần lấy lượt nghe: " . $total; echo "\n Tổng số bài hát cần lấy lượt nghe: " . $total;
$listen = [];
foreach ($inserted as $key => $track) { foreach ($inserted as $key => $track) {
$listen[] = $this->privateGetListen($from_page, $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']; echo "\n " . ($key+1) . "/" . $total . ": Đã lấy lịch sử lượt nghe bài hát có ID= " . $track['id'];
......
...@@ -139,7 +139,7 @@ class CrawlerTrackListenCommand extends Command ...@@ -139,7 +139,7 @@ class CrawlerTrackListenCommand extends Command
break; break;
case 'nct': case 'nct':
$url = getNctUrlGetCounter($track['id_nct']); /*$url = getNctUrlGetCounter($track['id_nct']);
$curl = cURL($url); $curl = cURL($url);
$response = json_decode($curl); $response = json_decode($curl);
...@@ -147,6 +147,28 @@ class CrawlerTrackListenCommand extends Command ...@@ -147,6 +147,28 @@ class CrawlerTrackListenCommand extends Command
if (isset($response->data) && isset($response->data->songs) && $response->data->songs->{$track['id_nct']} > 0) { if (isset($response->data) && isset($response->data->songs) && $response->data->songs->{$track['id_nct']} > 0) {
$listen = $response->data->songs->{$track['id_nct']}; $listen = $response->data->songs->{$track['id_nct']};
} }
}*/
/* Tính lượt nghe lấy data từ biểu đồ lượt nghe */
$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];
}*/
//echo "\n " . end($response->cumuChart) . " | " . end($response->dailyChart) . " : " . $track['id_nct'];
$listen = end($response->cumuChart) + end($response->dailyChart);
}
} }
break; break;
......
Markdown is supported
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