I have been struggling with the following script for way too many hours now.

The script is intended to...

1. grab all of the messages from the news server for comp.sys.be.advocacy 
and write the output to a file called %BeAdvocacyMessages.txt

2. read %BeAdvocacyMessages.txt line-by-line and keep only the From, 
Subject, Date, and Newsgroups headers and the body of the message.

3. The script also creates an index of Subject and Date headers for each 
message with anchors; the message headers have reverse anchors back to 
the index.

3. the script is supposed to keep only messages from the previous day.  As 
for the index, currently the script puts references to all messages in the 
index (has not been modified yet.)

4. the output file %NEWSbeadvocacy.html is an attractive representation of 
the messages from a newsgroup.

I have a version of this script that works fine if I choose to keep ALL of the 
messages retrieved from the news server for comp.sys.be.advocacy.  But the 
resulting html file ends up being about 1 MB (too large for practical use.)

I'd like to be able to have the script limit the messages by date and here is 
where I'm running into some difficulty.  For some reason the resulting file is 
way too big, so much so I have to halt the script.

Any suggestions??????

Thanks.

-Ryan


REBOL []

secure none

nntp-host: news://news.host.dom
np: open nntp-host

write/append %BeAdvocacyMessages.txt insert np [headers-bodies from
"comp.sys.be.advocacy"]

unwanted-headers: [ "Path:" "In-Reply-To:" "Message-ID:" "References:" "MIME-Version:" 
"Content-Type:" "Lines:" "NNTP-Posting-Host:" "X-Trace:" "NNTP-Posting-Date:" 
"Organization:" "Xref:" "Followup-To:" "Content-Transfer-Encoding:" "X-Complaints-To:" 
"X-Mailer:" "X-Accept-Language:" "Reply-To:" 

all-headers: [ "Path:" "In-Reply-To:" "Message-ID:" "References:" "MIME-Version:" 
"Content-Type:" "Lines:" "NNTP-Posting-Host:" "X-Trace:" "NNTP-Posting-Date:" 
"Organization:" "Xref:" "Followup-To:" "Content-Transfer-Encoding:" "X-Complaints-To:" 
"X-Mailer:" "X-Accept-Language:" "Reply-To:" "X-Ne

beginning: make string! 100000
out: make string! 100000
ending: make string! 100000

insert beginning {<HTML><HEAD><TITLE>comp.sys.be.advocacy</TITLE></HEAD><BODY>}
append beginning {<TABLE><TR><TD><H1>comp.sys.be.advocacy</H1><TR><TD>generated }
append beginning now
append beginning {<TR><TD><HR><TR><TD>&nbsp<TR><TD><H3>Index</H3>Posts by sorted by 
date.<P>Click on the Subject line to jump down to the message itself.  At the message 
itself, click on the "back to index" link in the Subject line to jump back to the 
Index.<TR><TD>&nbsp}

words: copy []
ignore: copy []

from-trigger: false
subject-trigger: false
date-trigger: false
newsgroups-trigger: false

body-trigger: false

anchorlinks: make string! 10000
anchornumber: make integer! 0
anchorback: make integer! 0

yesterday: now/date - 1

unwanted-messages: []

get-news-date: func [
        date-str [string!] "One of the above date strings"
][
        date-str: any [find/tail date-str ", " date-str]
        to-date date-str
]

get-news-date2: func [
        date-str [string!] "One of the above date strings"
][
        date-str: any [find/tail date-str " " date-str]
        to-date date-str
]


count: 1
messages: set to-word rejoin ["message" count] {}

foreach fields next read/lines %BeAdvocacyMessages.txt [
        anchornumber: anchornumber + 1
        anchorback: anchorback + 1
        checker: true
        clear words
        foreach word parse fields none [append words word]
        firstword: pick words 1

        if find all-headers firstword [
                at-header: true
                new-message-ques: at-header and body-trigger
                if new-message-ques = true [
                        count: count + 1
                        messages: set to-word rejoin ["message" count] {}
                        body-trigger: false
                ]
        ]

        either firstword = "From:" [
                from-trigger: true
                append messages {<TR><TD bgcolor="#CCFFFF"><B><small>}
                append messages fields
                append messages {</small></B>}
                clear fields
        ] [append ignore fields]

        either firstword = "Subject:" [
                subject-trigger: true
                anchorbacklink: anchorback * 100000
                append messages {<TR><TD bgcolor="#CCFFFF"><A name="}
                append messages anchornumber
                append messages {"><B><small>}
                append messages fields
                append messages {</small></B></A><A HREF="#}
                append messages anchorbacklink
                append messages {"><font color="red"><small>&nbsp back to 
index</small></font></A>}
                append anchorlinks {<TR><TD bgcolor="#D3E4E4"><A name="}
                append anchorlinks anchorbacklink
                append anchorlinks {"><B><small>index number &nbsp}
                append anchorlinks anchornumber
                append anchorlinks {</small></B></A><TR><TD bgcolor="#EBE1A9"><A 
HREF="#}
                append anchorlinks anchornumber
                append anchorlinks {"><small>}
                append anchorlinks fields
                append anchorlinks {</small></A>}
                clear fields
        ] [append ignore fields]

        either firstword = "Date:" [
                date-trigger: true
                append messages {<TR><TD bgcolor="#CCFFFF"><B><small>}
                append messages fields
                append messages {</small></B>}
                append anchorlinks {<TR><TD bgcolor="#EBE1A9"><small>}
                append anchorlinks fields
                append anchorlinks {</small>}

                dateline: fields

                if error? try [
                        message-date: get-news-date dateline
                        ][
                        message-date: get-news-date2 dateline
                ]

                if message-date <> yesterday [append unwanted-messages count]

        ] [append ignore fields]

        either firstword = "Newsgroups:" [
                newsgroups-trigger: true
                append messages {<TR><TD bgcolor="#CCFFFF"><B><small>}
                append messages fields
                append messages {</small></B>}
                clear fields
        ] [append ignore fields]

        trigger-one: from-trigger and subject-trigger
        trigger-two: date-trigger and newsgroups-trigger
        trigger-sum: trigger-one and trigger-two
        
        if trigger-sum = true [
                append messages {<TR><TD bgcolor="white">}
                append anchorlinks {<TR><TD bgcolor="white">&nbsp}
                from-trigger: false
                subject-trigger: false
                date-trigger: false
                newsgroups-trigger: false
                trigger-one: false
                trigger-two: false
                trigger-sum: false
        ]

        if find unwanted-headers firstword [
                clear fields
                checker: false checker
        ]

        either checker = false [
                clear fields
        ][
                append messages {<small>}
                append messages fields
                append messages {</small><BR>}
                body-trigger: true
        ]
]

        insert ending {</TABLE></BODY></HTML>}


                        

for build 1 count 1 [
        builder: reform ["messagebuilder:" rejoin ["message" build]]
        do builder
        either find unwanted-messages build [
                build: build +1
        ][
                append out messagebuilder
        ]
]
        

write %NEWSbeadvocacy.html beginning
write/append %NEWSbeadvocacy.html anchorlinks
write/append %NEWSbeadvocacy.html out
write/append %NEWSbeadvocacy.html ending

Reply via email to