Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jonathan-nwosu/28ad897d9d07794ca20bd5ebbcc8bccc to your computer and use it in GitHub Desktop.
Save jonathan-nwosu/28ad897d9d07794ca20bd5ebbcc8bccc to your computer and use it in GitHub Desktop.
Note: APIs have been deprecated (Created in 2015)
<!doctype html>
<html lang="en-US">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<title>My product (sentview)</title>
<link rel="stylesheet" type="text/css" href="sentiment_analysis.css">
<link rel="stylesheet" type="text/css" href="http://fonts.googleapis.com/css?family=Oldenburg">
<link href='http://fonts.googleapis.com/css?family=Squada+One' rel='stylesheet' type='text/css'>
<link href='http://fonts.googleapis.com/css?family=Oswald:700' rel='stylesheet' type='text/css'>
<link href='http://fonts.googleapis.com/css?family=Oswald:500' rel='stylesheet' type='text/css'>
<link href='http://fonts.googleapis.com/css?family=Oswald:400' rel='stylesheet' type='text/css'>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
</head>
<div id="wrap">
<header>
<div class='top_wrap'>
<div class = "logo"><img src="img/sentview_logo.png" width="160px" height="55px"></img></div>
<div class="title"><?php $company_name = ucwords($_GET['product']); echo $company_name;?> sentiment analysis</div>
<div id='dropdown' class='ddmenu'>
<?php include('session.php'); echo $username;?>
<ul>
<li><a href="http://sentview.com/profile.php">Home</a></li>
<li><a href='http://www.sentview.com/session_end.php'>Sign Out</a></li>
</ul>
</div>
</div>
</header>
<body>
<table class='menu_table'>
<tr>
<td class='table_pic'><img src="img/clip_pic.png" width="35px" height="35px"></img></td>
<td class='table_text'><a href="http://sentview.com/profile.php" style='text-decoration: none;'>My products</a></td>
</tr>
<tr>
<td class='table_pic'><img src="img/messenger_pic.png" width="33px" height="33px"></img></td>
<td class='table_text'><a href="http://sentview.com/competitor_products.php" style='text-decoration: none;'>Competitor products</a></td>
</tr>
<tr>
<td class='table_pic'><img src="img/overtime_pic.png" width="33px" height="33px"></img></td>
<td class='table_text'><a href="http://sentview.com/myplanner.php" style='text-decoration: none;'>My tracker</a></td>
</tr>
</table>
<div class="clipboard_pic"><img src="http://sentview.com/wp-content/uploads/2015/07/check-list-vector-icon-ai-58702-300x300.jpg" height="150px;" width="150px;"></img></div>
</body>
</div>
<script type='text/javascript'>
$("#dropdown").on("click", function(e){
if($(this).hasClass("open")) {
$(this).removeClass("open");
$(this).children("ul").slideUp("fast");
} else {
$(this).addClass("open");
$(this).children("ul").slideDown("fast");
}
});
</script>
</html>
<?php
require 'vendorMp4/autoload.php';
require 'vendorMp4/mashape/unirest-php/src/Unirest.php';
require 'vendor/autoload.php';
require 'vendorParse/autoload.php';
use GuzzleHttp\Client;
use Parse\ParseClient;
use Parse\ParseObject;
use Parse\ParseQuery;
use Parse\ParseUser;
ParseClient::initialize('up89hQ7MHKmtU8ivu1jAV3zldZJkFehKwmUHJkAy', '7LpIiQ6pamLRxtUWr92BMp6hc99oRiTM0VGWkT6i', 'wUH4Fg48MjhAzWGnH2vou3nwihALB4Hd2iZXk0v5');
Unirest\Request::verifyPeer(false);
Unirest\Request::setMashapeKey('CA8O3bkPS2mshlCR339WxR0570eTp1WoUF7jsnsp8qmGgGLUqJ');
set_time_limit(0);
$product_twitter = $_GET['product'];
$twitter_number = 40;
require_once 'lib/twitteroauth.php';
define('CONSUMER_KEY', 'TurnhYtmEN5T4BsoY6SZfbSQq');
define('CONSUMER_SECRET', 'bsDsWYYpT3qB6tWFeNVxaJZ95M8Y9ThhQ2Hh1Fx9SopqjzQPuc');
define('ACCESS_TOKEN', '3371097645-HtiTZC2Y9ZTN2lGD3znFucEtNSRsoWtqMYZ763p');
define('ACCESS_TOKEN_SECRET', 'ziUJO8DdpbdGLwt0MJq9ZDaAwlZyGykJ2cq8yCzk4jQwl');
function search(array $product_twitter)
{
$toa = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, ACCESS_TOKEN, ACCESS_TOKEN_SECRET);
return $toa->get('search/tweets', $product_twitter);
}
try {
$currentUser = ParseUser::getCurrentUser();
if ($currentUser) {
$query = ParseUser::query();
$query->equalTo("username", $username);
$results = $query->find();
$products = $results[0]->products;
$company = $results[0]->company;
echo "<div class='middle_wrapper'><div class='customer_review_title'>Customer review:</div>
<div class='platform_title'>Platform:</div>
<div class='sentiment_score_title'>Sentiment score:</div><div class='date_title'>Date of review:</div>
<div class='top_line'><hr></div></div>";
if(!empty($_GET['product'])){
$product_clean = $_GET['product'];
$product_strip_tags = strip_tags($product_clean);
$product_strip_slashes = stripslashes($product_strip_tags);
$product_lower_case= strtolower($product_strip_slashes);
$company_product = str_replace(' ', '_',$product_lower_case);
$number1 = 1;
$query = new ParseQuery("Sentiment");
$query->ascending("sentiment_date");
$query->equalTo("company_username", $username);
$query->equalTo("product", $company_product);
$query->equalTo("sentiment_type", $number1);
$results = $query->find();
if(!empty($results)){
$sentiment_array = $results[0]->sentiment;
$value = 'Parse\ParseObject Object';
foreach ($results as $key => $value) {
}
echo "<div class='products'>What customers like:</div>";
for ($i = 0; $i <= $key; $i++) {
$sentiment = $results[$i] ->sentiment[0];
$sentiment_score = $results[$i]->sentiment_score;
$sentiment_date = $results[$i]->sentiment_date;
$sentiment_data_new = $sentiment_date->format('Y-m-d H:i:s');
$sentiment_data = substr($sentiment_data_new,0, -8);
$platform = $results[$i]->platform;
echo "<table class='table' style='width:75%' >
<tr>
<td><div class='sentiment' style='width:80%'>$sentiment</div></td>
<td style='left: 3%;'><div class='platform_text'> $platform</div></td>
<td style='left: -18.5%;'><div class='sentiment_date'>$sentiment_data</div></td>
<td style='left: -15.5%;'><div class='sentiment_score'>$sentiment_score</div></td>
<tr>
</table>";
echo "<div class='seperation_lines'><hr></div>";
}
} else {
echo "<div class='products'>What customers like:</div>";
echo "<table>
<tr>
<td style='left: 52%; top: -186px;'><div class='sentiment'>No new reviews<br></div></td>
<td style='left: 115%; width: 15%; top: -186px;' ><div class='sentiment_score'>No new data</div>
</td>
<tr>
</table>
<div class='seperation_lines'><hr></div>";
}
$number2 = 2;
$query = new ParseQuery("Sentiment");
$query->ascending("sentiment_date");
$query->equalTo("company_username", $username);
$query->equalTo("product", $company_product);
$query->equalTo("sentiment_type", $number2);
$results = $query->find();
if(!empty($results)){
$sentiment_array = $results[0]->sentiment;
$value = 'Parse\ParseObject Object';
foreach ($results as $key => $value) {
}
echo "<div class='products'>What customers don't like:</div>";
for ($i = 0; $i <= $key; $i++) {
$sentiment = $results[$i] ->sentiment[0];
$sentiment_score = $results[$i]->sentiment_score;
$sentiment_date = $results[$i]->sentiment_date;
$sentiment_data_new = $sentiment_date->format('Y-m-d H:i:s');
$sentiment_data = substr($sentiment_data_new,0, -8);
$platform = $results[$i]->platform;
echo "<table class='table' style='width:75%' >
<tr>
<td><div class='sentiment' style='width:80%'>$sentiment</div></td>
<td style='left: 3%;'><div class='platform_text'> $platform</div></td>
<td style='left: -18.5%;'><div class='sentiment_date'>$sentiment_data</div></td>
<td style='left: -15.5%;'><div class='sentiment_score'>$sentiment_score</div></td>
<tr>
</table>";
echo "<div class='seperation_lines'><hr></div>";
}
} else {
echo "<div class='products'>What customers don't like:</div>";
echo "<table>
<tr>
<td style='left: 52%; top: -186px;'><div class='sentiment'>No new reviews<br></div></td>
<td style='left: 115%; width: 15%; top: -186px;' ><div class='sentiment_score'>No new data</div>
</td>
<tr>
</table>
<div class='seperation_lines'><hr></div>";
}
$number3 = 3;
$query = new ParseQuery("Sentiment");
$query->ascending("sentiment_date");
$query->equalTo("company_username", $username);
$query->equalTo("product", $company_product);
$query->equalTo("sentiment_type", $number3);
$results = $query->find();
if(!empty($results)){
$sentiment_array = $results[0]->sentiment;
$value = 'Parse\ParseObject Object';
foreach ($results as $key => $value) {
}
echo "<div class='products' >What customers want:</div>";
for ($i = 0; $i <= $key; $i++) {
$sentiment = $results[$i] ->sentiment[0];
$sentiment_score = $results[$i]->sentiment_score;
$sentiment_date = $results[$i]->sentiment_date;
$sentiment_data_new = $sentiment_date->format('Y-m-d H:i:s');
$sentiment_data = substr($sentiment_data_new,0, -8);
$platform = $results[$i]->platform;
echo "<table class='table' style='width:75%' >
<tr>
<td><div class='sentiment' style='width:80%'>$sentiment</div></td>
<td style='left: 3%;'><div class='platform_text'> $platform</div></td>
<td style='left: -18.5%;'><div class='sentiment_date'>$sentiment_data</div></td>
<td style='left: -15.5%;'><div class='sentiment_score'>$sentiment_score</div></td>
<tr>
</table>";
echo "<div class='seperation_lines'><hr></div>";
}
} else {
echo "<div class='products'>What customers want:</div>";
echo "<table>
<tr>
<td style='left: 52%; top: -186px;'><div class='sentiment'>No new reviews<br></div></td>
<td style='left: 115%; width: 15%; top: -186px;' ><div class='sentiment_score'>No new data</div>
</td>
<tr>
</table>
<div class='seperation_lines'><hr></div>";
}
$number4 = 4;
$query = new ParseQuery("Sentiment");
$query->ascending("sentiment_date");
$query->equalTo("company_username", $username);
$query->equalTo("product", $company_product);
$query->equalTo("sentiment_type", $number4);
$results = $query->find();
if(!empty($results)){
$sentiment_array = $results[0]->sentiment;
$value = 'Parse\ParseObject Object';
foreach ($results as $key => $value) {
}
echo "<div class='products' >What to improve:</div>";
for ($i = 0; $i <= $key; $i++) {
$sentiment = $results[$i] ->sentiment[0];
$sentiment_score = $results[$i]->sentiment_score;
$sentiment_date = $results[$i]->sentiment_date;
$sentiment_data_new = $sentiment_date->format('Y-m-d H:i:s');
$sentiment_data = substr($sentiment_data_new,0, -8);
$platform = $results[$i]->platform;
echo "<table class='table' style='width:75%' >
<tr>
<td><div class='sentiment' style='width:80%'>$sentiment</div></td>
<td style='left: 3%;'><div class='platform_text'> $platform</div></td>
<td style='left: -18.5%;'><div class='sentiment_date'>$sentiment_data</div></td>
<td style='left: -15.5%;'><div class='sentiment_score'>$sentiment_score</div></td>
<tr>
</table>";
echo "<div class='seperation_lines'><hr></div>";
}
} else {
echo "<div class='products'>What to improve:</div>";
echo "<table>
<tr>
<td style='left: 52%; top: -186px;'><div class='sentiment'>No new reviews<br></div></td>
<td style='left: 115%; width: 15%; top: -186px;' ><div class='sentiment_score'>No new data</div>
</td>
<tr>
</table>
<div class='seperation_lines'><hr></div>";
}
$number5 = 5;
$query = new ParseQuery("Sentiment");
$query->ascending("sentiment_date");
$query->equalTo("company_username", $username);
$query->equalTo("product", $company_product);
$query->equalTo("sentiment_type", $number5);
$results = $query->find();
if(!empty($results)){
$sentiment_array = $results[0]->sentiment;
$value = 'Parse\ParseObject Object';
foreach ($results as $key => $value) {
}
echo "<div class='products'>What customers will buy:</div>";
for ($i = 0; $i <= $key; $i++) {
$sentiment = $results[$i] ->sentiment[0];
$sentiment_score = $results[$i]->sentiment_score;
$sentiment_date = $results[$i]->sentiment_date;
$sentiment_data_new = $sentiment_date->format('Y-m-d H:i:s');
$sentiment_data = substr($sentiment_data_new,0, -8);
$platform = $results[$i]->platform;
echo "<table class='table' style='width:75%' >
<tr>
<td><div class='sentiment' style='width:80%'>$sentiment</div></td>
<td style='left: 3%;'><div class='platform_text'> $platform</div></td>
<td style='left: -18.5%;'><div class='sentiment_date'>$sentiment_data</div></td>
<td style='left: -15.5%;'><div class='sentiment_score'>$sentiment_score</div></td>
<tr>
</table>";
echo "<div class='seperation_lines'><hr></div>";
}
}else {
echo "<div class='products'>What customers will buy:</div>";
echo "<table>
<tr>
<td style='left: 52%; top: -186px;'><div class='sentiment'>No new reviews<br></div></td>
<td style='left: 115%; width: 15%; top: -186px;' ><div class='sentiment_score'>No new data</div>
</td>
<tr>
</table>
<div class='seperation_lines'><hr></div>";
}
//**Youtube comment logic bellow
set_time_limit(0);
echo "<div class='products'>Youtube comments:</div>";
$product_get = $_GET['product'];
$query_link = urlencode($product_get);
$link = "https://zazkov-youtube-grabber-v1.p.mashape.com/search.video.php?maxResults=20&query=$query_link";
$response = Unirest\Request::get($link,
array(
"X-Mashape-Key" => "D1rdRqm6zwmshp8DYyNkQIpAoqaip1AeizYjsn9RMTJPEK16RZ",
"Accept" => "application/json"
)
);
$result_links = $response->body;
$data_array = $result_links->data;
set_time_limit(0);
for($i=0; $i< count($data_array); $i++){
$video = $data_array[$i];
$video_ID = $video->videoId;
$json_data = file_get_contents("https://www.googleapis.com/youtube/v3/commentThreads?part=snippet&maxResults=10&videoId=$video_ID&key=AIzaSyB7eYjYk2c6kbgKpxVZODWoSe1qZUAtSb4");
$data = json_decode($json_data, true);
for ($x=0; $x < 2; $x++) {
if(!empty($data['items'][$x])){
$text = $data['items'][$x]['snippet']['topLevelComment']['snippet']['textDisplay'];
$refined_text_youtube = preg_replace("/[^a-zA-Z0-9\''&:;#]/", " ", $text);
$date = $data['items'][$x]['snippet']['topLevelComment']['snippet']['publishedAt'];
$date_trimmed = substr($date, 0, -14);
echo "<table class='table' style='width:75%' >
<tr>
<td><div class='sentiment' style='width:80%'>$refined_text_youtube</div></td>
<td style='left: 3%;'><div class='platform_text'>Youtube</div></td>
<td style='left: -18.5%;'><div class='sentiment_date'>$date_trimmed</div></td>
<td style='left: -15.5%;'><div class='sentiment_score'>0.00</div></td>
<tr>
</table>";
echo "<div class='seperation_lines'><hr></div>";
/*if(!empty($refined_text)){
$api_key = '1b555c64-da20-449e-8b49-f4ce34e50cbc';
$client = new GuzzleHttp\Client([
// 'base_url' => 'https://api.idolondemand.com',
// 'base_url' => 'https://google.com',
'timeout' => 2.0,
'verify' => false
]);
try {
$response = $client->post('https://api.idolondemand.com/1/api/async/analyzesentiment/v1', [
'multipart' => [
[
'name' => 'apikey',
'contents' => $api_key
],
[
'name' => 'text',
'contents' => $refined_text
]
],
'timeout' => 120
]);
}
catch(GuzzleHttp\Exception\BadResponseException $e){
var_dump($e->getResponse()->getBody()->getContents());
exit();
}
$job_ID = (json_decode($response->getBody()->getContents())->jobID);
$web_to_json = file_get_contents('https://api.idolondemand.com/1/job/status/'.$job_ID.'?apikey=1b555c64-da20-449e-8b49-f4ce34e50cbc');
$array = json_decode($web_to_json, true);
$sentiment_p_text = $array['actions'][0]['result']['positive'];
$sentiment_n_text = $array['actions'][0]['result']['negative'];
print_r($sentiment_p_text);
}
*/
/*
if(!empty($refined_text_youtube)) {
ParseClient::initialize('up89hQ7MHKmtU8ivu1jAV3zldZJkFehKwmUHJkAy', '7LpIiQ6pamLRxtUWr92BMp6hc99oRiTM0VGWkT6i', 'wUH4Fg48MjhAzWGnH2vou3nwihALB4Hd2iZXk0v5');
$youtube_comments_array = array($refined_text_youtube);
$company_name = 'glamglow';
$platform = 'youtube';
$sentimentObject = ParseObject::create("comments");
$sentimentObject->set("company_name",$company_name);
$sentimentObject->set("product",$query);
$sentimentObject->setArray("youtube_comments",$youtube_comments_array);
$sentimentObject->set("platform",$platform);
$sentimentObject->set("set","1");
$sentimentObject->save();
}
*/
}
}
}
echo "<div class='products'>Twitter comments:</div>";
$query = array(
"q" => $product_twitter,
"count" => $twitter_number,
"result_type" => "mixed",
"lang" => "en",
);
$results = search($query);
set_time_limit(0);
for ($i=0; $i <$twitter_number ; $i++) {
$result = $results->statuses[$i]->text;
$date = $results->statuses[$i]->created_at;
$refined_results_twitter = preg_replace("/[^a-zA-Z0-9\''&:;#.,]/", " ", $result);
$trim_date = substr($date, 0, -19);
//echo $trim_date.'<br>';
//echo $refined_results_twitter.' - Twiter<br><br>';
echo "<table class='table' style='width:75%' >
<tr>
<td><div class='sentiment' style='width:80%'>$refined_results_twitter</div></td>
<td style='left: 3%;'><div class='platform_text'>Twitter</div></td>
<td style='left: -18.5%;'><div class='sentiment_date'>$trim_date</div></td>
<td style='left: -15.5%;'><div class='sentiment_score'>0.00</div></td>
<tr>
</table>";
echo "<div class='seperation_lines'><hr></div>";
if(!empty($refined_text_twitter)) {
ParseClient::initialize('up89hQ7MHKmtU8ivu1jAV3zldZJkFehKwmUHJkAy', '7LpIiQ6pamLRxtUWr92BMp6hc99oRiTM0VGWkT6i', 'wUH4Fg48MjhAzWGnH2vou3nwihALB4Hd2iZXk0v5');
$twitter_comments_array = array($refined_text_twitter);
$company_name = 'glamglow';
$platform = 'twitter';
$sentimentObject = ParseObject::create("comments");
$sentimentObject->set("company_name",$company_name);
$sentimentObject->set("product",$query);
$sentimentObject->setArray("youtube_comments",$twitter_comments_array);
$sentimentObject->set("platform",$platform);
$sentimentObject->set("set","1");
$sentimentObject->save();
}
}
} else {
header('location: http://sentview.com/login');
}
} /*catch (ParseException $error){
header('location: login.php');
exit();*/
} catch (ParseException $error) {
header('location: http://sentview.com/login');
exit();
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment