mIRC Homepage
Posted By: Terminator2004 Make this work, plz???? - 06/06/06 12:30 AM
Can someone get this script to work?? The original scripter is awol. Been trying for months and I think its something in the lower sockread area...thx

Code:
  

; cnn breaking news 0.17
; by sonik (sonik@attbi.com)
;
; This addon checks the cnn.com website periodically for any breaking news
; and sends the message to wherever you want. Whenever they have breaking
; news they place a one or two sentence caption at the top of their site for 10-15 mins
; until they write a full story about it. With this addon you can be the first to tell your channel
; about some big news story or just echo it too yourself, whatever you want. 
; The messages they send are the same ones they send to their breaking news email
; subscribers, except it arrives 15-60 mins after the message is placed on their site, 
; meaning this addon is faster. If you have an email addon you could send out your
; own breaking news emails. There are usually atleast a few new messages from CNN
; a week. So, if nothing happens immediately, it's because it's a slow news day.
; If you turn on logging it creates and updates cnn.log which is found in your mirc 
; directory. It should prove to be fairly useful at first.
; TO INSTALL: Place cnn.mrc in your mirc directory. type ' /load -rs cnn.mrc ' into mirc 
; and click yes. Answer the 2 questions. 
; TO UPGRADE: You can either unload the old script by typing ' /unload -rs cnn.mrc ' and
;    then use the /load command mentioned above after the new file is in place. You can also 
;    use /cnn.upgrade . If the upgrade command doesn't work do the first option. You may also
;    want to delete the cnn.log file.
;    
; /cnn [on | off] - Without a parameter, it manually checks the web site. Nothing should show 
;           up on the screen, unless there is an error, or if there's breaking news. Add on or off
;           to the end to turn cnn.mrc on or off.
; /cnn.log [on | off] - Turns logging on or off. You can also use the numbers 0, 1, 2, and 3 instead
;           on and off. 0 = off, 1 = on, 2 = on part (3-4k each time the script runs will be written to cnn_full.log,
;           this text represents the upper half of the cnn.com page and may be usefull if you are having
;           problems. 3 = on full (50k will be written here, the entire cnn.com will be recorded)
;           /cnn.log by itself will tell you if logging in on or off.
; /cnn.upgrade - If you were using a previous version of this addon, type this to update a few
;           settings.
; /cnn.mode [mode] - Allows you to change where the messages should be sent. Examples:
;          "/echo -a" or "/amsg" or "/msg $me" - Don't type the quotes.
; /cnn.interval [x] - Allows you to change how often the web site is checked. The default 
;           is 180. The number is in seconds.
; /cnn.logview [x] - Displays the last x number of lines. If x isn't given, the default is 3.
; /cnn.text [text] - Changes the text that precedes breaking news text. The default is CNN: 
;           Example: CNN: Life has been disovered on the planet Mars.
; 
; I suppose I should add that I'm not affiliated with CNN in any way... and please don't sue me.
;
; Versions
; 0.17 - Fixed a couple bugs.
; 0.16 - Optimized code, should work faster. Changed logging options.
; 0.15 - Changed the code to reflect CNN's new HTML - Rewrote the logging to produce much
;   smaller and easier to read entries - Created several aliases to make the addon more user-friendly.
; 0.11 - Fixed a small bug.
; 0.10 - Initial release.

alias cnn { 
  ; %ticks = $ticks
  if $1 = on { .timercnn 0 %cnn.interval /cnn | .timer 1 1 cnn | echo -a 4cnn.mrc is on  | halt }
  if $1 = off { .timercnn off | echo -a 4cnn.mrc is off  | halt }
  sockopen cnn cnn.com 80
}

alias cnn.log { 
  if $1 isnum || $1 = on || $1 = off { 
    if $1 = on { %cnn.log = 1 } | elseif $1 = off { %cnn.log = 0 } | else { %cnn.log = $1 }
    echo -a 4cnn.mrc logging is now  $+ %cnn.log. [ $+ [ %cnn.log ] ] $+    ( $+ %cnn.log $+ ) | halt
  }
  if $len($1-) < 15 { echo -a 4cnn.mrc logging is  $+ %cnn.log. [ $+ [ %cnn.log ] ] $+    ( $+ %cnn.log $+ ) | halt }
  if %cnn.log > 0 {
    %cnn.lastlinenum = $lines(cnn.log)
    %cnn.lastline = $read(cnn.log,%cnn.lastlinenum)
    if %cnn.nomessage isin $1- { 
      if %cnn.nomessage isin %cnn.lastline && ~ isin %cnn.lastline { 
        if $count(%cnn.lastline,~) == 2 { write -l $+ %cnn.lastlinenum cnn.log $puttok(%cnn.lastline,$chr(32) $+ $asctime(mm/dd hh:nn:sst) $+ $chr(32),2,126) | halt }
        else { write -l $+ %cnn.lastlinenum cnn.log $instok(%cnn.lastline,$chr(32) $+ $asctime(mm/dd hh:nn:sst) $+ $chr(32),2,126) | halt }
      }
    }
    if %cnn.breakingnews isin $1- { 
      if %cnn.breakingnews isin %cnn.lastline { 
        if %cnn.message !isin %cnn.lastline { 
          %cnn.mode %cnn.text %cnn.message
          write cnn.log $asctime(mm/dd hh:nn:sst) $1-
          halt
        }
        else {
          if $count(%cnn.lastline,~) == 2 { write -l $+ %cnn.lastlinenum cnn.log $puttok(%cnn.lastline,$chr(32) $+ $asctime(mm/dd hh:nn:sst) $+ $chr(32),2,126) | halt }
          else { write -l $+ %cnn.lastlinenum cnn.log $instok(%cnn.lastline,$chr(32) $+ $asctime(mm/dd hh:nn:sst) $+ $chr(32),2,126) | halt }
        }
      }
      else { 
        %cnn.mode %cnn.text %cnn.message
      }
    }
    write cnn.log $asctime(mm/dd hh:nn:sst) $1-
  }
}

alias cnn.upgrade {
  if %cnn.mode = $null || %cnn.log = $null { echo -a error: some settings are not set correctly, try ' /load -rs cnn.mrc ' again | halt }
  %cnn.nomessage = no message found | %cnn.breakingnews = breaking news | %cnn.interval = 180 | %cnn.endhtml = </div>
  %cnn.text = CNN: | %cnn = <h1>BREAKING NEWS</h1>
  %cnn.log.3 = ON FULL | %cnn.log.2 = ON PART | %cnn.log.1 = ON | %cnn.log.0 = OFF
  if %cnn.fulllog = ON { %cnn.log = 3 }
  if %cnn.log = ON { %cnn.log = 1 }
  if %cnn.log = OFF { %cnn.log = 0 }
  if $timer(0) > 0 {
    %cnn.i = 1
    while %cnn.i <= $timer(0) {
      if $timer(%cnn.i).com = /cnn { .timer $+ %cnn.i off }
      inc %cnn.i
    }
  }
  .timercnn off | .timercnn 0 %cnn.interval /cnn | cnn
  echo -a 4cnn.mrc settings initialized.
}

alias cnn.fresh { unset %cnn.message | unset %cnn.1 }

alias cnn.mode {
  if $1 = $null { echo -a 4current cnn.mrc mode:  $+ %cnn.mode $+  | halt }
  %cnn.mode = $1- | echo -a 4new cnn.mrc mode:  $+ %cnn.mode $+  
}

alias cnn.interval {
  if $1 = $null { echo -a 4current cnn.mrc interval:  $+ %cnn.interval seconds ( $+ $round($calc(%cnn.interval / 60),2) mins $+ ) $+  | halt }
  if $1- !isnum { echo -a 4error: use only numbers for this field. each number represents 1 second. | halt }
  %cnn.interval = $1- | .timercnn off | .timercnn 0 %cnn.interval /cnn
  echo -a 4new cnn.mrc interval:  $+ %cnn.interval seconds ( $+ $round($calc(%cnn.interval / 60),2) mins $+ ) $+  
}

alias cnn.text {
  if $1 = $null { echo -a 4current cnn.mrc headline text: %cnn.text | halt }
  %cnn.text = $1- | echo -a 4current cnn.mrc headline text: %cnn.text
}

alias cnn.logview {
  if $1 !isnum { %cnn.lines = 3 } | else { %cnn.lines = $1 }
  %cnn.line = $lines(cnn.log)
  if lines isin $1 { return %cnn.line }
  %i2 = $calc(%cnn.line - %cnn.lines + 1)
  while %i2 <= %cnn.line { echo -a $remove($read(cnn.log, %i2), %cnn.lastmess) | inc %i2 }
}

on 1:load:/set %cnn.mode $?="Where do you want the message to be sent? Examples: $crlf $+ /echo -a $crlf $+ /msg #channel $crlf $+ /titlebar" | %cnn.log = 0 | if $?!="Do you want to turn on logging?" = $true { %cnn.log = 1 } | cnn.upgrade | echo -a 4cnn.mrc has been started
on 1:connect:/.timercnn 0 %cnn.interval /cnn | cnn

on 1:sockopen:cnn:/sockwrite -n cnn GET /
on 1:sockread:cnn:{
  %cnn.found = 0
  %cnn.endcheck = 0
  unset %cnn.1
  if ($sockerr > 0) return
  :nextread
  if %cnn.found > 0 && %cnn !isin %cnn.temp { %cnn.temp2 = %cnn.temp | sockread %cnn.temp | if %cnn.log > 1 { write cnn_full.log $left(%cnn.temp, 500) } | %cnn.temp = %cnn.temp2 %cnn.temp }
  elseif %cnn.found > 0 && %cnn isin %cnn.temp { sockread %cnn.temp | if %cnn.log > 1 { write cnn_full.log $left(%cnn.temp, 500) } }
  else { sockread %cnn.temp | if %cnn.log > 1 { write cnn_full.log $left(%cnn.temp, 500) } }
  if ($sockbr == 0) return
  if %cnn.found > 0 {
    if %cnn.endhtml !isin %cnn.temp && %cnn.endcheck < 5 { 
      inc %cnn.endcheck
      goto nextread
    }
    sockclose cnn
    set %cnn.1 $mid(%cnn.temp,$calc($pos(%cnn.temp,>,2)+1),$calc($pos(%cnn.temp,<,3)-$pos(%cnn.temp,>,2)-1))
    %cnn.1 = $remove(%cnn.1,Details soon.,Details soon,Details to come.,More soon.,Details on CNN.com.,Full story to come.,Full story soon.,Details shortly.)
    %cnn.message = %cnn.1 | cnn.log ~ Breaking News: %cnn.message
    halt
  }
  if %cnn isin %cnn.temp { %cnn.found = 1 | goto nextread }
  if %cnn.log < 3 && #CC0000 isin %cnn.temp && %cnn.found = 0 { goto end }
  if </body> isin %cnn.temp && %cnn.found = 0 { goto end }
  goto nextread
  :end
  ; e time: $calc(($ticks - %ticks) / 1000)
  sockclose cnn | cnn.log ~ no message found 
  halt
}



© mIRC Discussion Forums