2 * Copyright (c) 2010-2024 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 NapierCityCouncil} class contains the logic to get data the
24 * www.napier.govt.nz website.
28 * @author Stewart Cossey - Initial contribution
31 public class NapierCityCouncil implements WaterWebService {
32 private final Logger logger = LoggerFactory.getLogger(NapierCityCouncil.class);
34 private static final String HOSTNAME = "https://www.napier.govt.nz";
35 private static final String REGION_NAPIER = "/services/water/water-restrictions/";
37 private static final String PATTERN = "\"waterstat\".*?<p>.*?at (.*?) Restrictions.*?</div>";
38 private static final Pattern REGEX = Pattern.compile(PATTERN,
39 Pattern.CASE_INSENSITIVE | Pattern.MULTILINE | Pattern.DOTALL);
42 public String service() {
43 return "napiercitycouncil";
47 public String endpoint(final String region) {
48 switch (region.toLowerCase()) {
50 return HOSTNAME + REGION_NAPIER;
57 public int findWaterLevel(final String data, final String area) {
58 final Matcher matches = REGEX.matcher(data);
60 while (matches.find()) {
61 final String level = matches.group(1);
62 logger.debug("Data Level {}", level);
64 switch (level.toLowerCase()) {