Rewrite Metadata Validator/SoC 2008/IRC Scanner

From Creative Commons
Revision as of 08:02, 16 June 2008 by Hdworak (talk | contribs) (Syntax highlighting)
Jump to: navigation, search

If one wants to search for his or her activity at the IRC channel of Creative Commons, he or she can use Google or the following public domain script written in PHP 5: <source lang="php"><?php

$nick = 'john'; $path = 'http://mirrors.creativecommons.org/irc/cc/'; preg_match_all('/%23cc\.'.date('Y').'\-\d\d\-\d\d\.log\.html/', file_get_contents($path), $matches); $irrelevant = array(); if (file_exists('irrelevant.txt')) {

   $irrelevant = unserialize(file_get_contents('irrelevant.txt'));

} foreach ($matches[0] as $url) {

   if (file_exists('relevant/'.($filename = str_replace('%23', , $url)))
    || in_array($filename, $irrelevant)) {
       echo 'Skipped ', $filename, PHP_EOL;
       continue;
   }
   $contents = file_get_contents($path.$url);

if (!strstr($contents, $nick.'<td class="text"')) { echo 'Irrelevant ', $filename, PHP_EOL; $irrelevant[] = $filename; continue; } file_put_contents('relevant/'.$filename, $contents); echo 'Downloaded ', $filename, PHP_EOL; } file_put_contents('irrelevant.txt', serialize($irrelevant)); echo 'Saved irrelevant.txt', PHP_EOL;</source> Please note that the herewith enclosed script searches the logs saved the current year. All relevant logs are downloaded to the local machine.