Search in sources :

Example 6 with DownloadService

use of delta.games.lotro.utils.DownloadService in project lotro-tools by dmorcellet.

the class CharacterLogPageParser method parseLogPage.

private boolean parseLogPage(CharacterLog log, String rootURL, int pageNumber, int retryNumber) {
    if (_logger.isInfoEnabled()) {
        _logger.info("Page #" + pageNumber + ((retryNumber > 0) ? " try #" + retryNumber : ""));
    }
    boolean ret;
    String url = rootURL + "=" + String.valueOf(pageNumber);
    try {
        DownloadService downloader = DownloadService.getInstance();
        String page = downloader.getPage(url);
        Source source = new Source(page);
        // <table class="gradient_table activitylog">
        Element logTable = JerichoHtmlUtils.findElementByTagNameAndAttributeValue(source, HTMLElementName.TABLE, "class", "gradient_table activitylog");
        if (logTable != null) {
            List<Element> trs = logTable.getAllElements(HTMLElementName.TR);
            if ((trs != null) && (trs.size() >= 1)) {
                // ignore first (table headers)
                trs.remove(0);
                for (Element tr : trs) {
                    CharacterLogItem item = parseLogItem(tr);
                    if (item != null) {
                        boolean addIt = true;
                        long date = item.getDate();
                        if (_stopDate != null) {
                            if (date < _stopDate.longValue()) {
                                addIt = false;
                                _stop = true;
                                break;
                            }
                        }
                        if (addIt) {
                            log.addLogItem(item);
                        }
                    }
                }
            }
        }
        ret = true;
    } catch (Exception e) {
        _logger.warn("Cannot parse character page [" + url + "]", e);
        ret = false;
    }
    return ret;
}
Also used : Element(net.htmlparser.jericho.Element) CharacterLogItem(delta.games.lotro.character.log.CharacterLogItem) DownloadService(delta.games.lotro.utils.DownloadService) Source(net.htmlparser.jericho.Source)

Example 7 with DownloadService

use of delta.games.lotro.utils.DownloadService in project lotro-tools by dmorcellet.

the class CharacterPageParser method parseMainPage.

/**
 * Parse the character page at the given URL.
 * @param name Toon name.
 * @param url URL of character page.
 * @param retryNumber Number of previous tries.
 * @return A character or <code>null</code> if an error occurred..
 */
private CharacterData parseMainPage(String name, String url, int retryNumber) {
    if (_logger.isInfoEnabled()) {
        _logger.info("Character description page parsing for toon [" + name + "] " + ((retryNumber > 0) ? " try #" + retryNumber : ""));
    }
    CharacterData ret = null;
    try {
        DownloadService downloader = DownloadService.getInstance();
        String page = downloader.getPage(url);
        Source source = new Source(page);
        _character = null;
        // <table class="char_panel freep">
        Element charPanel = JerichoHtmlUtils.findElementByTagNameAndAttributeValue(source, HTMLElementName.TABLE, "class", "char_panel freep");
        if (charPanel != null) {
            _character = new CharacterData();
            parseCharacterDescription(charPanel);
            parseStats(charPanel);
        }
        ret = _character;
        _character = null;
    } catch (Exception e) {
        if (_logger.isInfoEnabled()) {
            _logger.info("Cannot parse character page [" + url + "]", e);
        }
    }
    return ret;
}
Also used : CharacterData(delta.games.lotro.character.CharacterData) Element(net.htmlparser.jericho.Element) DownloadService(delta.games.lotro.utils.DownloadService) Source(net.htmlparser.jericho.Source)

Example 8 with DownloadService

use of delta.games.lotro.utils.DownloadService in project lotro-tools by dmorcellet.

the class DataLotroCharacterPageParser method parseMainPage.

/**
 * Parse the character page at the given URL.
 * @param name Toon name.
 * @param url URL of character page.
 * @param retryNumber Number of previous tries.
 * @return A character or <code>null</code> if an error occurred..
 */
private CharacterData parseMainPage(String name, String url, int retryNumber) {
    if (_logger.isInfoEnabled()) {
        _logger.info("Character description page parsing for toon [" + name + "] " + ((retryNumber > 0) ? " try #" + retryNumber : ""));
    }
    CharacterData ret = null;
    try {
        DownloadService downloader = DownloadService.getInstance();
        byte[] page = downloader.getBuffer(url);
        ret = parseCharacter(page);
    } catch (Exception e) {
        if (_logger.isInfoEnabled()) {
            _logger.info("Cannot parse character page [" + url + "]", e);
        }
    }
    return ret;
}
Also used : CharacterData(delta.games.lotro.character.CharacterData) DownloadService(delta.games.lotro.utils.DownloadService)

Example 9 with DownloadService

use of delta.games.lotro.utils.DownloadService in project lotro-tools by dmorcellet.

the class ItemPageParser method internalParseItemPage.

/**
 * Parse the item page at the given URL.
 * @param url URL of item page.
 * @return An item or <code>null</code> if an error occurred.
 */
