Search in sources :

Example 1 with Downloader

use of delta.downloads.Downloader in project lotro-tools by dmorcellet.

the class RecipesIndexJSONParser method parseRecipesIndex.

/**
 * Get recipes index from web.
 * @return A recipes index or <code>null</code> if a problem occurs.
 */
public RecipesIndex parseRecipesIndex() {
    RecipesIndex ret;
    try {
        _index = new RecipesIndex();
        Downloader d = new Downloader();
        while ((_total == 0) || (_currentItemIndex < _total)) {
            load(d, _currentItemIndex);
        }
        ret = _index;
        _index = null;
    } catch (Exception e) {
        ret = null;
    }
    return ret;
}
Also used : RecipesIndex(delta.games.lotro.lore.crafting.recipes.index.RecipesIndex) Downloader(delta.downloads.Downloader)

Example 2 with Downloader

use of delta.downloads.Downloader in project lotro-tools by dmorcellet.

the class MainLoadStats method doItForOneMonthMax.

private Results doItForOneMonthMax(Date start, Date end, String file) {
    Results results = new Results();
    String url = buildURL("lotrocompanion", file, start, end);
    // System.out.println("URL: "+url);
    Downloader d = new Downloader();
    String s = null;
    try {
        s = d.downloadString(url);
        JSONObject o = new JSONObject(s);
        // OSes
        {
            JSONArray oses = o.getJSONArray("oses");
            int nbOses = oses.length();
            for (int i = 0; i < nbOses; i++) {
                JSONArray oneOS = (JSONArray) oses.get(i);
                String osName = (String) oneOS.get(0);
                Integer osNumber = (Integer) oneOS.get(1);
                results.addForOS(osName, osNumber.intValue());
            }
        }
        // Countries
        {
            JSONArray countries = o.getJSONArray("countries");
            int nbCountries = countries.length();
            for (int i = 0; i < nbCountries; i++) {
                JSONArray oneOS = (JSONArray) countries.get(i);
                String countryName = (String) oneOS.get(0);
                Integer number = (Integer) oneOS.get(1);
                results.addForCountry(countryName, number.intValue());
            }
        }
    } catch (Exception e) {
        System.out.println("Got exception. JSON was [" + s + "]");
        e.printStackTrace();
    }
    // System.out.println("Results: "+results);
    return results;
}
Also used : JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) Downloader(delta.downloads.Downloader)

Example 3 with Downloader

use of delta.downloads.Downloader in project lotro-tools by dmorcellet.

the class QuestsIndexJSONParser method parseQuestsIndex.

/**
 * Get quests index from web.
 * @return A quests index or <code>null</code> if a problem occurs.
 */
public QuestsIndex parseQuestsIndex() {
    QuestsIndex ret;
    try {
        _index = new QuestsIndex();
        Downloader d = new Downloader();
        while ((_total == 0) || (_currentItemIndex < _total)) {
            load(d, _currentItemIndex);
        }
        ret = _index;
        _index = null;
    } catch (Exception e) {
        ret = null;
    }
    return ret;
}
Also used : Downloader(delta.downloads.Downloader) QuestsIndex(delta.games.lotro.lore.quests.index.QuestsIndex)

Example 4 with Downloader

use of delta.downloads.Downloader in project lotro-tools by dmorcellet.

the class MainTestDownloadQuestPage method main.

/**
 * Main method.
 * @param args Not used.
 */
public static void main(String[] args) {
    String url = "http://lorebook.lotro.com/wiki/Special:LotroResource?id=1879210718";
    Downloader d = new Downloader();
    File tmpDir = FileSystem.getTmpDir();
    File tmp = new File(tmpDir, "tmp.html");
    try {
        d.downloadToFile(url, tmp);
    } catch (DownloadException de) {
        _logger.error("Cannot download quest page!", de);
    }
}
Also used : DownloadException(delta.downloads.DownloadException) Downloader(delta.downloads.Downloader) File(java.io.File)

Aggregations

Downloader (delta.downloads.Downloader)4 DownloadException (delta.downloads.DownloadException)1 RecipesIndex (delta.games.lotro.lore.crafting.recipes.index.RecipesIndex)1 QuestsIndex (delta.games.lotro.lore.quests.index.QuestsIndex)1 File (java.io.File)1 JSONArray (org.json.JSONArray)1 JSONObject (org.json.JSONObject)1