Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search

[REBOL] Re: Downloading patents?

From: bpaddock:csonline at: 3-Sep-2001 18:07

On Sunday 02 September 2001 02:41 am, Anton wrote:
> Well, it's working isn't it? :) Good job.
Now, its working better. I've got the look and feel how I want it with one exception. How do I get the 'cancel' button to work in the GetPatent function? Is there a Event tutorial some place, or some simpler way? Also I need to handle faults gracefully, like network time outs. On tutorials on that out there?
> I am also of the opinion that such long variable > names end up not being that helpful. I find that > it gets hard to read because the code is too long.
Lets just say on that point we don't agree.
> > Watch out for line-wraping...
REBOL [ Title: "Get Patent" Date: 03-Sep-2001/17:56:00:00-4:00 File: %patent.r Author: "Bob Paddock" Version: 1.0.0 ] GetPatent: func [ {Request a Patent Number to download from the net. Show progress. Return none on error.} PatentNumber /local url page pdf-url LastPage CurrentPage GetPageURL OutputNameFILE stop PatentDownload ] [ ;Examples PatentNumber: 4215330, 6163242 ; S+++6163242A1+I+ ; S+++4215330A1+I+ ; Read the 'navbar' to find out how many pages that there are to download: url: to-url rejoin ["" PatentNumber "&ID=US+++" PatentNumber "A1+I+"] page: read url LastPage: to-integer second parse copy/part find page "TOTPG=" 10 "=&" ; Need to test LastPage for zero ;LastPage: 3 ; testing print rejoin ["There are " LastPage " pages to this Patent, downloading now:"] pdf-url: rejoin ["" PatentNumber &ID=US+++ PatentNumber "A1+I+&PG="] ; Download all of the pages in the following loop, ; printout the URL and the name of the file being saved as we go: view/new center-face PatentDownload: layout [ title: text 300 bold red black center ProgressBar: progress 300x30 across button 90 "Cancel" [stop: true] stat: text 240 bold red black middle return ElapsedTimeText: text 240 bold red black center return EstimatedTimeText: text 240 bold red black center return RemainingTimeText: text 240 bold red black center ] stop: false ProgressBar/data: 0 title/text: reform ["Patent " PatentNumber " has " LastPage "pages"] show title StartTime: now/time ElapsedTimeText/text: reform ["Start Time: " StartTime] show ElapsedTimeText repeat CurrentPageNumber LastPage [ if stop [break] stat/text: reform ["Downloading Page " CurrentPageNumber " Now"] show stat GetPageURL: to-url rejoin ["http://" pdf-url to-string CurrentPageNumber] print GetPageURL OutputNameFILE: probe to-file rejoin ["US" PatentNumber "pg" CurrentPageNumber ".pdf"] ; Don't get pages that we do not need: if not exists? OutputNameFILE [ write/binary OutputNameFILE read/binary GetPageURL ] ProgressBar/data: ProgressBar/data + (1 / LastPage) elapsed: now/time - StartTime estimated: elapsed * ((LastPage + 1) / CurrentPageNumber) ElapsedTimeText/text: reform ["Elapsed Time: " elapsed] EstimatedTimeText/text: reform ["Estimated Time: " estimated] RemainingTimeText/text: reform ["Remaining Time: " estimated - elapsed] show [stat ProgressBar ElapsedTimeText EstimatedTimeText RemainingTimeText] ] ; Repeat unview/only PatentDownload print "Leaving GetPatent" ] ; GetPatent ; Derived from emailsend.r: view layout [ backdrop 30.40.100 effect [grid 10x10] origin 40x20 h2 white "Download Patent:" msg: field "Enter Patent Number here..." 210 text white "By Your Command:" across return button "Get Patent" [GetPatent msg/text] return button "Quit" [quit] ] ;do-events