Source for command line jlivejournal
Here is some source for a command line version of a java client. Didn't add in hardly any functionality, was just testing some HTTP specific JavaAPI stuff.
It works, and i guess that is the important part.
If anyone wants some commenting, or if you want to take it any hack it and want some help, lemme know.
-ken
(P.s. I'm almost done with the full gui (Swing) based livejournal Client) I'll drop a note here when its ready for download.
It works, and i guess that is the important part.
If anyone wants some commenting, or if you want to take it any hack it and want some help, lemme know.
-ken
(P.s. I'm almost done with the full gui (Swing) based livejournal Client) I'll drop a note here when its ready for download.
/* Command line jLiveJournal
* 2001 Sevensoft (Ken Brooks)
*
* GPL License, blah blah blah.
*
* This is about as basic as you can make a livejournal client.
* There is no formatting of the LiveJournal server response.
* I didn't add in another cl argument for subject, but feel free.
*
*/
import java.io.*;
import java.net.*;
import java.util.*;
public class Jlj {
public static void main(String[] args) throws Exception {
String modeString = new String("");
if(args.length == 3)
// should have usename password "post message"
{
String usernameString = args[0];
String passwordString = args[1];
String postStringFromArg = URLEncoder.encode(args[2]);
Calendar calendar = new GregorianCalendar();
modeString = "mode=postevent&user=" + usernameString +
"&password=" + passwordString +
"&event=" + postStringFromArg +
"&year=" + calendar.get(Calendar.YEAR) +
"&mon=" + (calendar.get(Calendar.MONTH)+1) +
"&day=" + calendar.get(Calendar.DATE) +
"&hour=" + calendar.get(Calendar.HOUR_OF_DAY) +
"&min=" + calendar.get(Calendar.MINUTE);
}
else if(args.length == 2)
// should have username password
{
String usernameString = args[0];
String passwordString = args[1];
modeString = "mode=login&user=" + usernameString + "&password=" + passwordString;
}
else
{
System.out.println("Usage:");
System.out.println(" loginMode: ");
System.out.println(" postMode : \"Post message\"");
}
URL url = new URL("http://www.livejournal.com/cgi-bin/log.cgi");
HttpURLConnection connection = (HttpURLConnection)url.openConnection();
connection.setRequestMethod("POST");
connection.setRequestProperty("Host", "www.livejournal.com");
connection.setRequestProperty("Content-type", "application/x-www-form-urlencoded");
connection.setRequestProperty("Content-length", Integer.toString(modeString.length()));
connection.setDoOutput(true);
PrintWriter out = new PrintWriter(
connection.getOutputStream());
out.print(modeString);
out.close();
System.out.println(connection.getResponseCode());
BufferedReader in = new BufferedReader(
new InputStreamReader(
connection.getInputStream()));
String inputLine;
while ((inputLine = in.readLine()) != null)
System.out.println(inputLine);
in.close();
}
}
