Skip to content

Commit 6b5a0ce

Browse files
committed
final.
1 parent 3534e8c commit 6b5a0ce

File tree

10 files changed

+158
-14
lines changed

10 files changed

+158
-14
lines changed

config/settings.php

+14-8
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,25 @@
11
<?
22
$articleSources = array("toi"=>array("base"=>"http://articles.timesofindia.indiatimes.com/",
3-
"search"=>"http://articles.timesofindia.indiatimes.com/keyword/"),
4-
"ie"=>array("base"=>"",
5-
"search"=>"http://www.indianexpress.com/topic/")
6-
);
3+
"search"=>"http://articles.timesofindia.indiatimes.com/keyword/"),
4+
"ie"=>array("base"=>"",
5+
"search"=>"http://www.indianexpress.com/topic/")
6+
);
77

8-
$apiKey = "AIzaSyBmbBwn6BqrVeXqDG-cbKMQk5RQWvbc0bc";
8+
$apiKey = "AIzaSyC-CRDiAPdXEBHgvM2YF-x6manmYk9H6D4";
99
$ieSearchID = "010961665768017960356:_zeideyipb8";
1010
$toiSearchID = "010961665768017960356:tyb6vy7xp5e";
1111
$hinduSearchID = "010961665768017960356:trzulzp-s_4";
1212

1313
$customSearchUrl = "https://www.googleapis.com/customsearch/v1?key=$apiKey";
1414

15-
// $repustateAPIKey = "d96df10c7b6a0d5846f7c33c427085f7558bf003";
16-
// $repustateAPIKey = "68306bc8217d78bad1520ba2c19082086d2781d2";
17-
$repustateAPIKey = "fb97aa74bceeab0bc25f3770247af8f71576a264";
15+
$repustateAPIKey = "d96df10c7b6a0d5846f7c33c427085f7558bf003";
1816
$repustateEndPoint = "http://api.repustate.com/v2/$repustateAPIKey/bulk-score.json";
17+
18+
$alchemyEndPoint = "http://access.alchemyapi.com/calls/url/URLGetTextSentiment";
19+
$alchemy_api_key ="4033ce5c39cdb94b7ab3361b5b9329cb33437ea7";
20+
$cs_api_key = "AIzaSyB9a8zvr8sGVpYPLz6wczFxxJBMWgW2DAg";
21+
$searchEngineID="002983451055951785828:gvpl63cui1i";
22+
$csURL = "https://www.googleapis.com/customsearch/v1?key=$cs_api_key&cx=$searchEngineID";
23+
24+
1925
?>

