Ejemplo n.º 1
0
<?php

require_once __DIR__ . '/../includes/mysqli_connect.php';
require_once __DIR__ . '/../includes/functions.php';
$time_start = microtime(true);
set_time_limit(86400);
header('Content-Type: text/html; charset=utf-8');
$mysqli->set_charset("utf8");
$count = 0;
if ($i = $mysqli->query("SELECT id FROM actors")) {
    while ($person = mysqli_fetch_assoc($i)) {
        $id = getPersonType($person['id']);
        mysqli_query($mysqli, "UPDATE actors SET person_id = {$id} WHERE id = {$person['id']}");
    }
}
$mysqli->close();
$time_end = microtime(true);
$execution_time = $time_end - $time_start;
//execution time of the script
// REPORTING
echo "\n---------------------------\n\n";
echo "Finished executing " . __FILE__ . " at " . date('g:i:s A') . " on " . date('F j, Y') . ".\n";
echo "Total Execution Time: " . $execution_time / 60 . " minutes (" . $execution_time / 3600 . " hours)";
if ($count) {
    echo "\n" . $count . " requests in " . $execution_time . " seconds means 1 request in " . $execution_time / $count . " seconds.";
}
echo "\n\n---------------------------\n";
// assume you have an actor id $id. Also assume you have included includes/functions.php (so you have getData)
// you should have an array of queries at the end: one for movies, one for keywords, one for movie_keywords, one for imdb,  $moviesQuery at the end, to insert the movie.
// check if we already have this person in DB
$count = mysqli_fetch_assoc($mysqli->query("SELECT COUNT(id) FROM actors WHERE id={$id}"));
$doNotHave = $count['COUNT(id)'] == 0 ? true : false;
$queryArr = array();
if ($doNotHave) {
    $a = getData("https://api.themoviedb.org/3/person/{$id}?api_key={$apikey}");
    if ($a === NULL) {
        echo 'Error parsing json';
        continue;
    }
    if (strlen($a->name) > 0) {
        $name = $a->name;
        $person_id = getPersonType($id);
        $photo = $a->profile_path;
        $about = $a->biography;
        $dob = $a->birthday;
        $dod = $a->deathday;
        $imdb_id = $a->imdb_id;
        //mysqli_query($mysqli, "DELETE FROM actors WHERE id=$id");
        $b = getData("https://api.themoviedb.org/3/person/{$id}/tagged_images?api_key={$apikey}");
        $backdrop = "";
        $backdrop_id = 0;
        if ($b->results[0]) {
            foreach ($b->results as $bd) {
                if ($bd->aspect_ratio > 1.7) {
                    $backdrop = $bd->file_path;
                    $backdrop_id = $bd->media->id;
                    break;