VoyForums
[ Show ]
Support VoyForums
[ Shrink ]
VoyForums Announcement: Programming and providing support for this service has been a labor of love since 1997. We are one of the few services online who values our users' privacy, and have never sold your information. We have even fought hard to defend your privacy in legal cases; however, we've done it with almost no financial support -- paying out of pocket to continue providing the service. Due to the issues imposed on us by advertisers, we also stopped hosting most ads on the forums many years ago. We hope you appreciate our efforts.

Show your support by donating any amount. (Note: We are still technically a for-profit company, so your contribution is not tax-deductible.) PayPal Acct: Feedback:

Donate to VoyForums (PayPal):

Login ] [ Main index ] [ Post a new message ] [ Search | Check update time | Archives: 12345678[9] ]


[ Next Thread | Previous Thread | Next Message | Previous Message ]

Date Posted: 19:42:46 05/29/03 Thu
Author: Tim
Subject: I've got the archiver/cacher working, and I've done North and South and East so far...
In reply to: Tim 's message, "Sorry about that, y'all..." on 19:41:01 05/29/03 Thu

To all you programmers out there, this is a free-ware, public-domain, steal-this-code program. It can be fitted or retrofitted to any caching needs. Any questions? Email me through (not AT, it's a spam-resistant redirector) meheral.10.evolute@spamgourmet.com
If I wanted to cache TT South, I would do
java VoyForumArchiver 22866 0 2 97
22866 is the forum #, 0 is the archive number, 2 and 97 are the first and last posts to cache. If the archive number is 0, the program doesn't look into the archive folder. If it is 5, the prog goes to http://www.voy.com/22866/5/2.html for post#2. Any pages that have been deleted or do not exist are noted in the output as "ERROR:" with the page name. The cache directory format is:
C:\My Documents\Tim's Stuff\Java\KRPG\harvested\www.voy.com\22866\62.html
The code is below, sorry about how Voy double-spaces everything:



import java.io.*;
import java.net.*;

public class VoyForumArchiver
{
public static final String localBase = "C:/My Documents/Tim's Stuff/Java/KRPG/harvested/";
public static final String domainBase = "www.voy.com/";
public static final String extension = ".html";

protected static String base = null;// "www.voy.com/22875/2.html"
protected static String fileName = null;// "1.html"
protected static String archiveName = null;

protected static FileWriter current;

public static void main(String[] args)
{
int forum = -1;
int archive = -1;
int first = -1;
int last = -1;

boolean parsed = false;
boolean confirmed = false;

try
{
forum = Integer.parseInt(args[0]);
archive = Integer.parseInt(args[1]);
first = Integer.parseInt(args[2]);
last = Integer.parseInt(args[3]);

parsed = true;

confirmed = forum>=1 && archive>=0 && first>=1 && last>=first;
}
catch(ArrayIndexOutOfBoundsException aioobe)
{
System.out.println("ERROR: Specify all three arguments:\n"+aioobe);
}
catch(NullPointerException npe)
{
System.out.println("ERROR: Specify all three arguments:\n"+npe);
}
catch(NumberFormatException nfe)
{
System.out.println("ERROR: Incorrect number format:\n"+nfe);
}
finally
{
if(!(parsed & confirmed))
{
System.out.println("ERROR: Usage:\njava VoyForumArchiver forum archive first last\n"+
"\tarchive\tis 0 if the posts are in the main index");
System.exit(0);
}
}
//so we're in the clear
try
{
writePagesToFile(forum, archive, first, last);
}
catch(Throwable t)
{
t.printStackTrace();
}
}

protected static void writePagesToFile(int forum, int archive, int first, int last) throws Throwable
{
URL temp;
archiveName = archive == 0 ? "" : archive+"/";
for(int i=first; i<=last; i++)
{
try
{
fileName = i+extension;
base = domainBase+forum+'/'+archiveName+fileName;
URL tempU = new URL("http://"+base);
String ts = WebReader.readFromWeb(tempU);
if(ts.indexOf("Invalid Message or Archive") != -1)
{
throw new IOException("404 Not Found on Voy");
}
// System.out.println(ts);
writeToFile(ts, forum, i);
}
catch(IOException ioe)
{
System.out.println("ERROR: File not read/written ("+base+"):\n"+ioe);
}
}
}

protected static void writeToFile(String text, int forum, int i) throws Throwable
{
File tf = new File(localBase+base);
tf.getParentFile().mkdirs();
System.out.println(tf);
// System.out.println(tf.exists());
// System.out.println(tf.getAbsoluteFile());
tf.createNewFile();
current = new FileWriter(tf);
current.write(text);
current.flush();
current.close();
}

}


[ Next Thread | Previous Thread | Next Message | Previous Message ]


Replies:

  • Got it all! Available upon request. (NT) -- Tim, 21:33:45 05/29/03 Thu


    Forum timezone: GMT-5
    VF Version: 3.00b, ConfDB:
    Before posting please read our privacy policy.
    VoyForums(tm) is a Free Service from Voyager Info-Systems.
    Copyright © 1998-2019 Voyager Info-Systems. All Rights Reserved.