dump.json

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
["{\"status\": \"OK\", \"results\": [{\"score\": 1.0, \"id\": \"65\"}, {\"score\": 0.24097, \"id\": \"29\"}, {\"score\": -0.06196, \"id\": \"67\"}, {\"score\": -0.02731, \"id\": \"66\"}, {\"score\": 0.2754, \"id\": \"61\"}, {\"score\": -0.00027, \"id\": \"60\"}, {\"score\": -0.2354, \"id\": \"63\"}, {\"score\": -0.2215, \"id\": \"62\"}, {\"score\": 0.23237, \"id\": \"69\"}, {\"score\": 0.23606, \"id\": \"68\"}, {\"score\": 0.0, \"id\": \"50\"}, {\"score\": -0.13988, \"id\": \"51\"}, {\"score\": -0.11132, \"id\": \"52\"}, {\"score\": 0.0, \"id\": \"53\"}, {\"score\": -0.06446, \"id\": \"54\"}, {\"score\": 0.67227, \"id\": \"55\"}, {\"score\": 0.59757, \"id\": \"56\"}, {\"score\": 1.0, \"id\": \"57\"}, {\"score\": 0.5365, \"id\": \"58\"}, {\"score\": 0.22244, \"id\": \"59\"}, {\"score\": 0.64972, \"id\": \"19\"}, {\"score\": -0.00098, \"id\": \"64\"}, {\"score\": -0.36838, \"id\": \"49\"}, {\"score\": -0.01475, \"id\": \"48\"}, {\"score\": -0.2215, \"id\": \"47\"}, {\"score\": 0.51637, \"id\": \"46\"}, {\"score\": 0.88309, \"id\": \"45\"}, {\"score\": 0.66058, \"id\": \"44\"}, {\"score\": 1.0, \"id\": \"43\"}, {\"score\": 0.67579, \"id\": \"42\"}, {\"score\": -0.13036, \"id\": \"41\"}, {\"score\": 0.53932, \"id\": \"40\"}, {\"score\": 0.3595, \"id\": \"75\"}, {\"score\": -0.21414, \"id\": \"38\"}, {\"score\": -0.38121, \"id\": \"39\"}, {\"score\": 0.0, \"id\": \"32\"}, {\"score\": 0.0, \"id\": \"33\"}, {\"score\": 0.89676, \"id\": \"30\"}, {\"score\": 1.0, \"id\": \"31\"}, {\"score\": -0.2754, \"id\": \"36\"}, {\"score\": 0.02042, \"id\": \"37\"}, {\"score\": -0.11584, \"id\": \"34\"}, {\"score\": 0.98862, \"id\": \"35\"}, {\"score\": 0.0, \"id\": \"28\"}, {\"score\": 0.6334, \"id\": \"21\"}, {\"score\": -0.56161, \"id\": \"20\"}, {\"score\": 0.30565, \"id\": \"23\"}, {\"score\": 0.0, \"id\": \"22\"}, {\"score\": -0.25819, \"id\": \"25\"}, {\"score\": 0.23237, \"id\": \"24\"}, {\"score\": 0.2187, \"id\": \"27\"}, {\"score\": 0.3595, \"id\": \"26\"}, {\"score\": 0.4967, \"id\": \"124\"}, {\"score\": 0.0, \"id\": \"123\"}, {\"score\": 0.0, \"id\": \"122\"}, {\"score\": 1.0, \"id\": \"121\"}, {\"score\": 0.24097, \"id\": \"120\"}, {\"score\": -0.22376, \"id\": \"2\"}, {\"score\": 0.21594, \"id\": \"3\"}, {\"score\": 0.0, \"id\": \"1\"}, {\"score\": 0.67611, \"id\": \"6\"}, {\"score\": 0.36521, \"id\": \"7\"}, {\"score\": 0.22533, \"id\": \"4\"}, {\"score\": 0.24786, \"id\": \"5\"}, {\"score\": -0.23458, \"id\": \"8\"}, {\"score\": 0.4103, \"id\": \"9\"}, {\"score\": 1.0, \"id\": \"118\"}, {\"score\": 0.24097, \"id\": \"116\"}, {\"score\": 0.37091, \"id\": \"117\"}, {\"score\": 0.42364, \"id\": \"114\"}, {\"score\": 0.2154, \"id\": \"115\"}, {\"score\": 0.0, \"id\": \"112\"}, {\"score\": -0.21372, \"id\": \"113\"}, {\"score\": -0.51512, \"id\": \"110\"}, {\"score\": 1.0, \"id\": \"111\"}, {\"score\": 0.0, \"id\": \"101\"}, {\"score\": 0.60332, \"id\": \"100\"}, {\"score\": -0.15835, \"id\": \"103\"}, {\"score\": -0.19494, \"id\": \"102\"}, {\"score\": 0.36865, \"id\": \"98\"}, {\"score\": 0.22376, \"id\": \"99\"}, {\"score\": -0.53014, \"id\": \"107\"}, {\"score\": 0.35555, \"id\": \"106\"}, {\"score\": -0.24786, \"id\": \"94\"}, {\"score\": -0.52326, \"id\": \"95\"}, {\"score\": -0.36387, \"id\": \"96\"}, {\"score\": -0.52326, \"id\": \"97\"}, {\"score\": 0.03591, \"id\": \"90\"}, {\"score\": 0.38809, \"id\": \"91\"}, {\"score\": 0.0, \"id\": \"92\"}, {\"score\": 1.0, \"id\": \"93\"}, {\"score\": 0.22032, \"id\": \"14\"}, {\"score\": 0.26392, \"id\": \"15\"}, {\"score\": 0.25819, \"id\": \"16\"}, {\"score\": 0.53136, \"id\": \"17\"}, {\"score\": 0.51353, \"id\": \"10\"}, {\"score\": 0.0, \"id\": \"11\"}, {\"score\": -0.2032, \"id\": \"12\"}, {\"score\": 0.83955, \"id\": \"13\"}, {\"score\": -0.22032, \"id\": \"18\"}, {\"score\": -0.36521, \"id\": \"76\"}, {\"score\": 0.26945, \"id\": \"77\"}, {\"score\": -0.43687, \"id\": \"74\"}, {\"score\": -0.35835, \"id\": \"72\"}, {\"score\": -0.42473, \"id\": \"73\"}, {\"score\": -0.24919, \"id\": \"70\"}, {\"score\": -0.69493, \"id\": \"71\"}, {\"score\": 0.2952, \"id\": \"78\"}, {\"score\": -0.16295, \"id\": \"79\"}, {\"score\": -0.22533, \"id\": \"105\"}, {\"score\": -0.59517, \"id\": \"104\"}, {\"score\": -1.0, \"id\": \"89\"}, {\"score\": -0.0166, \"id\": \"88\"}, {\"score\": 0.2754, \"id\": \"119\"}, {\"score\": 0.00066, \"id\": \"83\"}, {\"score\": 0.00354, \"id\": \"82\"}, {\"score\": 0.22981, \"id\": \"81\"}, {\"score\": 0.01291, \"id\": \"80\"}, {\"score\": 0.04886, \"id\": \"87\"}, {\"score\": -0.24097, \"id\": \"86\"}, {\"score\": -0.14496, \"id\": \"85\"}, {\"score\": -0.23606, \"id\": \"84\"}, {\"score\": 0.21688, \"id\": \"109\"}, {\"score\": 0.0, \"id\": \"108\"}]}","{\"status\": \"OK\", \"results\": []}","{\"status\": \"OK\", \"results\": [{\"score\": 0.23606, \"id\": \"65\"}, {\"score\": -0.21256, \"id\": \"64\"}, {\"score\": 0.03165, \"id\": \"67\"}, {\"score\": -0.07746, \"id\": \"66\"}, {\"score\": -0.2272, \"id\": \"61\"}, {\"score\": 0.927, \"id\": \"60\"}, {\"score\": 0.0, \"id\": \"63\"}, {\"score\": 0.2995, \"id\": \"62\"}, {\"score\": 0.45474, \"id\": \"69\"}, {\"score\": 0.36872, \"id\": \"68\"}, {\"score\": 0.53359, \"id\": \"50\"}, {\"score\": 0.22376, \"id\": \"51\"}, {\"score\": 0.39378, \"id\": \"52\"}, {\"score\": 0.57419, \"id\": \"53\"}, {\"score\": 0.52715, \"id\": \"54\"}, {\"score\": -0.26163, \"id\": \"55\"}, {\"score\": 0.22533, \"id\": \"56\"}, {\"score\": 0.39228, \"id\": \"57\"}, {\"score\": 0.50049, \"id\": \"58\"}, {\"score\": 0.39944, \"id\": \"59\"}, {\"score\": 0.23793, \"id\": \"49\"}, {\"score\": -0.30982, \"id\": \"48\"}, {\"score\": 0.81648, \"id\": \"47\"}, {\"score\": 0.19344, \"id\": \"46\"}, {\"score\": 0.0, \"id\": \"45\"}, {\"score\": 0.48539, \"id\": \"44\"}, {\"score\": 1.0, \"id\": \"43\"}, {\"score\": 0.44727, \"id\": \"42\"}, {\"score\": -0.01495, \"id\": \"41\"}, {\"score\": -0.02544, \"id\": \"40\"}, {\"score\": -0.2295, \"id\": \"38\"}, {\"score\": -0.07377, \"id\": \"39\"}, {\"score\": 1.0, \"id\": \"32\"}, {\"score\": 0.0, \"id\": \"33\"}, {\"score\": 0.07198, \"id\": \"30\"}, {\"score\": 0.5287, \"id\": \"31\"}, {\"score\": -0.2213, \"id\": \"36\"}, {\"score\": 0.0, \"id\": \"37\"}, {\"score\": -0.76964, \"id\": \"34\"}, {\"score\": 0.54553, \"id\": \"35\"}, {\"score\": 0.24919, \"id\": \"29\"}, {\"score\": -0.05164, \"id\": \"28\"}, {\"score\": 0.28681, \"id\": \"21\"}, {\"score\": 0.1442, \"id\": \"20\"}, {\"score\": -0.21946, \"id\": \"23\"}, {\"score\": -1.0, \"id\": \"22\"}, {\"score\": 0.36872, \"id\": \"25\"}, {\"score\": -0.50359, \"id\": \"24\"}, {\"score\": 0.48392, \"id\": \"27\"}, {\"score\": -0.24097, \"id\": \"26\"}, {\"score\": -0.40522, \"id\": \"2\"}, {\"score\": -1.0, \"id\": \"3\"}, {\"score\": 0.25253, \"id\": \"1\"}, {\"score\": -0.55549, \"id\": \"6\"}, {\"score\": -0.30982, \"id\": \"7\"}, {\"score\": 1.0, \"id\": \"4\"}, {\"score\": 0.21098, \"id\": \"5\"}, {\"score\": -0.2187, \"id\": \"8\"}, {\"score\": -0.35622, \"id\": \"9\"}, {\"score\": -1.0, \"id\": \"14\"}, {\"score\": -0.2643, \"id\": \"15\"}, {\"score\": 0.5277, \"id\": \"16\"}, {\"score\": 0.22032, \"id\": \"17\"}, {\"score\": 0.87085, \"id\": \"10\"}, {\"score\": 0.24786, \"id\": \"11\"}, {\"score\": 0.51159, \"id\": \"12\"}, {\"score\": -1.0, \"id\": \"13\"}, {\"score\": -0.24097, \"id\": \"18\"}, {\"score\": -0.02802, \"id\": \"19\"}, {\"score\": 0.50605, \"id\": \"76\"}, {\"score\": 0.18709, \"id\": \"77\"}, {\"score\": -0.39129, \"id\": \"74\"}, {\"score\": -0.76463, \"id\": \"75\"}, {\"score\": 0.5563, \"id\": \"72\"}, {\"score\": 0.2754, \"id\": \"73\"}, {\"score\": -0.64171, \"id\": \"70\"}, {\"score\": 0.2754, \"id\": \"71\"}, {\"score\": -0.71377, \"id\": \"78\"}, {\"score\": 0.72848, \"id\": \"79\"}, {\"score\": 1.0, \"id\": \"88\"}, {\"score\": 0.15626, \"id\": \"83\"}, {\"score\": 0.57342, \"id\": \"82\"}, {\"score\": 0.30982, \"id\": \"81\"}, {\"score\": 1.0, \"id\": \"80\"}, {\"score\": 0.25819, \"id\": \"87\"}, {\"score\": 0.20498, \"id\": \"86\"}, {\"score\": -0.23606, \"id\": \"85\"}, {\"score\": 0.0, \"id\": \"84\"}]}","{\"status\": \"OK\", \"results\": [{\"score\": 0.84063, \"id\": \"2\"}, {\"score\": 0.22533, \"id\": \"3\"}, {\"score\": 0.68575, \"id\": \"1\"}, {\"score\": -0.61038, \"id\": \"6\"}, {\"score\": 0.20959, \"id\": \"4\"}, {\"score\": 0.1319, \"id\": \"5\"}]}","{\"status\": \"OK\", \"results\": []}","{\"status\": \"OK\", \"results\": []}"]

