Пример #1
0
/**
* This is the method that inserts 200 recent Twitter response objects with their Twitter handles in 
* the DB (Table: Tweets). 
*/
function insertTweetInDB()
{
    //$users = array("result" => ["@katyperry"]);
    $users = getAllTwitterUsers();
    $twitterApiCallCount = 0;
    foreach ($users['result'] as $user) {
        if ($twitterApiCallCount % 180 == 0 && $twitterApiCallCount != 0) {
            // Sleep for 15mins and 30 seconds
            break;
        }
        // strip the initial character '@' and get 200 Twitter Responses for that screen-name.
        $twitterResp = getTweet(substr($user, 1), 200);
        $twitterApiCallCount += 1;
        $count = 1;
        mysqli_query(getConnection(), "START TRANSACTION;");
        foreach ($twitterResp as $response) {
            $response["source"] = str_replace('"', '\\"', $response["source"]);
            $response["text"] = str_replace('"', '\\"', $response["text"]);
            $object = json_encode($response);
            // Escaping all the ' character from the Tweet Data
            $object = str_replace("'", "\\'", $object);
            $query = "REPLACE INTO Tweets(Number, TwitterHandle, TwitterResp) VALUES('" . (string) $count . "', '" . $user . "', '" . $object . "');";
            $count += 1;
            $res = mysqli_query(getConnection(), $query);
            if (false === $res) {
                logWarning('tweetylogs.txt', "Insertion for Tweet #" . $count . " for Twitter User " . $user . " failed. Insertion error: " . mysqli_error($link));
                logWarning('warning.txt', "Insertion for Tweet #" . $count . " for Twitter User " . $user . " failed. Insertion error: " . mysqli_error($link));
                logWarning('tweetylogs.html', "Insertion for <b>Tweet #" . $count . "</b> for <b>Twitter User " . $user . "</b> failed. Insertion error: " . mysqli_error($link));
            }
        }
        if ($count >= 200) {
            logSuccess('tweetylogs.txt', "Insertion for 200 Tweets for Twitter User " . $user . " succeded.");
            logSuccess('warning.txt', "Insertion for 200 Tweets for Twitter User " . $user . " succeded.");
            logSuccess('tweetylogs.html', "Insertion for 200 Tweets for <b>Twitter User " . $user . "</b> succeded.");
        }
        mysqli_query(getConnection(), "COMMIT;");
    }
}
Пример #2
0
// min, max, mean of what?? ditributions of nr of nodes in the network
foreach ($links as $link) {
    $tweet_id = $link[0];
    $in_reply_to_status_id = $link[1];
    if (array_search($in_reply_to_status_id, $todo) === false && array_search($tweet_id, $todo) === false) {
        continue;
    }
    $node1 = new GexfNode($in_reply_to_status_id);
    // if node already exists, we want the attributes added that node instead
    $id = $gexf->nodeExists($node1);
    if ($id !== false && isset($gexf->nodeObjects[$id])) {
        $node1 = $gexf->nodeObjects[$id];
    }
    $node1->addNodeAttribute('tweet_id', $in_reply_to_status_id, 'string');
    if (!isset($tweets[$in_reply_to_status_id])) {
        $tweet = getTweet($in_reply_to_status_id);
        if ($tweet !== false) {
            $node1->addNodeAttribute('created_at', $tweet['created_at'], 'string');
            $node1->addNodeAttribute('tweet', $tweet['text'], 'string');
            $node1->addNodeAttribute('user', $tweet['from_user_name'], 'string');
            $node1->addNodeAttribute('from_user_lang', $tweet['from_user_lang'], 'string');
            $node1->addNodeAttribute('from_user_tweetcount', $tweet['from_user_tweetcount'], 'integer');
            $node1->addNodeAttribute('from_user_followercount', $tweet['from_user_followercount'], 'integer');
            $node1->addNodeAttribute('from_user_friendcount', $tweet['from_user_friendcount'], 'integer');
            $node1->addNodeAttribute('from_user_listed', $tweet['from_user_listed'], 'integer');
            $node1->addNodeAttribute('geo_lng', $tweet['geo_lng'], 'integer');
            $node1->addNodeAttribute('geo_lat', $tweet['geo_lat'], 'integer');
            $node1->addNodeAttribute('source', $tweet['source'], 'string');
        }
    } else {
        $node1->addNodeAttribute('created_at', $tweets[$in_reply_to_status_id]['created_at'], 'string');