package org.sillyjirafe.linker;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.sillyjirafe.db.Crawl_StateDB;
import org.sillyjirafe.db.ElementsDB;
import org.sillyblahaj.uoapi.*;

public class Main {
	public static void main(String[] args) throws Exception
	{
		Out Out = new Out();
		ElementsDB elementDB = new ElementsDB("jdbc:sqlite:elements.db");
		Crawl_StateDB crawlstateDB = new Crawl_StateDB("jdbc:sqlite:crawlstates.db");
		elementDB.LinkToDB();
		crawlstateDB.LinkToDB();
		
        List<String> bindNames = Out.PreOut();

        Map<String, Integer> pages = new HashMap<>();
        for (String nom : bindNames) {
            pages.put(nom, crawlstateDB.getPage(nom));
        }
		
		List<element> elements = Out.out(pages);
		
		for (int i = 0; i < elements.size(); i++)
		{
			element el = elements.get(i);
			elementDB.AddEllement(el.title(), el.url(), el.licence(), el.source(), el.type());
		}
		
		for (String name : bindNames) {
            crawlstateDB.updatePage(name);
        }
		
		elementDB.Close();
		crawlstateDB.Close();
	}
}
