function getTweets($num) { $num = mysql_real_escape_string($num); $res = mysql_query("SELECT `tweet`, `direct` FROM `Tweets` ORDER BY `date` DESC LIMIT 0 , {$num}") or die(mysql_error()); $ret = array(); require_once 'includes/cleantweet.php'; while ($row = mysql_fetch_array($res)) { if (isset($row['direct'])) { $ret[] = array(cleanTweet($row['tweet']), cleantweet($row['direct'])); } else { $ret[] = cleanTweet($row['tweet']); } } return $ret; }
function get_my_mentions($connection) { global $cron_every_x_minutes; $tArr = array(); $tweets_to_me = $connection->get('statuses/mentions_timeline', array('count' => 1)); foreach ($tweets_to_me as $i => $tweet) { if (strtotime($tweet->created_at) > strtotime("-{$cron_every_x_minutes} minutes")) { $tArr[$i]['created'] = $tweet->created_at; $tArr[$i]['tweetidstr'] = $tweet->id_str; $tArr[$i]['tweet'] = cleanTweet($tweet->text); $tArr[$i]['userid'] = $tweet->user->id; $tArr[$i]['useridstr'] = $tweet->user->id_str; $tArr[$i]['userscreenname'] = $tweet->user->screen_name; } } return $tArr; }
/** * Parses JSON object for tweets, gets sentiment object & writes to file with date * @param array of JSON data, number of tweets to analyze */ function parseData($arr, $num) { global $path; $count = 0; $flag = file_exists($path); $res = array(); //for debug $ind = 0; foreach ($arr as $tweet) { if ($flag == true) { $flag = false; continue; } $date = getTweetDate($tweet); $id = getTweetID($tweet); $str = getTweetText($tweet); $str = cleanTweet($str); if (strlen($str) < 5) { continue; } //using alchamy $sentiment = getTweetSentiment($str); $result = array(); $result[0] = $id; $result[1] = $date; $result[2] = $str; $result[3] = $sentiment->type; $result[4] = $sentiment->score; $resultString = getCacheString($result); writeInfo($result); writeData($resultString); $res[$ind++] = $resultString; if ($count > $num) { break; } $count++; } return $res; }