Auto-response to BOT movements

Source: Internet
Author: User
Tags add time
It's boring to think about how to create a robot. After analyzing the page, the following code is obtained. The function is relatively weak, and the time consumed is nothing more than regular expression debugging. To make it more complex, we need to do part-of-speech analysis and word statistics. Of course, this is not the focus of this discussion. The database table structure has been added synchronously this time. PS: Don't do anything bad.

It's boring to think about how to create a robot. After analyzing the page, the following code is obtained. The function is relatively weak, and the time consumed is nothing more than regular expression debugging. To make it more complex, we need to do part-of-speech analysis and word statistics. Of course, this is not the focus of this discussion. The database table structure has been added synchronously this time. PS: Don't do anything bad.

It's boring to think about how to create a robot. After analyzing the page, the following code is obtained.
The function is relatively weak, and the time consumed is nothing more than regular expression debugging.
To make it more complex, we need to do part-of-speech analysis and word statistics. Of course, this is not the focus of this discussion.

The database table structure has been added synchronously this time. PS: Don't do anything bad.

Git address for the project: http://git.oschina.net/fallBirds/oscsend-chicken-soup
<无>
  Login (); $ this-> getContent ();}/*** Logon account */private function login () {$ url =" https://www.oschina.net/action/user/hash_login ";/*** Enter your account */$ data =" email = & pwd = & verifyCode = & save_login = 1 "; $ curl = curl_init (); // start a CURL session curl_setopt ($ curl, CURLOPT_URL, $ url); // the address to be accessed curl_setopt ($ curl, CURLOPT_SSL_VERIFYPEER, 0 ); // check the certificate source curl_setopt ($ curl, CURLOPT_SSL_VERIFYHOST, 2); // check from the certificate whether the SSL encryption algorithm has curl_setopt ($ curl, CURLOPT_USERAGENT, $ _ SERVER ['HTTP _ USER_AGENT ']); // simulate the user's browser curl_setopt ($ curl, CURLOPT_FOLLOWLOCATI ON, 1); // use automatic jump curl_setopt ($ curl, CURLOPT_AUTOREFERER, 1); // automatically set Referer curl_setopt ($ curl, CURLOPT_POST, 1 ); // send a regular Post request curl_setopt ($ curl, CURLOPT_POSTFIELDS, $ data); // curl_setopt ($ curl, CURLOPT_COOKIEJAR, $ this-> cookie) submitted by Post ); // name of the file storing the Cookie information: curl_setopt ($ curl, CURLOPT_COOKIEFILE, $ this-> cookie); // read the Cookie information stored above: curl_setopt ($ curl, CURLOPT_TIMEOUT, 30); // set the timeout limit to prevent endless loop curl _ Setopt ($ curl, CURLOPT_HEADER, 0); // display the returned Header region content curl_setopt ($ curl, CURLOPT_RETURNTRANSFER, 1 ); // The obtained information returns curl_exec ($ curl) as a file stream; // execute the curl_close ($ curl) operation ); // close the CURL session}/*** get content */public function getContent () {$ replyType = $ this-> replyType ();/*** user center address. Ft = atme is @ the reminder Message Address */$ url =" http://my.oschina.net/u/2251019/?ft=atme "; $ Curl = curl_init (); // start a CURL session curl_setopt ($ curl, CURLOPT_URL, $ url); // curl_setopt ($ curl, CURLOPT_COOKIEFILE, $ this-> cookie); // read the previously stored Cookie information curl_setopt ($ curl, CURLOPT_TIMEOUT, 30); // set the timeout limit to prevent endless loops curl_setopt ($ curl, CURLOPT_HEADER, 0); // display the returned Header area content curl_setopt ($ curl, CURLOPT_RETURNTRANSFER, 1 ); // The obtained information is returned as a file stream $ tmpInfo = curl_exec ($ curl); // execute the curl_close ($ curl) operation ); // close the CURL session/*** the following start is the user and condition matching @ reminder */preg_match_all ('/([\ S \ S] + ?) <\/Td>/', $ tmpInfo, $ allContent); foreach ($ allContent [0] as $ key => $ value) {/*** obtain the unique ID value of @ notification first * to check whether the matching with the database already exists. */Preg_match ("/tweet_reply \ (\ d +) \)/", $ value, $ replyId ); $ recordId = preg_replace ('/[^ 0-9]/', ', $ replyId ['0']); if ($ this-> exitReply ($ recordId )) {continue;}/*** name */preg_match ('/([\ s \ S] + ?) <\/A>/', $ value, $ userName); $ replyName = strip_tags ($ userName ['0']); /*** get the command to be executed */preg_match ("/
  
   
([\ S \ S] + ?) <\/P>/", $ value, $ cmd); foreach ($ replyType as $ k => $ v) {/*** match the command * assemble the content that needs to be replied * starting from this code, you can do it as a basis * For example: add the learning instruction. Of course, you need to write another method to learn the instruction. * Well, when you write it here, you will find that the above Code is too many times and must be simplified and encapsulated. * Currently, I have only written it here, but I have not written it further. */If (strpos ($ cmd [0], $ v ['Type _ name'])! = False) {$ replyConten = ""; $ replyConten. = "@ {$ replyName}"; $ type = $ this-> getReplyType ($ v ['Type _ name']); if (empty ($ type )) {$ replyConten. = "Sorry, I have not found any matching command for chicken soup. You can enter # learning # + to learn chicken soup. ";} Else {$ replyConten. = $ type ['learn _ reply'];} $ this-> doReply ($ replyConten); $ this-> recordReplySend ($ recordId, $ replyName, $ replyConten) ;}}}/ *** reply type */public function replyType () {$ thing = $ this-> db-> prepare ("SELECT * FROM {$ this-> prefix} reply_type"); $ thing-> execute (); return $ something-> fetchAll ();}/*** last reply */private function exitReply ($ id) {$…… = $ this-> db-> prepare ("SELECT * FROM {$ This-> prefix} reply_record where record_id =: record_id "); $ something-> execute (array ('record _ id' => $ id )); return $ something-> fetch ();}/*** get the corresponding reply content * @ param type $ type */private function getReplyType ($ type) {$ something = $ this-> db-> prepare ("SELECT * FROM {$ this-> prefix} learn WHERE learn_title =: learn_title limit 1 "); $ something-> execute (array ('learn _ title' => $ type); return $ something-> fetch ();}/*** send chicken soup * @ todo You see! The code here is obviously repeated. */Private function doReply ($ content) {sleep (2); $ url =" http://my.oschina.net/action/tweet/pub "; $ Data =" user = & user_code = & attachment = 0 & code_brush = & code_snippet = & msg = {$ content} "; $ curl = curl_init (); // start a CURL session curl_setopt ($ curl, CURLOPT_URL, $ url); // curl_setopt ($ curl, CURLOPT_POST, 1 ); // send a regular Post request curl_setopt ($ curl, CURLOPT_POSTFIELDS, $ data); // curl_setopt ($ curl, CURLOPT_COOKIEFILE, $ this-> cookie) submitted by Post ); // read the previously stored Cookie information curl_setopt ($ curl, CURLOPT_TIMEOUT, 30); // set the timeout limit to prevent endless loops curl_setopt ($ curl, CURLOPT_HEADER, 0 ); // display the returned Header content curl_setopt ($ curl, CURLOPT_RETURNTRANSFER, 1); // The obtained information returns $ tmpInfo = curl_exec ($ curl) as a file stream ); // execute curl_close ($ curl); // close the CURL session}/*** the record has been sent */private function recordReplySend ($ id, $ user, $ content) {$ SQL = "INSERT INTO {$ this-> prefix} reply_record ('record _ id', 'user _ name', 'content') VALUES (: record_id,: user_name,: content) "; $ something = $ this-> db-> prepare ($ SQL); $ something-> execute (array ('record _ id' => $ id, 'User _ name' => $ user, 'content' => $ content) ;}}$ mail = new reply (); $ mail-> index ();
  
-- PhpMyAdmin SQL Dump -- version 4.1.8 -- http://www.phpmyadmin.net---- Host: 127.0.0.1 -- Generation Time: 2014-10-21 09:35:46 -- server Version: 5.6.15 -- PHP Version: 5.5.9SET SQL _MODE = "NO_AUTO_VALUE_ON_ZERO"; SET time_zone = "+ 00:00 ";/*! 40101 SET @ OLD_CHARACTER_SET_CLIENT = @ CHARACTER_SET_CLIENT */;/*! 40101 SET @ OLD_CHARACTER_SET_RESULTS = @ CHARACTER_SET_RESULTS */;/*! 40101 SET @ OLD_COLLATION_CONNECTION = @ COLLATION_CONNECTION */;/*! 40101 set names utf8 */; ---- Database: 'chicken' ---- 'ck _ learn' of the orders TABLE -- create table if not exists 'ck _ learn' ('learn _ id' int (11) not null AUTO_INCREMENT, 'Learn _ title' varchar (255) not null, 'learn _ reply' varchar (255) not null, 'learn _ status' tinyint (1) not null, 'Learn _ time' int (11) not null, primary key ('learn _ id') ENGINE = InnoDB DEFAU Lt charset = utf8 AUTO_INCREMENT = 6; -- Comment TABLE structure 'ck _ Post' -- create table if not exists 'ck _ Post' ('Post _ id' int (11) not null AUTO_INCREMENT, 'Post _ page' int (11) not null comment 'page collection page', 'Post _ content' text not null comment 'chicken soup content ', 'Post _ send' tinyint (1) not null comment' whether to send ', 'Post _ time' int (11) not null comment' add time ', primary key ('Post _ id ') ENGINE = MyISAM default charset = utf8 AUTO_INCREMENT = 6971; -- tables TABLE Structure 'ck _ reply_record '-- create table if not exists 'ck _ reply_record' ('reply _ record_id 'int (11) not null AUTO_INCREMENT, 'record _ id' bigint (20) not null, 'user _ name' varchar (128) not null, 'content' varchar (255) not null, primary key ('reply _ record_id ') ENGINE = InnoDB DEFAUL T charset = utf8 COMMENT = 'System reply record 'AUTO_INCREMENT = 22; -- tables TABLE Structure 'ck _ reply_type '-- create table if not exists 'ck _ reply_type' ('reply _ type_id 'int (11) not null AUTO_INCREMENT, 'Type _ name' varchar (128) not null, primary key ('reply _ type_id ') ENGINE = MyISAM default charset = utf8 AUTO_INCREMENT = 5 ;/*! 40101 SET CHARACTER_SET_CLIENT = @ OLD_CHARACTER_SET_CLIENT */;/*! 40101 SET CHARACTER_SET_RESULTS = @ OLD_CHARACTER_SET_RESULTS */;/*! 40101 SET COLLATION_CONNECTION = @ OLD_COLLATION_CONNECTION */;

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.