fix: Locale format
This commit is contained in:
parent
decbd83316
commit
70c573eb81
@ -6,6 +6,7 @@ import java.io.InputStreamReader;
|
|||||||
import java.net.HttpURLConnection;
|
import java.net.HttpURLConnection;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
import eirb.pg203.utils.JSONFetcher;
|
import eirb.pg203.utils.JSONFetcher;
|
||||||
import org.json.JSONArray;
|
import org.json.JSONArray;
|
||||||
@ -28,7 +29,7 @@ public class City {
|
|||||||
private static JSONObject getDataFromName(String cityName) throws IOException {
|
private static JSONObject getDataFromName(String cityName) throws IOException {
|
||||||
StringBuilder result = new StringBuilder();
|
StringBuilder result = new StringBuilder();
|
||||||
URL url = URI.create(
|
URL url = URI.create(
|
||||||
String.format("https://api-adresse.data.gouv.fr/search/?q=%s&autocomplete=0&limit=1",
|
String.format(Locale.ENGLISH, "https://api-adresse.data.gouv.fr/search/?q=%s&autocomplete=0&limit=1",
|
||||||
cityName
|
cityName
|
||||||
)
|
)
|
||||||
).toURL();
|
).toURL();
|
||||||
@ -79,7 +80,7 @@ public class City {
|
|||||||
public String toString() {
|
public String toString() {
|
||||||
try {
|
try {
|
||||||
Coords coords = this.getCityCoords();
|
Coords coords = this.getCityCoords();
|
||||||
return String.format(
|
return String.format(Locale.ENGLISH,
|
||||||
"City(%s, lat: %f, lon: %f)",
|
"City(%s, lat: %f, lon: %f)",
|
||||||
this.cityName,
|
this.cityName,
|
||||||
coords.getLat(),
|
coords.getLat(),
|
||||||
@ -87,7 +88,7 @@ public class City {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
catch (IOException e) {
|
catch (IOException e) {
|
||||||
return String.format(
|
return String.format(Locale.ENGLISH,
|
||||||
"City(%s, lat: Request failed, lon: Request Failed)",
|
"City(%s, lat: Request failed, lon: Request Failed)",
|
||||||
this.cityName
|
this.cityName
|
||||||
);
|
);
|
||||||
|
@ -10,6 +10,8 @@ import java.net.URI;
|
|||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
import eirb.pg203.WeatherData.Condition;
|
import eirb.pg203.WeatherData.Condition;
|
||||||
|
|
||||||
// https://api.open-meteo.com/v1/forecast?latitude=52.52&longitude=13.41&hourly=temperature_2m
|
// https://api.open-meteo.com/v1/forecast?latitude=52.52&longitude=13.41&hourly=temperature_2m
|
||||||
@ -30,15 +32,14 @@ public class OpenMeteo implements WeatherDataAPI {
|
|||||||
// https://www.nodc.noaa.gov/archive/arc0021/0002199/1.1/data/0-data/HTML/WMO-CODE/WMO4677.HTM
|
// https://www.nodc.noaa.gov/archive/arc0021/0002199/1.1/data/0-data/HTML/WMO-CODE/WMO4677.HTM
|
||||||
private JSONObject fetchWeather(int days, City city) throws IOException {
|
private JSONObject fetchWeather(int days, City city) throws IOException {
|
||||||
URL url = URI.create(
|
URL url = URI.create(
|
||||||
String.format(forecastBaseURL + "?latitude=%.2f&longitude=%.2f&forecast_days=%d&daily=" + dailyQuery,
|
String.format(Locale.ENGLISH, forecastBaseURL + "?latitude=%.2f&longitude=%.2f&forecast_days=%d&daily=" + dailyQuery,
|
||||||
city.getCityCoords().getLat(),
|
city.getCityCoords().getLat(),
|
||||||
city.getCityCoords().getLon(),
|
city.getCityCoords().getLon(),
|
||||||
days
|
days
|
||||||
)
|
)
|
||||||
).toURL();
|
).toURL();
|
||||||
|
|
||||||
JSONArray jsonArray = JSONFetcher.fetchArray(url);
|
return JSONFetcher.fetch(url);
|
||||||
return jsonArray.getJSONObject(0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Condition getConditionFromCode(int WMOCode) {
|
private static Condition getConditionFromCode(int WMOCode) {
|
||||||
|
@ -12,6 +12,8 @@ import java.time.DayOfWeek;
|
|||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
import java.time.ZoneId;
|
import java.time.ZoneId;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
import eirb.pg203.WeatherData.Condition;
|
import eirb.pg203.WeatherData.Condition;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -27,7 +29,7 @@ public class OpenWeatherMap implements WeatherDataAPI {
|
|||||||
|
|
||||||
private JSONObject fetchWeather(int days, City city) throws IOException {
|
private JSONObject fetchWeather(int days, City city) throws IOException {
|
||||||
URL url = URI.create(
|
URL url = URI.create(
|
||||||
String.format(forecastBaseURL + "?appid=%s&lat=%.2f&lon=%.2f&units=metric",
|
String.format(Locale.ENGLISH, forecastBaseURL + "?appid=%s&lat=%.2f&lon=%.2f&units=metric",
|
||||||
APIKey,
|
APIKey,
|
||||||
city.getCityCoords().getLat(),
|
city.getCityCoords().getLat(),
|
||||||
city.getCityCoords().getLon(),
|
city.getCityCoords().getLon(),
|
||||||
|
@ -11,6 +11,7 @@ import java.net.URI;
|
|||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* WeatherAPI implementation
|
* WeatherAPI implementation
|
||||||
@ -25,7 +26,7 @@ public class WeatherAPI implements WeatherDataAPI{
|
|||||||
|
|
||||||
private JSONObject fetchWeather(int days, String city) throws IOException {
|
private JSONObject fetchWeather(int days, String city) throws IOException {
|
||||||
URL url = URI.create(
|
URL url = URI.create(
|
||||||
String.format(forecastBaseURL + "?key=%s&q=%s&days=%d",
|
String.format(Locale.ENGLISH, forecastBaseURL + "?key=%s&q=%s&days=%d",
|
||||||
this.weatherAPIKey,
|
this.weatherAPIKey,
|
||||||
city,
|
city,
|
||||||
days
|
days
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package eirb.pg203;
|
package eirb.pg203;
|
||||||
|
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
|
import java.util.Locale;
|
||||||
import java.util.concurrent.locks.Condition;
|
import java.util.concurrent.locks.Condition;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -249,7 +250,7 @@ public class WeatherData {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return String.format("%05.2f° %s %05.2fkm/h %06.2f° %s",
|
return String.format(Locale.ENGLISH, "%05.2f° %s %05.2fkm/h %06.2f° %s",
|
||||||
this.getTemp(),
|
this.getTemp(),
|
||||||
this.getCondition().toString(),
|
this.getCondition().toString(),
|
||||||
this.getWindSpeed(),
|
this.getWindSpeed(),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user