-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNewsInt.php
29 lines (29 loc) · 909 Bytes
/
NewsInt.php
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
<?php
function getNewsScore($query) {
include 'AlchInt.php';
include_once('lib.php');
$query = urlencode($query);
$searchResults = json_decode(file_get_contents("https://ajax.googleapis.com/ajax/services/search/news?v=1.0&q=$query"), true);
if($searchResults != null && array_key_exists("responseData", $searchResults)) {
$searchResults = $searchResults["responseData"];
if($searchResults != null && array_key_exists("results", $searchResults)) {
$searchResults = $searchResults["results"];
}
else {
return 2;
}
}
else {
return 2;
}
$sentiments = array();
foreach($searchResults as $result) {
try {
array_push($sentiments, json_decode($AlchemyObj->URLGetTextSentiment($result["unescapedUrl"], AlchemyAPI::JSON_OUTPUT_MODE), true)['docSentiment']['score']);
}
catch(Exception $e) {
}
}
return scoreCalc($sentiments);
}
?>