package DNA.java;
import javax.swing.*;
import java.awt.*;
import java.text.*;
import java.io.* ;
import java.util.*;
import java.net.* ;
public class Berechnung {
public Berechnung() {}
public static void main(String[] berechnung) throws Exception {
BufferedReader br0 = new BufferedReader(new InputStreamReader(System.in));
boolean b1 = true;
boolean b2 = true;
String geblubber="";
String[] o ={"nick","read","datum1","onMin"};
URL url;
int time = 0;
int k= 0;
int i =0;
int xtb =0;
String nick = "";
String read = "";
String datum1 = "";
String onMin ="";
double onMinD;
System.out.println("Eingabe:");
DateFormat df = new SimpleDateFormat("dd.MM.yyyy");
DateFormat defaultDate = DateFormat.getDateInstance();
String datum = defaultDate.format(new java.util.Date());
Date to = df.parse(datum);
StringTokenizer st = new StringTokenizer(br0.readLine() , ",");
int al =st.countTokens()+1;
String[] nicks = new String[al];
double[] werte = new double[al];
while (st.hasMoreTokens()) {
for (int x =0;st.hasMoreTokens(); x++) {
xtb++;
nick = st.nextToken();
if (nick.contains("DNAofDeath")){
nick = " blah";}
if (nick.contains("James")){
nick = " blah";}
if (x >= 1){
nick = nick.substring(1);}
nick = "http://knuddels.de/ww/"+nick;
if (nick.contains(" "));{
nick = nick.replace(" ","_");
nick = nick.replace("&","%26");
url = new URL(nick);}
BufferedReader br1 = new BufferedReader(new InputStreamReader(url.openStream()));
while((read = br1.readLine()) != null){
read = read.replace("<HTML><HEAD><META HTTP-EQUIV=\"Refresh\" CONTENT=\"0; URL=", "");
read = read.replace("\"></HEAD></HTML>", "");
url = new URL(read);
BufferedReader br2 = new BufferedReader(new InputStreamReader(url.openStream()));
while((read = br2.readLine()) != null){
nick = nick.replace("http://knuddels.de/ww/", "");
if (read.contains("<FONT FACE=\"Arial\">
[B]")){
read = read.replace("<FONT FACE=\"Arial\">
[B]", "");
read = read.replace("<FONT COLOR=\"#000000\" SIZE=2>[/B]<FONT COLOR=\"000000\"> hat sich am [B]", "");
if (read.contains("http://spenden.knuddels.de")) {
read = read.replace("<a href=\"http://spenden.knuddels.de\" target=_blank><img border=0 src=\"../../images/ico_ribbon.gif\"></a> ", "") ;
read = read.replace("<FONT COLOR=\"#000000\" SIZE=2>[/B]<FONT COLOR=\"000000\">hat sich am [B]", "");}
read = read.replace("&","&");
read = read.replace("&",">");
read = read.replace("&","<");
read = read.replace("&", " ");
nick = nick.replace("%26","&");
nick = nick.replace("_", " ");
int zeichen = nick.length();
int h = nick.length();
if (zeichen == nick.length()){
nick = read.substring(0, h);
k = nick.length() + 10 ;
datum1 = read.substring( h, k);
String time1 = read.substring(h + 39, h + 47);
read = read.replace(nick + datum1 + "[/B]<FONT COLOR=\"000000\"> um " + time1 + " bei Knuddels registriert und seitdem schon [B]", "");
String ez = read.substring(0, 10);
String[] n = {"0","1","2","3","4","5","6","7","8","9"};
for (int a =0; a <= 9; a++) {
String t = ez.substring(a, a+1);
for (int j =0; j <= 9; j++) {
if (t.contains(n[j])){
onMin = onMin + n[j];}}}
onMinD = Double.parseDouble( onMin ) ;
Date from = df.parse(datum1);
double diffMillis = to.getTime() - from.getTime();
double diffMins = diffMillis / (1000 * 60 );
double erg = (100 / diffMins ) * (double) onMinD ;
double stunden = erg * 0.24 ;
double minuten = stunden * 60 ;
erg = Math.round( erg * 10000. ) / 10000.;
onMin = "" + "";
boolean b3 = true;
boolean b4 = true;
try {
File file = new File("C:\\nickliste\\"+nick+".txt");
FileWriter fw = null;
if( file.exists() )
if (b3){
System.out.println("Datei existiert bereits.");
b3 = false;} else
{
System.out.println("Datei wird erstellt.");
b3 = false;}
fw = new FileWriter( file.getPath() , true );
PrintWriter pw = new PrintWriter( fw );
if (b4){
pw.println("Registriert am : " + datum1);
pw.println("Verbrachte Minuten : " + onMinD);
pw.println("Suchtywert : " + erg);
pw.println("Letzte aktualisierung : " + datum);
b4 = false;}
fw.flush();
fw.close();
pw.flush();
pw.close();} catch( IOException e ) {
e.printStackTrace();}
System.out.println(erg +" = " + nick);
nicks[i] = nick ;
werte[i] = erg ;
i++;}}}
br2.close();}
br1.close();}
br0.close();}
final Map<String, Double> map = new HashMap<String, Double>();
int g = 1;
for (int xd = 0;xd <= xtb;xd++){
map.put(nicks[xd],werte[xd]);}
Comparator<String> comparator = new Comparator<String>() {
public int compare(String a, String b) {
return -map.get(a).compareTo(map.get(b));}};
Map<String, Double> sortedMap = new TreeMap<String, Double>(comparator);
sortedMap.putAll(map);
for (String s : sortedMap.keySet()) {
try {
File file = new File("C:\\test.txt");
FileWriter fw = null;
if( file.exists() )
if (b1){
System.out.println("Datei existiert bereits.");
b1 = false;} else
if (b1){
System.out.println("Datei wird erstellt.");
b1 = false;}
fw = new FileWriter( file.getPath() , true );
PrintWriter pw = new PrintWriter( fw );
if (b2){
pw.println("#Suchtywerte _Top-Ten_#");
b2 = false;}
String blah = "#" + g + ".)" + s + " ~~~~~~> " + sortedMap.get(s);
pw.println(blah);
fw.flush();
fw.close();
pw.flush();
pw.close();} catch( IOException e ) {
e.printStackTrace();}
g++;
if (g == 21){
break;}}
String path = "C:\test.txt";}}