* Created by Stefan Compton * Date: 10/11/2015 * Time: 08:22 * * * */ require_once './TwitterSentimentAnalysis.php'; $number_of_tweet_results = 100; $tags = array('afcb', 'arsenal', 'avfc', 'cfc', 'coys', 'cpfc', 'efc', 'lcfc', 'lfc', 'mcfc', 'mufc', 'ncfc', 'nufc', 'saintsfc', 'scfc', 'safc', 'swans', 'watfordfc', 'wba', 'whufc'); $DBConnect = @mysqli_connect('dxhost.net', 'football_user', '*8eC@0LpH^Nt') or die("Unable to connect to the database server. " . "Error code " . mysqli_connect_errno() . ": " . mysqli_connect_error()); @mysqli_select_db($DBConnect, "football_db") or die("Unable to select the database." . "Error code " . mysqli_errno($DBConnect) . ": " . mysqli_error($DBConnect)); echo "Successfully opened the database."; echo date("Y/m/d h:i:sa"); //$tags = array("mufc", "watfordfc"); $tp = new TwitterSentimentAnalysis(); foreach ($tags as $tag) { $res = $tp->sentimentAnalysis(array("q" => "%23" . $tag, "count" => $number_of_tweet_results)); $count = 0; $possent = 0; $negsent = 0; foreach ($res as $i) { if ($i == "pos") { $possent++; } else { if ($i == "neg") { $negsent--; } } $count++; }
<meta http-equiv="Lang" content="en"> <title>Datumbox Twitter Sentiment Analysis Demo</title> </head> <body> <h1>Datumbox Twitter Sentiment Analysis</h1> <p>Type your keyword below to perform Sentiment Analysis on Twitter Results:</p> <form method="GET"> <label>Keyword: </label> <input type="text" name="q" /> <input type="submit" /> </form> <?php if (isset($_GET['q']) && $_GET['q'] != '') { include_once dirname(__FILE__) . '/config.php'; include_once dirname(__FILE__) . '/lib/TwitterSentimentAnalysis.php'; $TwitterSentimentAnalysis = new TwitterSentimentAnalysis(DATUMBOX_API_KEY, TWITTER_CONSUMER_KEY, TWITTER_CONSUMER_SECRET, TWITTER_ACCESS_KEY, TWITTER_ACCESS_SECRET); //Search Tweets parameters as described at https://dev.twitter.com/docs/api/1.1/get/search/tweets $twitterSearchParams = array('q' => $_GET['q'], 'lang' => 'en', 'count' => 10); $results = $TwitterSentimentAnalysis->sentimentAnalysis($twitterSearchParams); ?> <h1>Results for "<?php echo $_GET['q']; ?> "</h1> <table border="1"> <tr> <td>Id</td> <td>User</td> <td>Text</td> <td>Twitter Link</td> <td>Sentiment</td>
<?php // The search terms are passed in the q parameter // search_server.php?q=[search terms] if (!empty($_GET['q'])) { // Remove any hack attempts from input data $search_terms = htmlspecialchars($_GET['q']); // Get the application OAuth tokens require 'app_tokens.php'; //get the datumbox api key require 'config.php'; require 'lib/TwitterSentimentAnalysis.php'; $TwitterSentimentAnalysis = new TwitterSentimentAnalysis(DATUMBOX_API_KEY, TWITTER_CONSUMER_KEY, TWITTER_CONSUMER_SECRET, TWITTER_ACCESS_KEY, TWITTER_ACCESS_SECRET); // Create an OAuth connection require 'tmhOAuth.php'; $connection = new tmhOAuth(array('consumer_key' => $consumer_key, 'consumer_secret' => $consumer_secret, 'user_token' => $user_token, 'user_secret' => $user_secret)); // Request the most recent 100 matching tweets $http_code = $connection->request('GET', $connection->url('1.1/search/tweets'), $twitterSearchParams = array('q' => $search_terms, 'count' => 25, 'lang' => 'en', 'type' => 'recent')); // Search was successful if ($http_code == 200) { // Extract the tweets from the API response $response = json_decode($connection->response['response'], true); $tweet_data = $response['statuses']; //Response to be sent to Sentiment API $response = $TwitterSentimentAnalysis->sentimentAnalysis($twitterSearchParams); //Sending the Twitter API response(JSONP) direct to a local file $file = 'data.json'; file_put_contents('data.json', json_encode($response)); // Load the template for tweet display $tweet_template = file_get_contents('tweet_template.html'); // Load the library of tweet display functions