Skip to content

Instantly share code, notes, and snippets.

@RunasSudo
Last active August 29, 2015 14:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RunasSudo/e9532928c9c33bd06e00 to your computer and use it in GitHub Desktop.
Save RunasSudo/e9532928c9c33bd06e00 to your computer and use it in GitHub Desktop.
WA Counter
/nations.xml.gz
import java.io.*;
import java.net.*;
import java.util.*;
import java.util.zip.*;
public class WACounter {
public static void main (String[] args) throws Exception { // :P
String REGION = args[0];
BufferedReader rdr = new BufferedReader(new InputStreamReader(new GZIPInputStream(new FileInputStream("nations.xml.gz"))));
String data = null;
int numWA = 0;
while ((data = rdr.readLine()) != null) {
//Regex is bad for XML? What about loops!
if (data.startsWith("<UNSTATUS>")) {
String unstatus = data.substring(10, data.length() - 11);
if (unstatus.equalsIgnoreCase("WA Member")) {
//Nation is a WA Member. Tell me more!
while ((data = rdr.readLine()) != null) {
if (data.startsWith("<REGION>")) {
String region = data.substring(8, data.length() - 9);
if (region.equalsIgnoreCase(REGION)) {
//Success!
numWA++;
break;
}
}
}
}
}
}
rdr.close();
System.out.println(numWA);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment