Browse Source

查看抓取结果

pull/50/head
pengda 6 days ago
parent
commit
cdf7b4dab6
  1. 9
      control/weibo.php
  2. 25
      model/mWeiboBehavior.php

9
control/weibo.php

@ -87,12 +87,13 @@ class weibo extends publicBase {
public function ajax_get_spider_list() { public function ajax_get_spider_list() {
$date = trim($this->post('date')); $date = trim($this->post('date'));
$uid = trim($this->post('uid'));
$cur_page = $this->post('currentPage') ? $this->post('currentPage') : 1; $cur_page = $this->post('currentPage') ? $this->post('currentPage') : 1;
$page_size = $this->post('pageSize') ? $this->post('pageSize') : 20; $page_size = $this->post('pageSize') ? $this->post('pageSize') : 20;
$obj = new mWeiboBehavior(); $obj = new mWeiboBehavior();
$list = $obj->getSpiderBehavior($date, $cur_page, $page_size); $list = $obj->getSpiderBehavior($date, $uid, $cur_page, $page_size);
$total = $obj->getSpiderBehaviorTotal($date); $total = $obj->getSpiderBehaviorTotal($date, $uid);
$rdata = array( $rdata = array(
'total' => $total, 'total' => $total,
@ -133,14 +134,14 @@ class weibo extends publicBase {
public function ajax_update_cookie() { public function ajax_update_cookie() {
$cookie = trim($this->get('cookie')); $cookie = trim($this->get('cookie'));
if(empty($cookie)) $this->ajax_json(false, '参数错误'); if (empty($cookie)) $this->ajax_json(false, '参数错误');
$type = $this->get('type') + 0; $type = $this->get('type') + 0;
$obj = new mWeiboBehavior(); $obj = new mWeiboBehavior();
$robj = $obj->initRedis(); $robj = $obj->initRedis();
$robj->set(_RC_WEIBO_LOGIN_COOKIE, $cookie); $robj->set(_RC_WEIBO_LOGIN_COOKIE, $cookie);
if($type == 0){ if ($type == 0) {
shell_exec("nohup /usr/bin/php /data1/www/zhishiku.yizherenxin.cn/queue/crontab/spider_behavior_data.php > /dev/null 2>&1 &"); shell_exec("nohup /usr/bin/php /data1/www/zhishiku.yizherenxin.cn/queue/crontab/spider_behavior_data.php > /dev/null 2>&1 &");
$this->ajax_json(true, '设置成功'); $this->ajax_json(true, '设置成功');
} }

25
model/mWeiboBehavior.php

@ -36,13 +36,24 @@ class mWeiboBehavior extends mBase {
return $this->obj->delete($this->tbl_delta, array('sql' => "`date`<?", 'vals' => array($date))); return $this->obj->delete($this->tbl_delta, array('sql' => "`date`<?", 'vals' => array($date)));
} }
public function getSpiderBehavior($date, $page_num, $page_size) { public function getSpiderBehavior($date, $uid, $page_num, $page_size) {
$where = array('sql' => "`date`=?", 'vals' => array($date));
if ($uid > 0) {
$where['sql'] .= " AND `uid`=?";
$where['vals'][] = $uid;
}
$offset = ($page_num - 1) * $page_size; $offset = ($page_num - 1) * $page_size;
return $this->obj->selectAll($this->tbl_data, array('sql' => "`date`=?", 'vals' => array($date)), 'created_at desc', array($offset, $page_size));
return $this->obj->selectAll($this->tbl_data, $where, 'created_at desc', array($offset, $page_size));
} }
public function getSpiderBehaviorTotal($date) { public function getSpiderBehaviorTotal($date, $uid) {
return $this->obj->count($this->tbl_data, array('sql' => "`date`=?", 'vals' => array($date))); $where = array('sql' => "`date`=?", 'vals' => array($date));
if ($uid > 0) {
$where['sql'] .= " AND `uid`=?";
$where['vals'][] = $uid;
}
return $this->obj->count($this->tbl_data, $where);
} }
public function getHotBehavior($type, $sdate, $edate, $page_num, $page_size) { public function getHotBehavior($type, $sdate, $edate, $page_num, $page_size) {
@ -75,11 +86,11 @@ class mWeiboBehavior extends mBase {
$weibo_list = array_column($weibos, null, 'wid'); $weibo_list = array_column($weibos, null, 'wid');
$weibo_user = $GLOBALS['WEIBO_USER_LIST']; $weibo_user = $GLOBALS['WEIBO_USER_LIST'];
foreach ($res as &$re){ foreach ($res as &$re) {
$weibo = isset($weibo_list[$re['wid']]) ? $weibo_list[$re['wid']] : array(); $weibo = isset($weibo_list[$re['wid']]) ? $weibo_list[$re['wid']] : array();
$re['uname'] = empty($weibo)? $weibo_user[WEIBO_USER_ZHANG] : $weibo_user[$weibo['uid']]; $re['uname'] = empty($weibo) ? $weibo_user[WEIBO_USER_ZHANG] : $weibo_user[$weibo['uid']];
$re['title'] = empty($weibo)? '无文字展示' : $weibo['text']; $re['title'] = empty($weibo) ? '无文字展示' : $weibo['text'];
$re['url'] = sprintf(WEIBO_DETAIL_URL, $re['wid']); $re['url'] = sprintf(WEIBO_DETAIL_URL, $re['wid']);
} }
return $res; return $res;

Loading…
Cancel
Save