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: 1, 2, 3, 4, 5, 6, 7, 8, [9] ] |
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();
}
}