Last active
August 29, 2015 14:03
-
-
Save RunasSudo/e9532928c9c33bd06e00 to your computer and use it in GitHub Desktop.
WA Counter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/nations.xml.gz |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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