mirror of
https://github.com/Sheldan/abstracto.git
synced 2026-04-19 21:17:43 +00:00
[AB-89] adding command to retrieve weather data
This commit is contained in:
@@ -14,4 +14,11 @@
|
||||
<maven.compiler.target>8</maven.compiler.target>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.google.code.gson</groupId>
|
||||
<artifactId>gson</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
@@ -3,4 +3,5 @@ package dev.sheldan.abstracto.webservices.config;
|
||||
public class WebServicesSlashCommandNames {
|
||||
public static final String YOUTUBE = "youtube";
|
||||
public static final String URBAN = "urban";
|
||||
public static final String WEATHER = "weather";
|
||||
}
|
||||
|
||||
@@ -5,7 +5,10 @@ import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
public enum WebserviceFeatureDefinition implements FeatureDefinition {
|
||||
YOUTUBE("youtube"), URBAN_DICTIONARY("urban"), THREAD_READER("threadReader");
|
||||
YOUTUBE("youtube"),
|
||||
URBAN_DICTIONARY("urban"),
|
||||
THREAD_READER("threadReader"),
|
||||
OPEN_WEATHER_MAP("openWeatherMap");
|
||||
|
||||
private String key;
|
||||
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
package dev.sheldan.abstracto.webservices.openweathermap.config;
|
||||
|
||||
import dev.sheldan.abstracto.core.config.FeatureConfig;
|
||||
import dev.sheldan.abstracto.core.config.FeatureDefinition;
|
||||
import dev.sheldan.abstracto.webservices.config.WebserviceFeatureDefinition;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
@Component
|
||||
public class OpenWeatherMapConfig implements FeatureConfig {
|
||||
|
||||
public static final String OPEN_WEATHER_MAP_LANGUAGE_KEY_SYSTEM_CONFIG_KEY = "openWeatherMapLanguageKey";
|
||||
|
||||
@Override
|
||||
public FeatureDefinition getFeature() {
|
||||
return WebserviceFeatureDefinition.OPEN_WEATHER_MAP;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getRequiredSystemConfigKeys() {
|
||||
return Arrays.asList(OPEN_WEATHER_MAP_LANGUAGE_KEY_SYSTEM_CONFIG_KEY);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package dev.sheldan.abstracto.webservices.openweathermap.exception;
|
||||
|
||||
import dev.sheldan.abstracto.core.exception.AbstractoTemplatableException;
|
||||
|
||||
public class LocationNotFoundException extends AbstractoTemplatableException {
|
||||
@Override
|
||||
public String getTemplateName() {
|
||||
return "no_weather_location_found_exception";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getTemplateModel() {
|
||||
return new Object();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package dev.sheldan.abstracto.webservices.openweathermap.model;
|
||||
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
public class GeoCodingLocation {
|
||||
@SerializedName("name")
|
||||
private String name;
|
||||
@SerializedName("lat")
|
||||
private Double latitude;
|
||||
@SerializedName("lon")
|
||||
private Double longitude;
|
||||
@SerializedName("country")
|
||||
private String countryKey;
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package dev.sheldan.abstracto.webservices.openweathermap.model;
|
||||
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@Builder
|
||||
public class GeoCodingResult {
|
||||
private List<GeoCodingLocation> results;
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package dev.sheldan.abstracto.webservices.openweathermap.model;
|
||||
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.awt.*;
|
||||
import java.time.Instant;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@Builder
|
||||
public class WeatherResponseModel {
|
||||
private Float temperature;
|
||||
private Float minTemperature;
|
||||
private Float maxTemperature;
|
||||
private String mainWeather;
|
||||
private String description;
|
||||
private Float feelsLikeTemperature;
|
||||
private Integer humidity;
|
||||
private Integer pressure;
|
||||
private Integer seaLevelPressure;
|
||||
private Integer groundLevelPressure;
|
||||
private Float rain1H;
|
||||
private Float rain3H;
|
||||
private Float snow1H;
|
||||
private Float snow3H;
|
||||
private Integer clouds;
|
||||
private Instant sunrise;
|
||||
private Instant sunset;
|
||||
private Integer visibility;
|
||||
private Instant dataCalculationTime;
|
||||
private String locationName;
|
||||
private String countryKey;
|
||||
private Color embedColor;
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package dev.sheldan.abstracto.webservices.openweathermap.model;
|
||||
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
public class WeatherResult {
|
||||
@SerializedName("coord")
|
||||
private WeatherResultCoordinates coordinates;
|
||||
@SerializedName("weather")
|
||||
private List<WeatherResultWeatherDescription> weathers;
|
||||
@SerializedName("visibility")
|
||||
private Integer visibility;
|
||||
@SerializedName("main")
|
||||
private WeatherResultMain mainWeather;
|
||||
@SerializedName("rain")
|
||||
private WeatherResultRain rainInfo;
|
||||
@SerializedName("snow")
|
||||
private WeatherResultSnow snowInfo;
|
||||
@SerializedName("dt")
|
||||
private Long dayTime;
|
||||
@SerializedName("clouds")
|
||||
private WeatherResultClouds cloudInfo;
|
||||
@SerializedName("sys")
|
||||
private WeatherResultSystem systemInfo;
|
||||
@SerializedName("timezone")
|
||||
private Long timezoneShift;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package dev.sheldan.abstracto.webservices.openweathermap.model;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
public class WeatherResultClouds {
|
||||
private Integer all;
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package dev.sheldan.abstracto.webservices.openweathermap.model;
|
||||
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
public class WeatherResultCoordinates {
|
||||
@SerializedName("lon")
|
||||
private Float longitude;
|
||||
@SerializedName("lat")
|
||||
private Float latitude;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package dev.sheldan.abstracto.webservices.openweathermap.model;
|
||||
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
public class WeatherResultMain {
|
||||
@SerializedName("temp")
|
||||
private Float temperature;
|
||||
@SerializedName("feels_like")
|
||||
private Float feelsLikeTemperature;
|
||||
@SerializedName("temp_min")
|
||||
private Float minTemperature;
|
||||
@SerializedName("temp_max")
|
||||
private Float maxTemperature;
|
||||
@SerializedName("pressure")
|
||||
private Integer pressure;
|
||||
@SerializedName("humidity")
|
||||
private Integer humidity;
|
||||
@SerializedName("sea_level")
|
||||
private Integer seaLevelPressure;
|
||||
@SerializedName("grnd_level")
|
||||
private Integer groundLevelPressure;
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package dev.sheldan.abstracto.webservices.openweathermap.model;
|
||||
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
public class WeatherResultRain {
|
||||
@SerializedName("1h")
|
||||
private Float rain1H;
|
||||
|
||||
@SerializedName("3h")
|
||||
private Float rain3H;
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package dev.sheldan.abstracto.webservices.openweathermap.model;
|
||||
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
public class WeatherResultSnow {
|
||||
@SerializedName("1h")
|
||||
private Float snow1H;
|
||||
|
||||
@SerializedName("3h")
|
||||
private Float snow3H;
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package dev.sheldan.abstracto.webservices.openweathermap.model;
|
||||
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
public class WeatherResultSystem {
|
||||
@SerializedName("country")
|
||||
private String country;
|
||||
|
||||
@SerializedName("sunrise")
|
||||
private Long sunrise;
|
||||
|
||||
@SerializedName("sunset")
|
||||
private Long sunset;
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package dev.sheldan.abstracto.webservices.openweathermap.model;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
public class WeatherResultWeatherDescription {
|
||||
private Long id;
|
||||
private String main;
|
||||
private String description;
|
||||
private String icon;
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package dev.sheldan.abstracto.webservices.openweathermap.model;
|
||||
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
public class WeatherResultWind {
|
||||
@SerializedName("speed")
|
||||
private Float speed;
|
||||
@SerializedName("deg")
|
||||
private Integer degrees;
|
||||
@SerializedName("gust")
|
||||
private Float gust;
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package dev.sheldan.abstracto.webservices.openweathermap.service;
|
||||
|
||||
import dev.sheldan.abstracto.webservices.openweathermap.model.GeoCodingLocation;
|
||||
import dev.sheldan.abstracto.webservices.openweathermap.model.GeoCodingResult;
|
||||
import dev.sheldan.abstracto.webservices.openweathermap.model.WeatherResult;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public interface OpenWeatherMapService {
|
||||
GeoCodingResult searchForLocation(String query) throws IOException;
|
||||
WeatherResult retrieveWeatherForLocation(GeoCodingLocation geoCodingLocation, String languageKey) throws IOException;
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package dev.sheldan.abstracto.webservices.openweathermap.service;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
public interface WeatherService {
|
||||
Color getColorForTemperature(Float temperature);
|
||||
}
|
||||
Reference in New Issue
Block a user