Package by.dreamer

Source Code of by.dreamer.App

/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/

package by.dreamer;

import com.healthmarketscience.jackcess.Database;
import com.healthmarketscience.jackcess.DatabaseBuilder;
import com.healthmarketscience.jackcess.Table;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Map;
import java.util.TreeMap;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;

/**
*
* @author Admin
*/
public class App {

    /**
     * @param args the command line arguments
     * @throws java.io.IOException
     */
    public static void main(String[] args) throws IOException {
        Document doc = Jsoup.connect("http://snooker.org/res/index.asp?event=268").get();
        for (Element event : doc.select("table#event thead")) {
            System.out.println(event.siblingIndex() + " : " + event.className() + " : " + event.html());
        }
    }

    private static void updateEvents() throws IOException {
        try (Database db = DatabaseBuilder.open(new File("d:\\My Sport\\Snooker\\Info.mdb"))) {
            Table sevents = db.getTable("snooker_events");
            for (Map<String, Object> event : getEvents()) {
                sevents.addRowFromMap(event);
            }           
        }
    }

    private static ArrayList<Map<String, Object>> getEvents() throws IOException {
        ArrayList<Map<String, Object>> events = new ArrayList<>();
        Document doc = Jsoup.connect("http://snooker.org/res/index.asp?season=2013&template=2").get();
        for (Element event : doc.select("table#diary tbody tr")) {
            events.add(getEvent(event));
        }
        return events;
    }

    private static Map<String, Object> getEvent(Element eventNode) {
        Map<String, Object> event = new TreeMap<>();
        for (Element item : eventNode.select("td")) {
            switch (item.siblingIndex()) {
                case 1: System.out.println("# : " + item.text());
                        event.put("num", item.text());
                        break;
                case 3: System.out.println("Start : " + item.text());
                        event.put("start", item.text());
                        break;
                case 5: System.out.println("Finish : " + item.text());
                        event.put("finish", item.text());
                        break;
                case 7: System.out.println("Dates : " + item.text());
                        event.put("dates", item.text());
                        break;
                case 9: System.out.println("Event : " + item.text());
                        System.out.println("Event : " + item.child(0).attr("abs:href"));
                        event.put("name", item.text());
                        event.put("ref", item.child(0).attr("abs:href"));
                        break;
                case 11: System.out.println("Draw : " + item.text());
                         event.put("draw", item.text());
                         break;
                case 13: System.out.println("Type : " + item.text());
                         event.put("type", item.text());
                         break;
                case 15: System.out.println("Venue : " + item.text());
                         event.put("venue", item.text());
                         break;
                case 17: System.out.println("City : " + item.text());
                         event.put("city", item.text());
                         break;
                case 19: System.out.println("Country : " + item.text());
                         event.put("country", item.text());
                         break;
                default: System.out.println("Invalid item : " + item.text());
            }
        }
        return event;
    }
   
}
TOP

Related Classes of by.dreamer.App

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.