Last active
January 3, 2016 07:19
-
-
Save RunasSudo/8429011 to your computer and use it in GitHub Desktop.
DSA Calculator
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
package io.github.runassudo.dsacalculator; | |
import java.io.*; | |
import java.net.*; | |
import java.util.*; | |
public class DSACalculator { | |
public static void main (String[] args) throws Exception { // :P | |
String REGION = args[0]; | |
URLConnection conn = new URL("http://www.nationstates.net/cgi-bin/api.cgi?region=" + REGION + "&q=nations").openConnection(); | |
BufferedReader rdr = new BufferedReader(new InputStreamReader(conn.getInputStream())); | |
String data = rdr.readLine(); | |
rdr.close(); | |
float total = 0; | |
String[] nationsArray = data.substring(data.indexOf("<NATIONS>") + "<NATIONS>".length(), data.indexOf("</NATIONS>")).split(":"); | |
List<String> nations = Arrays.asList(nationsArray); | |
rdr = new BufferedReader(new FileReader("nations.xml")); | |
data = null; | |
while ((data = rdr.readLine()) != null) { | |
if (data.contains("<NAME>")) { | |
String name = data.substring(data.indexOf("<NAME>") + "<NAME>".length(), data.indexOf("</NAME>")).toLowerCase().replace(" ", "_"); | |
if (nations.contains(name)) { | |
while (!(data = rdr.readLine()).contains("<CATEGORY>")); | |
String category = data.substring(data.indexOf("<CATEGORY>") + "<CATEGORY>".length(), data.indexOf("</CATEGORY>")); | |
int score = 0; | |
if (category.equals("Psychotic Dictatorship") || category.equals("Iron Fist Consumerists") || category.equals("Corporate Police State")) | |
score = 1; | |
if (category.equals("Authoritarian Democracy") || category.equals("Moralistic Democracy") || category.equals("Right-wing Utopia")) | |
score = 2; | |
if (category.equals("Corrupt Dictatorship") || category.equals("Father Knows Best State") || category.equals("Mother Knows Best State") || category.equals("Compulsory Consumerist State")) | |
score = 2; | |
if (category.equals("Tyranny by Majority") || category.equals("Conservative Democracy") || category.equals("Free-Market Paradise")) | |
score = 4; | |
if (category.equals("Iron Fist Socialists") || category.equals("Libertarian Police State") || category.equals("Benevolent Dictatorship")) | |
score = 4; | |
if (category.equals("Democratic Socialists") || category.equals("Inoffensive Centrist Democracy") || category.equals("Capitalist Paradise")) | |
score = 8; | |
if (category.equals("Liberal Democratic Socialists") || category.equals("New York Times Democracy") || category.equals("Corporate Bordello")) | |
score = 8; | |
if (category.equals("Scandinavian Liberal Paradise") || category.equals("Left-Leaning College State") || category.equals("Capitalizt")) | |
score = 8; | |
if (category.equals("Left-wing Utopia") || category.equals("Civil Rights Lovefest") || category.equals("Anarchy")) | |
score = 8; | |
if (score == 0) | |
System.out.println("UNKNOWN CATEGORY: " + category); | |
total += score; | |
} | |
} | |
} | |
rdr.close(); | |
System.out.println(total / nations.size()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment