Commit 7a715767 by Phạm Văn Đoan

xóa phần xử lý thừa

parent 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;
}
}
......@@ -4,7 +4,6 @@ namespace App\Console;
use App\Console\Commands\CalculateDailyListenCommand;
use App\Console\Commands\CalculateReportCommand;
use App\Console\Commands\CrawlerNctTrackListenCommand;
use App\Console\Commands\CrawlerTrackListenCommand;
use App\Console\Commands\CrontjobCommand;
use App\Console\Commands\ExportRankingCommand;
......@@ -52,9 +51,6 @@ class Kernel extends ConsoleKernel
SendWarningCommand::class,
CrawlerNctTrackListenCommand::class,
];
/**
......
......@@ -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
* 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
* 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 $crawlered
......@@ -308,9 +310,15 @@ class TrackRepository extends BaseRepository
}
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':
$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) {
$query->whereNull('composer_list');
}
......
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