handlers/getpop.php

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
require_once 'config/settings.php';
4+
class getpop
5+
{
6+
7+
8+
function pop_score($url)
9+
{
10+
//Name of politician
11+
list($type, $score, $mixed) = $this->sentiment($url);
12+
return $score;
13+
14+
15+
}
16+
17+
function sentiment($urlparam)
18+
{
19+
global $alchemyEndPoint, $alchemy_api_key;
20+
$response=file_get_contents($alchemyEndPoint."?apikey={$alchemy_api_key}&url={$urlparam}&outputMode=json");
21+
$response=json_decode($response,true);
22+
$type = $response["docSentiment"]["type"];
23+
$score = $response["docSentiment"]["score"];
24+
$mixed = $response["docSentiment"]["mixed"];
25+
return array($type, $score, $mixed);
26+
27+
}
28+
29+
}
30+

index.php

+37-4
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,50 @@
11
<?php
2-
ini_set('display_errors',1);
3-
error_reporting(E_ALL);
2+
// ini_set('display_errors',1);
3+
// error_reporting(E_ALL);
44
define("ROOT", __DIR__);
55
//require(ROOT."/config.php");
66
require(ROOT."/Toro.php");
77
//require(ROOT."/lib/db.php");
88
require(ROOT."/handlers/home.php"); //function requires all the files stored in ROOT."/handlers/"
9+
require(ROOT."/handlers/getpop.php");
10+
//require(ROOT."/handlers/search.php");
11+
require 'config/settings.php';
912

