#!/usr/bin/perl -w # # sitescooper - download news from web sites and convert it automatically # into one of several formats suitable for viewing on a Palm # handheld. # # Skip down to read the POD documentation, or search for "=head1". # # To set up, search for "CUSTOMISE" -- note UK/Irish spelling. ;) # Change the setting appropriately and uncomment it, if required. # Then move the required sites from the "sites_off" directory into the # "sites" directory, and those will be downloaded automatically next # time you run the script. # # Sitescooper is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; either version 2 of the License, or (at your # option) any later version. See the COPYRIGHT section in the POD # documentation below, or the "doc/gpl.html" file in the distribution, # for further details. $main::VERSION = "2.1.1"; # NOTE: on Windows, you will need to use 2 backslashes in any paths in # this built-in configuration file, to avoid Perl interpreting them, # like so: C:\\TMP # $CONFIG = ' # UNIX users: you can use $HOME in this file to mean your home directory. # ####################################################################### # OPTIONAL SITE-DEPENDENT CONFIGURATION # NOTE: If you will be converting sites into Pilot-readable format, you # may need to specify this! The directory under your PalmPilot Desktop dir # where installable PRC files need to go, or the application that should # be run to install a PRC file. # # On UNIX platforms using pilot-xfer, you should set up a directory where # installed files are to go before you run "pilot-xfer -i". Alternatively, # several UNIX versions of pilot desktop are supported; place the name, as # printed below, in the PilotInstallApp field to use them. These are # PilotManager, gnome-pilot and JPilot. # # On a Win32 machine with only one Pilot user, this is determined # automatically from the registry, so you will not need to set it. # Otherwise, on Win32 platforms this is generally of the format # {pilotdir}/{username}/Install, where {pilotdir} is the PalmPilot Desktop # directory, and {username} is the abbreviation of the Pilot user name. # # MacOS users: you do need to customise this, a default will be used # (although nothing will be written there). You need to run the conversion # command yourself afterwards :( # PilotInstallDir: $HOME/pilot/install # CUSTOMISE # PilotInstallApp: InstallApp # CUSTOMISE ####################################################################### # Sites directory, where the site description files are stored. # By default, a directory called "sites" under your current directory, # or under your $HOME on UNIX, is used if it exists. # SitesDir: $HOME/lib/sites # CUSTOMISE ####################################################################### # Temporary directory to use for sitescooper. A subdirectory will be # created called sitescooper{uid} where {uid} is your user id (or # 0 on Win32 platforms). On UNIX platforms, this defaults to a hidden # directory under your home dir, for privacy. # TmpDir: /tmp # CUSTOMISE ####################################################################### # Specify the HTTP proxy server in use at your site, if applicable. # ProxyHost: proxy.clubi.ie # CUSTOMISE # ProxyPort: 80 # CUSTOMISE ####################################################################### # Diff will be searched for on the path if this is not specified here. # If the word "MODULE" is specified, the Perl module Algorithm::Diff # will be used instead of an external helper application (Note that # Algorithm::Diff seems significantly slower though). # Diff: C:\\path\\to\\diff.exe # CUSTOMISE # Diff: MODULE # CUSTOMISE ####################################################################### # The MakeDoc tool will be searched for on the path if it is # not specified here. Default values are "makedoc" on UNIX platforms, # or "makedocw.exe" on Windows. # MakeDoc: makedocw.exe # CUSTOMISE # The iSilo conversion tool will be searched for on the path if it is # not specified here. Default values are "iSilo386" for UNIX platforms, # or "iSiloC32.exe" on Windows. # iSilo: iSiloC32.exe # CUSTOMISE ####################################################################### # Where you want the text-format output to be saved. If commented, # it will be saved under the sitescooper temporary directory. # Note: MakeDocW on Windows does not like reading text from a # directory with spaces in it, such as a directory under Program Files. # In this case changing this parameter may help. # TextSaveDir: C:\\where\\I\\want\\News # CUSTOMISE ####################################################################### # Where the "site_samples" directory can be found. # This is the directory sitescooper was installed into. Generally # sitescooper can work this out itself. # SitescooperDir: /where/sitescooper/is/installed # CUSTOMISE ####################################################################### # If you want to share a cache between multiple users or multiple # configurations of sitescooper, uncomment this. It will allow a # shared cache to be used. # SharedCacheDir: /home/jm/lib/scoop_cache # CUSTOMISE ####################################################################### # How long should a cached front page be considered valid? # Specified in minutes. # CachedPageLifetime: 60 # CUSTOMISE ####################################################################### # How long should cached files be kept before expiring? Specified in # days, and fractions are OK. # ExpireCacheAfter: 7.0 # CUSTOMISE '; #--------------------------------------------------------------------------- =head1 NAME sitescooper - download news from web sites and convert it automatically into one of several formats suitable for viewing on a Palm handheld. =head1 SYNOPSIS sitescooper [options] [ [-site sitename] ...] sitescooper [options] [-sites sitename ...] sitescooper [options] [-levels n] [-storyurl regexp] url [...] Options: [-debug] [-refresh] [-config file] [-limit numkbytes] [-install dir] [-instapp app] [-dump] [-dumpprc] [-nowrite] [-nodates] [-quiet] [-admin cmd] [-nolinkrewrite] [-stdout-to file] [-keep-tmps] [-noheaders] [-nofooters] [-fromcache] [-filename template] [-prctitle template] [-text | -html | -mhtml | -doc | -isilo | -misilo | -richreader | -pipe fmt command] =head1 DESCRIPTION This script, in conjunction with its configuration file and its set of B files, will download news stories from several top news sites into text format and/or onto your Palm handheld (with the aid of the B/B or B utilities). Alternatively URLs can be supplied on the command line, in which case those URLs will be downloaded and converted using a reasonable set of default settings. HTTP and local files, using the C protocol, are both supported. Multiple types of sites are supported: =over 4 1-level sites, where the text to be converted is all present on one page (such as Slashdot, Linux Weekly News, BluesNews, NTKnow, Ars Technica); 2-level sites, where the text to be converted is linked to from a Table of Contents page (such as Wired News, BBC News, and I, Cringely); 3-level sites, where the text to be converted is linked to from a Table of Contents page, which in turned is linked to from a list of issues page (such as PalmPower). =back In addition sites that post news as items on one big page, such as Slashdot, Ars Technica, and BluesNews, are supported using diff. Note that at this moment in time, the URLs-on-the-command-line invocation format does not support 2- or 3-level sites. The script is portable to most UNIX variants that support perl, as well as the Win32 platform (tested with ActivePerl 5.00502 build 509). Currently the configuration is stored as a string inside the script itself, but an alternative configuration file can be specified with the B<-config> switch. The sites downloaded will be the ones listed in the site files you keep in your F directory. sitescooper maintains a cache in its temporary directory; files are kept in this cache for a week at most. Ditto for the text output directory (set with B in the built-in configuration). If a password is required for the site, and the current sitescooper session is interactive, the user will be prompted for the username and password. This authentication token will be saved for later use. This way a site that requires login can be set up as a .site -- just log in once, and your password is saved for future non-interactive runs. Note however that the encryption used to hide the password in the sitescooper configuration is pretty transparent; I recommend that rather than using your own username and password to log in to passworded sites, a dedicated, sitescooper account is used instead. =head1 OPTIONS =over 4 =item -refresh Refresh all links -- ignore the F file, do not diff pages, and always fetch links, even if they are available in the cache. =item -config file Read the configuration from B instead of using the built-in one. =item -limit numkbytes Set the limit for output file size to B kilobytes, instead of the default 200K. =item -install dir The directory to save PRC files to once they've been converted, in order to have them installed to your Palm handheld. =item -instapp app The application to run to install PRC files onto your Palm, once they've been converted. =item -site sitename Limit the run to the site named in the B argument. Normally all available sites will be downloaded. To limit the run to 2 or more sites, provide multiple B<-site> arguments like so: -site ntk.site -site tbtf.site =item -sites sitename [...] Limit the run to multiple sites; an easier way to specify multiple sites than using the -site argument for each file. =item -levels n When specifying a URL on the command-line, this indicates how many levels a site has. Not needed when using .site files. =item -storyurl regexp When specifying a URL on the command-line, this indicates the regular expression which links to stories should conform to. Not needed when using .site files. =item -doc Convert the page(s) downloaded into DOC format, with all the articles listed in full, one after the other. =item -text Convert the page(s) downloaded into plain text format, with all the articles listed in full, one after the other. =item -html Convert the page(s) downloaded into HTML format, on one big page, with a table of contents (taken from the site if possible), followed by all the articles one after another. =item -mhtml Convert the page(s) downloaded into HTML format, but retain the multiple-page format. This will create the output in a directory called B; in conjunction with the B<-dump> argument, it will output the path of this directory on standard output before exiting. =item -isilo Convert the page(s) downloaded into iSilo format (see http://www.isilo.com/ ), on one big page. This is the default. The page(s) will be displayed with a table of contents (taken from the site if possible), followed by all the articles one after another. =item -misilo Convert the page(s) downloaded into iSilo format (see http://www.isilo.com/ ), with one iSilo document per site, with each story on a separate page. The iSilo document will have a table-of-contents page, taken from the site if possible, with each article on a separate page. =item -richreader Convert the page(s) downloaded into RichReader format using HTML2Doc.exe (see http://users.erols.com/arenakm/palm/RichReader.html ). The page(s) will be displayed with a table of contents (taken from the site if possible), followed by all the articles one after another. =item -pipe fmt command Convert the page(s) downloaded into an arbitrary format, using the command provided. Sitescooper will still rewrite the page(s) according to the B argument, which should be one of: =over 4 =item text Plain text format. =item html HTML in one big page. =item mhtml HTML in multiple pages. =back The command argument can contain C<__SCOOPFILE__>, which will be replaced with the filename of the file containing the rewritten pages in the above format, C<__SYNCFILE__>, which will be replaced with a suitable filename in the Palm synchronization folder, and C<__TITLE__>, which will be replaced by the title of the file (generally a string containing the date and site name). Note that for the B<-mhtml> switch, C<__SCOOPFILE__> will be replaced with the name of the file containing the table-of-contents page. It's up to the conversion utility to follow the href links to the other files in that directory. =item -dump Output the page(s) downloaded directly to stdout in text or HTML format, instead of writing them to files and converting each one. This option implies B<-text>; to dump HTML, use B<-dump -html>. =item -dumpprc Output the page(s) downloaded directly to stdout, in converted format as a PRC file, suitable for installation to a Palm handheld. =item -nowrite Test mode -- do not write to the cache or already_seen file, instead write what would be written normally to a directory called new_cache and a new_already_seen file. This is very handy when writing a new site file. =item -debug Enable debugging output. This output is in addition to the usual progress messages. =item -quiet Process sites quietly, without printing the usual progress messages to STDERR. Warnings about incorrect site files and system errors will still be output, however. =item -admin cmd Perform an administrative command. This is intended to ease the task of writing scripts which use sitescooper output. The following admin commands are available: =over 4 =item dump-sites List the sites which would be scooped on a scooping run, and their URLs. Instead of scooping any sites, sitescooper will exit after performing this task. The format is one site per line, with the site file name first, a tab, the site's URL, a tab, the site name, a tab, and the output filename that would be generated without path or extension. For example: S =item journal Write a journal with dumps of the documents as they pass through the formatting and stripping steps of the scooping process. This is written to a file called B in the sitescooper temporary directory. =item import-cookies file Import a Netscape B file into sitescooper, so that certain sites which require them, can use them. For example, the site B requires this. Here's how to import cookies on a UNIX machine: S and on Windows: S Unfortunately, MS Internet Explorer cookies are currently unsupported. If you wish to write a patch to support them, that'd be great. =back =item -nolinkrewrite Do not rewrite links on scooped documents -- leave them exactly as they are. =item -noheaders Do not attach the sitescooper header (URL, site name, and navigation links) to each page. =item -nofooters Do not attach the sitescooper footer ("copyright retained by original authors" blurb) to each page. =item -fromcache Do not perform any network access, retrieve everything from the cache or the shared cache. =item -filename template Change the format of output filenames. B