blob: 96afa135237939622e5c992a655035a6727dbfbd (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
<?php
namespace App\Libraries;
use Illuminate\Support\Facades\DB;
use App\Libraries\AnimeSeason;
use App\Anime;
use App\AnimeStats;
use Carbon\Carbon;
use Jikan\MyAnimeList\MalClient;
use Jikan\Helper\Constants;
class AnimeSeason {
public $year;
public $name;
public $anime;
public function __construct() {
}
public function save() {
#Anime::where('mal_id', 2 );
$jikan = new MalClient;
$season = $jikan->getSeasonal(
(new \Jikan\Request\Seasonal\SeasonalRequest(
))
);
$this->year = $season->seasonYear;
$this->name = $season->seasonName;
foreach($season->anime as $entry) {
/**
* Debug
if ( DB::table('stats')->where('mal_id', $entry->getMalID())->exists() ) {
continue;
}
#*/
/**
* Sleep to avoid 403 by MAL.
*/
sleep(10);
$count++;
$check = Anime::where('mal_id', $entry->getMalID() )->first()->get();
if ( ! is_null($check) ) {
/**
* We already have this anime saved.
*/
}
$anime = new Anime();
$anime->fill( $entry->getMalID() );
if( ! DB::table('anime')->where('mal_id', $entry->getMalID() )->exists() ) {
$anime->save();
}
$animeStats = new AnimeStats();
$animeStats->fill( $entry->getMalID(), $this->year, $this->name );
$this->anime[] = $animeStats;
$animeStats->save();
}
}
}
|