1013
ToroHook::add("404", function() {
1114
echo "Not found";
1215
});
16+
17+
class searchHandler{
18+
function get($name=NULL) {
19+
if($name){
20+
$pop = new getpop();
21+
22+
global $csURL;
23+
$response=file_get_contents($csURL."&q={$name}");
24+
$response=json_decode($response,true);
25+
$searchResults = $response["items"];
26+
$i = 0;
27+
foreach($searchResults as $item)
28+
{ if($i>2)
29+
break;
30+
31+
$url = $item["link"];
32+
$score[$i] = $pop->pop_score($url);
33+
//echo $score[$i];
34+
$i = $i + 1;
35+
}
36+
echo array_sum($score)/3;
37+
}
38+
else{
39+
include "views/csearch.php";
40+
}
41+
;
42+
}
43+
}
1344

1445
Toro::serve(array(
15-
"/" => "HomeHandler"
46+
"/" => "HomeHandler",
47+
"/csearch" => "searchHandler",
48+
"/csearch/([a-zA-Z0-9-_]+)" => "searchHandler"
1649
));
17-
?>
50+
?>

public/css/style.css

+4
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,8 @@ body{
66
background-color: black;
77
padding-left:80px;
88
padding-right:80px;
9+
}
10+
.masthead{
11+
background-image:url('/public/images/Coffee-Table-1024x682.jpg');
12+
background-size:cover;
913
}
73 KB
Loading

