有時可能會有一段時間沒辦法用 Plurk 。此時如果不想讓卡馬下降,除了開啟假期模式以外,也可以參考「never4get 的記事本: [PHP 筆記] 發個私噗給自己」,利用程式定時自動發私噗給自己。在這裡稍微說明一下利用 Ubuntu Linux 系統實做的步驟。

(如果您只有 Windows 可用,這裡也有 Windows 系統的實做說明。)

Ubuntu 系統預設是沒有 CLI 跟 cURL 的,所以執行以下的指令來安裝:

  1. sudo apt-get install php5-cli php5-curl
  2. 安裝完 cURL 之後,執行以下的指令重新啟動 Apache ,這樣 cURL 才會生效:
    sudo /etc/init.d/apache2 restart
  3. 之後,新增 plurkbot.php ,內容如下:
    <?php
    	header('Content-type:text/html; charset=utf-8');
    	define('NICKNAME', ''); //輸入 PLURK 的帳號
    	define('PASSWORD', ''); //輸入 PLURK 的密碼
    	$user_id = getid(NICKNAME);
    	define('USER_ID', "$user_id");
    	set_time_limit(240);
    
    	// login
    	$ch = curl_init();
    	curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    	curl_setopt($ch, CURLOPT_COOKIEJAR, '\plurk_cookie_n.txt');
    	curl_setopt($ch, CURLOPT_URL, 'http://www.plurk.com/Users/login');
    	curl_setopt($ch, CURLOPT_POSTFIELDS, 'nick_name='.NICKNAME.'&password='.PASSWORD);
    	curl_exec($ch);
    	curl_close($ch);
    
    	//
    
    	date_default_timezone_set("Asia/Taipei");
    	$out = date("Y-m-d H:i:s");
    	echo $out;
    	post($out);
    
    	function post($message){
    		// post
    		$ch3 = curl_init();
    		curl_setopt($ch3, CURLOPT_COOKIEFILE, '\plurk_cookie_n.txt');
    		curl_setopt($ch3, CURLOPT_URL, 'http://www.plurk.com/TimeLine/addPlurk');
    		curl_setopt($ch3, CURLOPT_POSTFIELDS, 'qualifier=gives&limited_to=%5B'.USER_ID.'%5D&lang=tr_ch&uid='.USER_ID.'&no_comments=0&content='.$message);
    		curl_exec($ch3);
    		curl_close($ch3);
    	}
    
    	function getid($name){
    		$ourl= 'http://plurk.com/'.NICKNAME;
    		$fid = file_get_contents($ourl);
    		preg_match('/user_id\": (.*?)\,/s',$fid,$matches);
    		$u_id = $matches[1];
    		return($u_id);
    	}
    ?>

帳號跟密碼記得要設定唷。確認一下 plurkbot.php 的絕對路徑;這裡以 "/home/username/bin/plurkbot.php" 為例。

  • 最後,再利用 crontab 讓這個程式定期自動執行即可。執行:
    crontab -e

    新增以下內容:

    # 每隔四小時噗浪自動發噗
    0 */4 * * * /usr/bin/php /home/username/bin/plurkbot.php

    這裡的 "/home/username/bin/plurkbot.php" 應該要跟剛剛確認過的 plurkbot.php 絕對路徑相同。