Java Programming Forums Desktop App (Is that okay?)
A desktop app that checks threads for new posts, new notifications and what have you sounded nice so I decided to start working on one. However, this will obviously be doing a lot of authentication through login.php while I am testing and wasn't sure if that would be kosher. I can probably have it do the 'stay logged in' thing and just pass the stored cookie to the site so that there won't be multiple login attempts each time it gets run. Right now, I can log in and get to the main page to begin scraping, but I wanted to make sure doing this was fine with the site's administration before going further. Doesn't seem to me this would be a problem but doesn't hurt to be sure.
Re: Java Programming Forums Desktop App (Is that okay?)
I think somebody else was working on a similar application. Might want to do a search and contact that person before you reinvent the wheel.
Re: Java Programming Forums Desktop App (Is that okay?)
Hello KucerakJM.
Thank you for your enthusiasm.
As Kevin pointed out, something like this has been brought up many times.
I am trying to find the threads but here is one:
http://www.javaprogrammingforums.com...-software.html
I'm sure it will be a fun project to work on but I can't really see it of being much use.
All the features such as newest posts, posts with zero replies etc are all functions easily accessed directly on the forums.
Although I don't mind you testing the application, I would prefer it if you had a test environment rather than making multiple requests to the live site.
I understand how this could be hard though as vBulletin is a licensed application.
I would be very interested to see the code you have written to login to the forums.
Maybe you could submit it and we can add it to the code tutorials section or promote it to an article?
Re: Java Programming Forums Desktop App (Is that okay?)
Thank you for the replies. I did do a search for other ideas like this and found that they were from a while back which is why I made this additional thread. I know it's a bit redundant but I see my app as being a bit different. The idea is just to have a desktop app scrape info such as new threads/posts (which could be put into a "watch" list) or private messages (the only reason login would really be needed) and then notify the user appropriately; probably through a little popup containing a link that opens the page in a browser. The following does the login work, whether or not it's the best way to go about it, I can't say but it does work.
Code java:
import java.io.BufferedReader;
//import java.io.BufferedWriter;
import java.io.DataOutputStream;
import java.io.InputStreamReader;
import java.math.BigInteger;
import java.net.HttpURLConnection;
import java.net.URL;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Scanner;
public class barebonesLogin {
public static void main(String[] args) throws Exception
{
String username, password;
Scanner input = new Scanner(System.in);
System.out.println("Please enter your username: ");
username = input.nextLine();
System.out.println("Please enter your password: ");
password = input.nextLine();
login("http://javaprogrammingforums.com/login.php?do=login", username, MD5Password(password));
}
public static void login(String url, String username, String password) throws Exception
{
// This was obtained through the Live HTTP Headers firefox plugin
String content = "vb_login_username=" + username + "&vb_login_password=&vb_login_password_hint=Password&cookieuser=1&s=&" +
"securitytoken=guest&do=login&vb_login_md5password="+ password +"&vb_login_md5password_utf="+ password;
// Create a new URL object
URL website = new URL(url);
// Creates Connection referred by the URL object
HttpURLConnection conn = (HttpURLConnection) website.openConnection();
// Set some basic connection properties
conn.setRequestMethod("POST");
conn.setDoOutput(true);
conn.setDoInput(true);
conn.connect();
// Create a DataOutputStream to be able to write data to the underlying HttpURLConnection outputstream
DataOutputStream out = new DataOutputStream(conn.getOutputStream());
// Send the content
out.writeBytes(content);
/*
// Variables for getting header names and setting cookie value(s)
String hName=null;
String cookie = null;
// Loops through headers to obtain all cookie values and add them to the cookie String
// The cookie would be used later to access pages as a logged-in user
for (int i=1; (hName = conn.getHeaderFieldKey(i))!=null; i++)
{
if (hName.equals("Set-Cookie")) {
cookie += conn.getHeaderField(i) + "; ";
}
}
*/
// Force any buffered output to be written to the stream and then close it to free the resources
out.flush();
out.close();
// This part will get the returned html data which can be checked if the login was successful
BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
String line = "";
// Use the FileWriter if there is a large amount of text
//FileWriter fstream = new FileWriter("out.txt");
//BufferedWriter fout = new BufferedWriter(fstream);
while((line=in.readLine())!=null)
{
System.out.println(line);
//fout.write(line);
//fout.newLine();
}
//fout.close();
// Close out the buffered reader that is no longer needed
in.close();
// Done with the connection
conn.disconnect();
}
private static String MD5Password(String password) throws NoSuchAlgorithmException
{
MessageDigest md = MessageDigest.getInstance("MD5");
byte[] messageDigest = md.digest(password.getBytes());
BigInteger md5 = new BigInteger(1, messageDigest);
String md5Pass = md5.toString(16);
while (md5Pass.length() < 32) {
md5Pass = "0" + md5Pass;
}
return md5Pass;
}
}
If this was successful the the returned html code with contain the text "Thank you for logging in, [YourUsername]". Thinking about it, I just want to make a glorified html scraper to automate checking threads in the background while I do w/e on my computer. Again, thank you for the replies
- Michael
Re: Java Programming Forums Desktop App (Is that okay?)
Just so you know there is an app that already checks for replies and is interconnected with Google Chrome [My favorite browser], which has an official label and works nicely with this forum and almost every other forum as well while being verified safe by Google. [Which is a big plus compared to a third-party program] Also has an iOS, Android, and Blackberry app already released at production-level.
https://chrome.google.com/webstore/d...nflfofmahljkjj
Re: Java Programming Forums Desktop App (Is that okay?)
Well, since the point of furthering this project is now moot it is time to look for something else to preoccupy my time. Thank you all for the replies.
Re: Java Programming Forums Desktop App (Is that okay?)
Thanks for posting your code. I am going to test it out and possibly post it in the code snippets section. I will be sure to credit you.