private List<Item> internalParseItemPage(String url) {
    List<Item> items = null;
    try {
        DownloadService downloader = DownloadService.getInstance();
        String page = downloader.getPage(url);
        Source source = new Source(page);
        // <div id="lorebookNoedit">
        // Element lorebook=JerichoHtmlUtils.findElementByTagNameAndAttributeValue(source,HTMLElementName.DIV,"id","lorebookNoedit");
        // if (lorebook!=null)
        {
            items = new ArrayList<Item>();
            // Fetch identifier
            List<Element> itemSections = JerichoHtmlUtils.findElementsByTagNameAndAttributeValue(source, HTMLElementName.TABLE, "class", "tooltip");
            if ((itemSections != null) && (itemSections.size() > 0)) {
                String key = fetchItemKey(source);
                _key = key;
                for (Element itemSection : itemSections) {
                    Item item = parseItemSection(itemSection);
                    if (item != null) {
                        items.add(item);
                        item.setKey(key);
                    }
                }
                findIdentifiers(items);
            }
            List<Element> resourceSections = JerichoHtmlUtils.findElementsByTagNameAndAttributeValue(source, HTMLElementName.DIV, "class", "lorebookresource");
            if ((resourceSections != null) && (resourceSections.size() > 0)) {
                String key = fetchItemKey(source);
                _key = key;
                for (Element resourceSection : resourceSections) {
                    Item item = parseResourceSection(resourceSection);
                    if (item != null) {
                        items.add(item);
                        item.setKey(key);
                    }
                }
                findIdentifiers(items);
            }
        }
    } catch (Exception e) {
        items = null;
        _logger.error("Cannot parse item page [" + url + "]", e);
    }
    return items;
}
Also used : Item(delta.games.lotro.lore.items.Item) Element(net.htmlparser.jericho.Element) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) DownloadService(delta.games.lotro.utils.DownloadService) Source(net.htmlparser.jericho.Source) InputSource(org.xml.sax.InputSource)

Example 10 with DownloadService

use of delta.games.lotro.utils.DownloadService in project lotro-tools by dmorcellet.

the class RecipePageParser method parseRecipePage.

/**
 * Parse the recipe page at the given URL.
 * @param url URL of recipe page.
 * @return A list of recipes or <code>null</code> if an error occurred.
 */
public List<Recipe> parseRecipePage(String url) {
    List<Recipe> recipes = null;
    try {
        // url="http://lorebook.lotro.com/wiki/Recipe:Ancient_Steel_Scholar%27s_Glass";
        // url="http://lorebook.lotro.com/wiki/Recipe:Heavy_Cotton_Armour"; // Multiple output
        DownloadService downloader = DownloadService.getInstance();
        String page = downloader.getPage(url);
        // File f=new File("D:\\dam\\dev\\perso\\lotro\\docs\\recipes\\Glass.html");
        // File f=new File("D:\\dam\\dev\\perso\\lotro\\docs\\recipes\\Chisel.html");
        // String page=TextUtils.loadTextFile(f,EncodingNames.ISO8859_1);
        Source source = new Source(page);
        // <div id="lorebookNoedit">
        Element lorebook = JerichoHtmlUtils.findElementByTagNameAndAttributeValue(source, HTMLElementName.DIV, "id", "lorebookNoedit");
        if (lorebook != null) {
            // identifier
            // <a id="ca-nstab-recipe" class="lorebook_action_link" href="/wiki/Recipe:Sage%5C%27s_Sharp_Chisel">Article</a></div>
            _key = null;
            Element articleLink = JerichoHtmlUtils.findElementByTagNameAndAttributeValue(source, HTMLElementName.A, "id", "ca-nstab-recipe");
            if (articleLink != null) {
                String thisURL = articleLink.getAttributeValue("href");
                if ((thisURL != null) && (thisURL.startsWith(RECIPE_URL_SEED))) {
                    _key = thisURL.substring(RECIPE_URL_SEED.length()).trim();
                }
            }
            int tier = findTier(source);
            recipes = new ArrayList<Recipe>();
            List<Element> recipeSections = JerichoHtmlUtils.findElementsByTagNameAndAttributeValue(lorebook, HTMLElementName.DIV, "class", "lorebookclass");
            if ((recipeSections != null) && (recipeSections.size() > 0)) {
                for (Element recipeSection : recipeSections) {
                    Recipe recipe = parseRecipeSection(recipeSection);
                    if (recipe != null) {
                        recipes.add(recipe);
                        recipe.setKey(_key);
                        if (tier != 0) {
                            recipe.setTier(tier);
                        }
                    }
                }
            }
            findIdentifiers(recipes);
            for (Recipe recipe : recipes) {
                System.out.println("Recipe: ");
                System.out.println(recipe.dump());
            }
        }
    } catch (Exception e) {
        recipes = null;
        _logger.error("Cannot parse quest page [" + url + "]", e);
    }
    return recipes;
}
Also used : Recipe(delta.games.lotro.lore.crafting.recipes.Recipe) Element(net.htmlparser.jericho.Element) DownloadService(delta.games.lotro.utils.DownloadService) InputSource(org.xml.sax.InputSource) Source(net.htmlparser.jericho.Source)

Aggregations

DownloadService (delta.games.lotro.utils.DownloadService)13 Element (net.htmlparser.jericho.Element)11 Source (net.htmlparser.jericho.Source)11 InputSource (org.xml.sax.InputSource)6 CharacterData (delta.games.lotro.character.CharacterData)2 Item (delta.games.lotro.lore.items.Item)2 DownloadException (delta.downloads.DownloadException)1 CharacterLogItem (delta.games.lotro.character.log.CharacterLogItem)1 Recipe (delta.games.lotro.lore.crafting.recipes.Recipe)1 QuestDescription (delta.games.lotro.lore.quests.QuestDescription)1 Area (delta.games.lotro.lore.region.Area)1 Region (delta.games.lotro.lore.region.Region)1 File (java.io.File)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1