Script Junkie | REBOL Bots

Over the past two decades, my search for the perfect scripting language led me to work with companies such as HP, Amiga, and Apple. In that time, I investigated more than 50 different languages, from Ada to C, from Pascal to Lisp. I wanted a language that was very simple and readable with almost no syntax, yet very flexible with a wide degree of expressive freedom.


January 01, 2002
URL:http://www.drdobbs.com/script-junkie-rebol-bots/184413924

REBOL [
   Title:  "Example Script"
   Date:   20-July-1999
   File:   %example.r
   Author: "Carl Sassenrath"
   Email:  [email protected]
   Purpose: "Show an example header"
]
REBOL [
   Title:  "Scan Web Sites"
   Date:   20-June-1999
   Purpose: "Scan web sites for keywords"
]

user: [email protected]

web-sites: [www.rebol.com www.xml.com www.cnn.com]

keywords: ["robot" "agent" "filter"]

foreach site web-sites [
   page: read join http:// site
   foreach item keywords [
      if find page item [send user page  break]
   ]
]


http://your.server/time

http://your.server/dir+docs

http://your.server/del+oldfile.txt

http://your.server/read+docs/file.txt

http://your.server/mail?
REBOL [
   Title: "Mail Summary"
   Date:  4-June-1999
   Purpose: {
      Creates an HTML file that summarizes
      the email in your inbox.
   }
]

html: make string! 10000

emit: func [data] [append html reduce data]

emit [
   <html><body>
   <H2>"Mailbox Summary for " now</H2>
   <p><table>
]

inbox: read pop://user:[email protected]

foreach message inbox [
   mail: import-email message
   emit [
      <tr>
      <td> first mail/from </td>
      <td> mail/date </td>
      <td> mail/subject </td>
      <td> length? mail/content </td>
      </tr>
   ]
]

emit [</table><p></body></html>]

write %inbox.html html  ; the % indicates a filename

forward [email protected]

forward "urgent"

list %docs

send %docs/letter.txt

delete %docs/salaries.html

quit
REBOL [
   Title: "Download Web Page Links"
   Purpose: {
      Save items of a particular variety
      (images, MP3s, etc.) from a web site.
   }
]

system/schemes/default/timeout:  0:10

site:   http://www.theonion.com/
start:  "archives_content.html"
suffix: ".html"

save-dir: %savedir
tags: make block! 100  ; list of tags

page: read join site start

parse page [
   to "<" some [
      copy tag ["<" thru ">"] 
      (append tags tag) | to "<"
   ]
]

web-link-rules: [
   "<A" thru "HREF="
   [{"} copy link to {"} | copy link to ">"]
   to end
]

foreach tag tags [
   if all [
      parse tag web-link-rules
      not find link http://
      find link suffix
   ][
      file: second split-path to-url link
      if not exists? file [
         print ["Retrieving: " link]
         write/binary save-dir/:file read/binary site/:link
      ]
   ]
]
send [email protected] append "pass-email^/" mold [

   forward [email protected]

   list %docs

   send %docs/letter.txt

   delete %docs/salaries.html

]
REBOL [
   Title: "Micro Web Server"
   Date:  24-June-1999
   Purpose: "A web server for HTML and images only"
]

   web-dir: %web-pages

   listen-port: open/lines tcp://:80  ; port used for web connections

   errors: [
      400 "Forbidden" "No permission to access:"
      404 "Not Found" "File was not found:"
   ]

   send-error: function [err-num file] [err] [
      err: find errors err-num
      insert http-port form ["HTTP/1.0" 
         err-num err/2 "^/Content-type: text/html^/^/" 
         <HTML> <TITLE> err/2 </TITLE>
         "<BODY><H1>SERVER ERROR</H1><P>REBOL Webserver Error:"
         err/3 file newline <P> </BODY> </HTML>
      ]
   ]

   send-page: func [data mime] [
      insert data rejoin ["HTTP/1.0 200 OK^/Content-type: " mime "^/^/"]
      write-io http-port data length? data
   ] 

   while [on] [
      http-port: first wait listen-port
      request: first http-port
      file: "index.html"
      mime: "text/plain"
      parse request ["get" ["http" | "/ " | copy file to " "]]
      parse file [thru "." [
            "html" (mime: "text/html") |
            "gif"  (mime: "image/gif") |
            "jpg"  (mime: "image/jpeg")
         ]
      ]
   ]
   any [
      if not exists? web-dir/:file [send-error 404 file]
      if error? try [data: read/binary web-dir/:file] [send-error 400 file]
      send-page data mime
   ]
   close http-port
]
parse file [
   "time" (send-page form now mime) |
   "dir" "+" copy name thru end
      (send-page read to-file append name "/") |
   "del" "+" copy name thru end
      (delete to-file name
      send-page "file deleted" mime) |
   "read" ["+" copy name thru end
      (send-page read name)] |
    "mail?" (mail-port: open pop://user:pass@server
      send-page reform [length? mail-port "new messages"] mime
      close mail-port) |
   thru "." [
      "html" (mime: "text/html") |
      "gif"  (mime: "image/gif") |
      "jpg"  (mime: "image/jpeg")
   ] (any [
      if not exists? web-dir/:file [send-error 404 file]
      if error? try [data: read/binary web-dir/:file] [
         send-error 400 file]
      send-page data mime
   ])
]

REBOL [Title: "Remote Email Agent"]

   users: [[email protected] [email protected]]
   password: "pass-email"
   stop-time: now + 12:00
   prior-len: 0

   do-ops: func [ops user mailbox /local action] [
      foreach [op arg] ops [
         action: select [
            forward [
               if string? arg [
                  foreach mail mailbox [
                     if find mail arg [send user mail]
                  ]
               ]
               if email? arg [
                  foreach mail mailbox [
                     msg: import-email mail
                     if arg = first msg/from [send user mail]
                  ]
               ]
            ]
            list [send user read arg]
            send [send user read arg]
            delete [delete arg]
            quit [quit]
         ] op
         either action [do action][
            send user join "bad op: " op
         ]
      ]
   ]

   while [now < stop-time] [
      mailbox: read pop://user:[email protected]

      foreach msg skip mailbox prior-len [
         msg: import-email msg
         from: first msg/from
         if all [
            find users from
            msg/subject = password
         ][
            ops: try [load msg/content]
            either error? ops [
               send from join "Error: " msg/content
            ][
               do-ops ops from mailbox
            ]
         ]
      ]
      prior-len: length? mailbox
      wait 0:10
   ]

Terms of Service | Privacy Statement | Copyright © 2024 UBM Tech, All rights reserved.