Example #1
0
<?php

/*
 * use the API "users/hot" to get users' informations from SINA and put
 * them into local DB. if there are any repeatedly informations with
 * the same uid, which is in local DB and from "users/hot", then refresh
 * the ones in local DB.   
 */
include_once 'config.php';
include_once 'weibooauth.php';
include_once dirname(__FILE__) . '/../zmysqlConn.class.php';
include_once "expkits.inc.php";
$o = new WeiboOAuth(WB_AKEY, WB_SKEY, LAST_OAUTH_TOKEN, LAST_OAUTH_TOKEN_SECRET);
$zconn = new zmysqlConn();
$hots = $o->get("http://api.t.sina.com.cn/users/hot.json", array('source' => WB_AKEY));
$sex = array('f', 'm');
if ($argc == 2) {
    if (in_array($argv[1] . '', $sex)) {
        $sex = array($argv[1]);
    }
}
$i = 0;
foreach ($hots as $hot) {
    if (in_array('' . $hot['gender'], $sex) && intval($hot['id']) >= 0) {
        $sql = __get_user_insert_update_sql($hot);
        mysql_query("set names 'utf8';");
        mysql_query($sql, $zconn->dblink) or die("~failed~~db_err:" . mysql_error() . "~~failed~");
        $i += mysql_affected_rows();
    }
}
echo "Total: " . count($hots) . " / Affected: " . $i . ". (" . date("Y-m-d H:i:s") . ")\n";
Example #2
0
<?php

/*
 * use the API "users/show" to get user's information from SINA and put
 * them into local DB. if there are any repeatedly informations with
 * the same uid, just overwrite it.   
 */
include_once 'config.php';
include_once 'weibooauth.php';
include_once dirname(__FILE__) . '/../zmysqlConn.class.php';
include_once "expkits.inc.php";
$c = new WeiboClient(WB_AKEY, WB_SKEY, LAST_OAUTH_TOKEN, LAST_OAUTH_TOKEN_SECRET);
$zconn = new zmysqlConn();
if ($argc != 2) {
    exit("it should take 1 parameter as 'uid'.\n");
}
$uid = $argv[1];
$user = $c->show_user($uid);
//var_dump($user);
if (array_key_exists("error", $user)) {
    echo $user['error'] . "#{$uid}#\n" . print_r($user, true);
} else {
    $sql = __get_user_insert_update_sql($user);
    mysql_query("set names 'utf8';");
    mysql_query($sql, $zconn->dblink) or die("~failed~~db_err:" . mysql_error() . "~~failed~\n");
    echo mysql_affected_rows() . " row affected.\n";
}
Example #3
0
$i = $j = $f = 0;
if ($friends != null && !array_key_exists("error", $friends)) {
    foreach ($friends as $friend) {
        /*
         * we only gather the female ones and their followers 
         * must not be over 100000.
         */
        if ($friend['gender'] == 'f' && $friend['followers_count'] < 100000) {
            //echo ++$i //for debug
            //	. " | " . $friend["id"] //for debug
            //	. " | " . $friend["screen_name"] //for debug
            //	. " | " . $friend["gender"] //for debug
            //	. " | " . $friend["followers_count"]; //for debug
            //echo "\n"; //for debug
            ++$i;
            $sql = __get_user_insert_update_sql($friend);
            mysql_query("set names 'utf8';");
            mysql_query($sql, $zconn->dblink);
            $f += mysql_affected_rows() == -1 ? 1 : 0;
            $j += mysql_affected_rows() == -1 ? 0 : mysql_affected_rows();
        }
    }
}
/*
 * get the totals after insert / update.
 */
$sql = "select count(id) from weibo_users";
$rs = mysql_query($sql, $zconn->dblink);
$r = mysql_fetch_row($rs);
$aftertotals = $r[0];
$adds = $aftertotals - $foretotals;