<commit_before><!doctype html>
<html>
<head>
<meta charset="UTF-8" />
<title></title>
</head>
<body>
<?php
	
	//Connect to DB
	include 'db_connection.php';
	
	if (!function_exists('curl_init')){
		die('CURL is not installed!');
	}

	if(isset($_POST["filmTitle"])){
		$query=$_POST["filmTitle"];
		
		//$query=$_GET["q"];
		$apikey = '';
		$q = urlencode($query); // make sure to url encode an query parameters
		
		// construct the query with our apikey and the query we want to make
		$endpoint = 'http://api.rottentomatoes.com/api/public/v1.0/movies.json?apikey=' . $apikey . '&q=' . $q . '&page_limit=5';
		
		$search_results = getJsonCurl($endpoint);

		if(isset($_POST["json"])){
			echo $search_results;
		}
		
		// play with the data!
		$movies = $search_results->movies;
		
		echo '<ul>';
		
		foreach ($movies as $movie) {
		
			echo '<li>';
			//<a href="http://api.rottentomatoes.com/api/public/v1.0/movies/' . $movie->id . '.json?apikey=' . $apikey . '">' . $movie->title . " (" . $movie->year . ")</a><br>";
			$details = getDetailMovie($movie->id);
			echo '</li>';
		
		}
		
		echo '</ul>';
		
	}

	function getJsonCurl($url){
		
		// setup curl to make a call to the endpoint
		$session = curl_init($url);
		
		// indicates that we want the response back
		curl_setopt($session, CURLOPT_RETURNTRANSFER, true);
		
		// exec curl and get the data back
		$data = curl_exec($session);
		
		// remember to close the curl session once we are finished retrieveing the data
		curl_close($session);
		
		/*
		// decode the json data to make it easier to parse the php
		echo $data;
		*/
		
		$search_results = json_decode($data);
		
		if ($search_results === NULL) die('Error parsing json');
		
		return $search_results;
	}
		
	function getDetailMovie($id){
	
		global $apikey;
		
		$url = "http://api.rottentomatoes.com/api/public/v1.0/movies/" . $id . ".json?apikey=". $apikey;
		$result = getJsonCurl($url);
		
		//Get TITLE
		if(isset($result->title)){
			$title = $result->title;
		}
		
		//Get YEAR
		if(isset($result->year)){
			$year = $result->year;
		}

		//Send TITLE and YEAR to DB
		
		$sql = "SELECT * FROM film_title_table WHERE rotten_tomatoes_api_id='$id'";
			
		$sqlResult = mysql_query ($sql);
		
		if (! $tab_line = mysql_fetch_row($sqlResult)){
							
			$writeFilmTitle = "INSERT INTO film_title_table (film_title, release_year, rotten_tomatoes_api_id) VALUES ('$title', '$year', '$id')";
			mysql_query ($writeFilmTitle);
			
			$newDoc = "INSERT INTO doc (doc_title, doc_usage) VALUES ('$title', '1')";
			mysql_query ($newDoc);
			
		}
		
		//Get DIRECTOR NAME and send to DB
		if(isset($result->abridged_directors)){<commit_msg>Correction<commit_after><!doctype html>
<html>
<head>
<meta charset="UTF-8" />
<title></title>
</head>
<body>
<?php
	
	//Connect to DB
	include 'db_connection.php';
	
	if (!function_exists('curl_init')){
		die('CURL is not installed!');
	}

	if(isset($_POST["filmTitle"])){
		$query=$_POST["filmTitle"];
		
		//$query=$_GET["q"];
		$apikey = '';
		$q = urlencode($query); // make sure to url encode an query parameters
		
		// construct the query with our apikey and the query we want to make
		$endpoint = 'http://api.rottentomatoes.com/api/public/v1.0/movies.json?apikey=' . $apikey . '&q=' . $q . '&page_limit=5';
		
		$search_results = getJsonCurl($endpoint);

		if(isset($_POST["json"])){
			echo $search_results;
		}
		
		// play with the data!
		$movies = $search_results->movies;
		
		echo '<ul>';
		
		foreach ($movies as $movie) {
		
			echo '<li>';
			//<a href="http://api.rottentomatoes.com/api/public/v1.0/movies/' . $movie->id . '.json?apikey=' . $apikey . '">' . $movie->title . " (" . $movie->year . ")</a><br>";
			$details = getDetailMovie($movie->id);
			echo '</li>';
		
		}
		
		echo '</ul>';
		
	}

	function getJsonCurl($url){
		
		// setup curl to make a call to the endpoint
		$session = curl_init($url);
		
		// indicates that we want the response back
		curl_setopt($session, CURLOPT_RETURNTRANSFER, true);
		
		// exec curl and get the data back
		$data = curl_exec($session);
		
		// remember to close the curl session once we are finished retrieveing the data
		curl_close($session);
		
		/*
		// decode the json data to make it easier to parse the php
		echo $data;
		*/
		
		$search_results = json_decode($data);
		
		if ($search_results === NULL) die('Error parsing json');
		
		return $search_results;
	}
		
	function getDetailMovie($id){
	
		global $apikey;
		
		$url = "http://api.rottentomatoes.com/api/public/v1.0/movies/" . $id . ".json?apikey=". $apikey;
		$result = getJsonCurl($url);
		
		//Get TITLE
		if(isset($result->title)){
			$title = $result->title;
		}

		//Send TITLE and YEAR to DB
		if(isset($result->year)){
			$year = $result->year;
		
			$sql = "SELECT * FROM film_title_table WHERE rotten_tomatoes_api_id='$id'";
				
			$sqlResult = mysql_query ($sql);
			
			if (! $tab_line = mysql_fetch_row($sqlResult)){
								
				$writeFilmTitle = "INSERT INTO film_title_table (film_title, release_year, rotten_tomatoes_api_id) VALUES ('$title', '$year', '$id')";
				mysql_query ($writeFilmTitle);
				
				$newDoc = "INSERT INTO doc (doc_title, doc_usage) VALUES ('$title', '1')";
				mysql_query ($newDoc);
			
			}
			
		}
		
		//Get DIRECTOR NAME and send to DB
		if(isset($result->abridged_directors)){
{'fraction_non_alphanumeric': 0.1739620514747323, 'fraction_numerical': 0.0033815517565282736, 'mean_word_length': 3.238853503184713, 'pattern_counts': {'":': 0, '<': 35, '<?xml version=': 0, '>': 53, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1744326', 'n_tokens_mistral': 2210, 'n_tokens_neox': 1818, 'n_words': 453}