Search in sources :

Example 11 with DownloadService

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

the class RecipePageParser method findIdentifiers.

private void findIdentifiers(List<Recipe> recipes) {
    String url = "http://lorebook.lotro.com/index.php?title=Recipe:" + _key + "&action=edit";
    DownloadService downloader = DownloadService.getInstance();
    try {
        String page = downloader.getPage(url);
        Source s = new Source(page);
        // <textarea id="wpTextbox1"
        Element pageSource = JerichoHtmlUtils.findElementByTagNameAndAttributeValue(s, HTMLElementName.TEXTAREA, "id", "wpTextbox1");
        if (pageSource != null) {
            String text = JerichoHtmlUtils.getTextFromTag(pageSource);
            parsePageSource(text, recipes);
        } else {
            _logger.warn("Cannot find identifiers!");
        }
    } catch (Exception e) {
        _logger.error("Parsing error", e);
    }
}
Also used : Element(net.htmlparser.jericho.Element) DownloadService(delta.games.lotro.utils.DownloadService) InputSource(org.xml.sax.InputSource) Source(net.htmlparser.jericho.Source)

Example 12 with DownloadService

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

the class QuestPageParser method findIdentifiers.

private void findIdentifiers(List<QuestDescription> quests) {
    String url = "http://lorebook.lotro.com/index.php?title=Quest:" + _key + "&action=edit";
    DownloadService downloader = DownloadService.getInstance();
    try {
        String page = downloader.getPage(url);
        Source s = new Source(page);
        // <textarea id="wpTextbox1"
        Element pageSource = JerichoHtmlUtils.findElementByTagNameAndAttributeValue(s, HTMLElementName.TEXTAREA, "id", "wpTextbox1");
        String text = JerichoHtmlUtils.getTextFromTag(pageSource);
        parsePageSource(text, quests);
    } catch (Exception e) {
        _logger.error("Parsing error", e);
    }
}
Also used : Element(net.htmlparser.jericho.Element) DownloadService(delta.games.lotro.utils.DownloadService) InputSource(org.xml.sax.InputSource) Source(net.htmlparser.jericho.Source)

Example 13 with DownloadService

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

the class ItemIconsDownloader method doIt.

private void doIt() {
    DownloadService downloader = DownloadService.getInstance();
    File toFile = new File("items.xml").getAbsoluteFile();
    _toDir.mkdirs();
    HashMap<Integer, Item> items = loadItemsFile(toFile);
    System.out.println(items.size());
    for (Integer id : items.keySet()) {
        System.out.println(id);
        String url = "http://lotro.fr/img/bdd/items/" + id + ".png";
        File to = new File(_toDir, id + ".png");
        try {
            downloader.downloadToFile(url, to);
        } catch (DownloadException de) {
            _logger.error("Cannot fetch icon [" + url + "]!", de);
        }
    }
}
Also used : Item(delta.games.lotro.lore.items.Item) DownloadException(delta.downloads.DownloadException) File(java.io.File) DownloadService(delta.games.lotro.utils.DownloadService)

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