public/js/script.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ $(document).ready(function(){
2323
else if(score > 4)
2424
rating = "Mixed";
2525
else
26-
rating = "Negative";
26+
rating = "Relatively Poor";
2727
$("div.result").append('<span><h1>'+rating+':'+score+'</h1></span>');
2828
$("#ajax-loader").remove();
2929
}

public/js/script2.js

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
$(document).ready(function(){
2+
3+
$('#sub2').click(function(){
4+
event.preventDefault();
5+
var keystring = $('#keystring2').val();
6+
var data = {
7+
keystring:keystring
8+
}
9+
$.ajax({
10+
type:'get',
11+
url:"csearch/"+keystring,
12+
data:data,
13+
complete:function(msg){
14+
console.log(msg.responseText);
15+
var score = msg.responseText;
16+
score = score*50 +5;
17+
score = (Math.round(parseFloat(score)*10))/10;
18+
19+
rating = '';
20+
if(score > 8)
21+
rating = "Extremely positive";
22+
else if(score > 6)
23+
rating = "Fairly positive";
24+
else if(score > 4)
25+
rating = "Mixed";
26+
else
27+
rating = "Relatively Poor";
28+
$("div.result").append('<span><h1>'+rating+':'+score+'</h1></span>');
29+
$("#ajax-loader").remove();
30+
}
31+
})
32+
$('form').append('<div id="ajax-loader"><br/><br/><img src="public/images/ajax-loader.gif"/></div>');
33+
$('#results').empty()
34+
$('#results').append('<div class="result row"><div class="span4"></div></div>');
35+
// var imgSrc = $("#source").val();
36+
// $('#results').append('<div class="result row"><img style="height:120px" src="public/images/'+imgSrc+'.jpg"></div>');
37+
});
38+
39+
});

scraping/iescraper.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ public function getArticleContent($url)
2727
if(!$url)
2828
return false;
2929
$html = file_get_html($url);
30-
$result["title"] = $html->find('div#ie2013-content h1', 0)->innertext;
30+
if($res = $html->find('div#ie2013-content h1', 0))
31+
$result["title"] = $res->innertext;
3132
$result["content"] = "";
3233
foreach ($html->find('div.ie2013-contentstory p') as $key => $value)
3334
{

views/csearch.php

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<html>
2+
<head>
3+
<title>
4+
Syntax Error
5+
</title>
6+
<link href="public/css/bootstrap.css" rel="stylesheet" media="screen">
7+
<link href="public/css/bootswatch.css" rel="stylesheet" media="screen">
8+
<link href="public/css/docs.css" rel="stylesheet" media="screen">
9+
<link href="public/css/style.css" rel="stylesheet" media="screen">
10+
<script src="public/js/jquery.min.js"></script>
11+
<script src="public/js/script2.js"></script>
12+
</head>
13+
<body>
14+
<header class="jumbotron masthead">
15+
<div class="container">
16+
<div class="row">
17+
<div class="span12" style="margin:auto auto">
18+
<form >
19+
<h1 style="font-size:60px;color:#0088cc">I'd like to know current news opinion about
20+
<input name="keystring" id = "keystring2" style="height:35px" type="text"/> </h1>
21+
<button type="submit" id="sub2" class="btn">Submit</button>
22+
</form>
23+
</div>
24+
</div>
25+
</div>
26+
</header>
27+
<div id="results" style="text-align:center">
28+
</div>
29+
</body>
30+
</html>

0 commit comments

Comments
 (0)