2 * Copyright (c) 2010-2023 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
7 * This program and the accompanying materials are made available under the
8 * terms of the Eclipse Public License 2.0 which is available at
9 * http://www.eclipse.org/legal/epl-2.0
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.nzwateralerts.internal.api;
15 import java.util.regex.Matcher;
16 import java.util.regex.Pattern;
18 import org.eclipse.jdt.annotation.NonNullByDefault;
19 import org.slf4j.Logger;
20 import org.slf4j.LoggerFactory;
23 * The {@link TaupoDistrictCouncil} class contains the logic to get data the
24 * www.taupodc.govt.nz website.
26 * Taupo District Council
28 * NOTE: This is currently a placeholder. This region needs to go into restrictions
29 * first so I can parse the correct output. -Stewart Cossey
31 * @author Stewart Cossey - Initial contribution
34 public class TaupoDistrictCouncil implements WaterWebService {
35 private final Logger logger = LoggerFactory.getLogger(TaupoDistrictCouncil.class);
37 private static final String HOSTNAME = "https://www.taupodc.govt.nz";
38 private static final String REGION_TAUPO = "/transport-and-water/water-conservation";
40 private static final String PATTERN = "div class=\"rc\".*?<tbody>.*?<strong>.*?<strong>(.*?) restrictions</strong>";
41 private static final Pattern REGEX = Pattern.compile(PATTERN,
42 Pattern.CASE_INSENSITIVE | Pattern.MULTILINE | Pattern.DOTALL);
45 public String service() {
46 return "taupodistrictcouncil";
50 public String endpoint(final String region) {
51 switch (region.toLowerCase()) {
53 return HOSTNAME + REGION_TAUPO;
60 public int findWaterLevel(final String data, final String area) {
61 final Matcher matches = REGEX.matcher(data);
63 while (matches.find()) {
64 final String level = matches.group(1);
65 logger.debug("Data Level {}", level);
67 switch (level.toLowerCase()) {