Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Parsing boards

Name: Anonymous 2009-10-09 9:56


(defun thread-info (line)
  (remove-if (lambda (x)         
               (zerop (length x)))      
             (cl-ppcre:split "<>" line)))
                                                                                         
; name author id post-count last-post                                                                                                                                                
(defmacro with-thread ((&rest names) line &body body)
  `(destructuring-bind `,(,@names &rest ,(gensym))
       (thread-info ,line)
     ,@body))
                                         
(defun thread-link (id &key (server "dis")
                    (board "prog")  
                    (post-number ""))
  (concatenate 'string                           
               "http://" server ".4chan.org/read/"
               board "/" (write-to-string id) "/"
               (if (stringp post-number)
                   post-number                    
                   (write-to-string post-number))))


Example use:

CL-USER> (with-open-file (s "data")                                                                                                                                           
           (do ((line (read-line s nil nil)                                                                                                                                          
                      (read-line s nil nil))                                                                                                                                         
                (i 0 (1+ i)))                                                                                                                                                        
               ((or (= i 10) (null line)))                                                                                                                                           
             (with-thread (name author id)                                                                                                                                           
                 line                                                                                                                                                                
                 (format t "Topic name: ~A. Author: ~A. Link: ~A~%"                                                                                                                  
                         name author (thread-link id)))))
                                                                                                                                             
Topic name: Have You Listened to Your Program Today?. Author: Anonymous. Link: http://dis.4chan.org/read/prog/"1255036130"/                                                          
Topic name: JS. Author: Anonymous. Link: http://dis.4chan.org/read/prog/"1255087731"/                                                                                                
Topic name: Sexual acts. Author: Anonymous. Link: http://dis.4chan.org/read/prog/"1255078786"/                                                                                       
Topic name: Final Fantasy. Author: Anonymous. Link: http://dis.4chan.org/read/prog/"1255014637"/                                                                                     
Topic name: Japan. Author: PROG. LANG. LISTS MEME FAN. Link: http://dis.4chan.org/read/prog/"1255075749"/                                                                            
Topic name: I'm just going to come out say it.. Author: Anonymous. Link: http://dis.4chan.org/read/prog/"1238918305"/                                                           
Topic name: Oh the personality. Author: Anonymous. Link: http://dis.4chan.org/read/prog/"1255034599"/                                                                                
Topic name: Sussman attains enlightenment. Author: Anonymous. Link: http://dis.4chan.org/read/prog/"1209943333"/                                                                     
Topic name: Fall dog bombs the moon. Author: Anonymous. Link: http://dis.4chan.org/read/prog/"1255070515"/                                                                           
Topic name: Present day.... Author: Present time.... Link: http://dis.4chan.org/read/prog/"1254664796"/


P.S. My programming language > yours, suave style.

Name: PHPAdvocate !/IpofbrXAc 2009-10-09 13:44


$prog_index = file_get_contents('http://dis.4chan.org/prog/');

preg_match_all("%a name='([0-9]+)%", $prog_index, $ids);
preg_match_all('%postername">(.+?)<%', $prog_index, $authors);
preg_match_all("%1-40'>(.+?)</a></h2>%", $prog_index, $titles);

foreach($ids[1] as $key => $id)
{
    $thread_data[$id] = array
    (
        'author' => strip_tags( $authors[1][$key] ),
        'title'  => $titles[1][$key]
    );
}

foreach($thread_data as $id => $data)
{
    printf('Topic name: %s. Author: %s. Link: http://dis.4chan.org/read/prog/%d' . "\n", $data['title'], $data['author'], $id);
}


Topic name: Haxus the Original Poster. Author: Haxus the Original Poster. Link: http://dis.4chan.org/read/prog/1252033912
Topic name: Final Fantasy. Author: Haxus the haxer. Link: http://dis.4chan.org/read/prog/1255014637
Topic name: Twitter accounts. Author: Anonymous. Link: http://dis.4chan.org/read/prog/1254239526
Topic name: Coolness. Author: Anonymous. Link: http://dis.4chan.org/read/prog/1255015277
Topic name: Parsing boards. Author: Haxus the gay. Link: http://dis.4chan.org/read/prog/1255096595
Topic name: The Forced Writing of Code. Author: Anonymous. Link: http://dis.4chan.org/read/prog/1255101445
Topic name: JS. Author: Anonymous. Link: http://dis.4chan.org/read/prog/1255087731
Topic name: A message to  Linux fans. Author: Anonymous. Link: http://dis.4chan.org/read/prog/1252430981
Topic name: Have You Listened to Your Program Today?. Author: Anonymous. Link: http://dis.4chan.org/read/prog/1255036130
Topic name: THE RAPE TUNNEL. Author: Anonymous. Link: http://dis.4chan.org/read/prog/1254809827
Topic name: Jon Harrop. Author: Anonymous. Link: http://dis.4chan.org/read/prog/1255009907
Topic name: Sexual acts. Author: Haxus the lvl.99 black mage. Link: http://dis.4chan.org/read/prog/1255078786
Topic name: Japan. Author: Anonymous. Link: http://dis.4chan.org/read/prog/1255075749
Topic name: I'm just going to come out say it.. Author: Anonymous. Link: http://dis.4chan.org/read/prog/1238918305
Topic name: Oh the personality. Author: Anonymous. Link: http://dis.4chan.org/read/prog/1255034599
Topic name: Sussman attains enlightenment. Author: Haxus the twat. Link: http://dis.4chan.org/read/prog/1209943333
Topic name: Fall dog bombs the moon. Author: Anonymous. Link: http://dis.4chan.org/read/prog/1255070515
Topic name: Present day.... Author: Haxus the leaver. Link: http://dis.4chan.org/read/prog/1254664796

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List