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;
}
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;
}
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;
}
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;
}
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;
}
Aggregations