aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSamuel Tardieu <sam@rfc1149.net>2013-05-19 19:15:05 +0200
committerSamuel Tardieu <sam@rfc1149.net>2013-05-19 19:34:21 +0200
commitf47e3312c35627569d50b34a2282a54915c759c9 (patch)
tree07b56d7c2ddb084e76d8f1497d5feee07b5a88d6
parenta09d414466028179ac4c7737dd0336a6d38bc00d (diff)
downloadcgeo-f47e3312c35627569d50b34a2282a54915c759c9.zip
cgeo-f47e3312c35627569d50b34a2282a54915c759c9.tar.gz
cgeo-f47e3312c35627569d50b34a2282a54915c759c9.tar.bz2
fix: parse basic member difficulty and terrain
Part of work on #2733.
-rw-r--r--main/src/cgeo/geocaching/connector/gc/GCConstants.java1
-rw-r--r--main/src/cgeo/geocaching/connector/gc/GCParser.java18
2 files changed, 19 insertions, 0 deletions
diff --git a/main/src/cgeo/geocaching/connector/gc/GCConstants.java b/main/src/cgeo/geocaching/connector/gc/GCConstants.java
index c916071..00b773a 100644
--- a/main/src/cgeo/geocaching/connector/gc/GCConstants.java
+++ b/main/src/cgeo/geocaching/connector/gc/GCConstants.java
@@ -118,6 +118,7 @@ public final class GCConstants {
/** Second group used */
public final static Pattern PATTERN_SEARCH_TRACKABLESINSIDE = Pattern.compile("(<img src=\"[^\"]+\" alt=\"([^\"]+)\" title=\"[^\"]*\" />[^<]*)");
public final static Pattern PATTERN_SEARCH_DIRECTION_DISTANCE = Pattern.compile("<img src=\"/images/icons/compass/([^\\.]+)\\.gif\"[^>]*>[^<]*<br />([^<]+)</span>");
+ public final static Pattern PATTERN_SEARCH_DIFFICULTY_TERRAIN = Pattern.compile("<span class=\"small\">([0-5]([\\.,]5)?)/([0-5]([\\.,]5)?)</span><br />");
public final static Pattern PATTERN_SEARCH_GEOCODE = Pattern.compile("\\|\\W*(GC[0-9A-Z]+)[^\\|]*\\|");
public final static Pattern PATTERN_SEARCH_ID = Pattern.compile("name=\"CID\"[^v]*value=\"([0-9]+)\"");
public final static Pattern PATTERN_SEARCH_FAVORITE = Pattern.compile("<span id=\"ctl00_ContentBody_dlResults_ctl[0-9]+_uxFavoritesValue\" title=\"[^\"]*\" class=\"favorite-rank\">([0-9]+)</span>");
diff --git a/main/src/cgeo/geocaching/connector/gc/GCParser.java b/main/src/cgeo/geocaching/connector/gc/GCParser.java
index b4d665b..54bd19d 100644
--- a/main/src/cgeo/geocaching/connector/gc/GCParser.java
+++ b/main/src/cgeo/geocaching/connector/gc/GCParser.java
@@ -176,6 +176,19 @@ public abstract class GCParser {
}
}
+ // difficulty/terrain
+ final MatcherWrapper matcherDT = new MatcherWrapper(GCConstants.PATTERN_SEARCH_DIFFICULTY_TERRAIN, row);
+ if (matcherDT.find()) {
+ final Float difficulty = parseStars(matcherDT.group(1));
+ if (difficulty != null) {
+ cache.setDifficulty(difficulty);
+ }
+ final Float terrain = parseStars(matcherDT.group(3));
+ if (terrain != null) {
+ cache.setTerrain(terrain);
+ }
+ }
+
// cache inventory
final MatcherWrapper matcherTbs = new MatcherWrapper(GCConstants.PATTERN_SEARCH_TRACKABLES, row);
String inventoryPre = null;
@@ -306,6 +319,11 @@ public abstract class GCParser {
return searchResult;
}
+ private static Float parseStars(final String value) {
+ float floatValue = Float.parseFloat(StringUtils.replaceChars(value, ',', '.'));
+ return floatValue >= 0.5 && floatValue <= 5.0 ? floatValue : null;
+ }
+
static SearchResult parseCache(final String page, final CancellableHandler handler) {
final SearchResult searchResult = parseCacheFromText(page, handler);
if (searchResult != null && !searchResult.getGeocodes().isEmpty()) {