Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*Call the OpenWeatherMap API
- Get the Json Data Of Corresponding City
- Search by City_ID
- */
- public void parser2() throws IOException, ParseException {
- String default1 = "http://api.openweathermap.org/data/2.5/forecast/daily?id=";
- String default2 = "&units=metric&cnt=7&APPID=a19e9f99d3ad3e8fe4a0c84367193dda";
- int cityID;
- String s21 = Scene1Controller.getInstance().cityY.toLowerCase();
- cityID = weather.app.WeatherApp.myMap.get(s21);
- System.out.println(" paisi -> " + cityID);
- List = "";
- hoise = false;
- URL Open_Weather = new URL(default1 + cityID + default2);
- URLConnection yc = Open_Weather.openConnection();
- try (BufferedReader in = new BufferedReader(
- new InputStreamReader(
- yc.getInputStream()))) {
- String inputLine;
- while ((inputLine = in.readLine()) != null) {
- List += inputLine;
- //System.out.println(inputLine);
- }
- } catch (IOException e) {
- hoise = true;
- Alert alert = new Alert(Alert.AlertType.ERROR);
- alert.setTitle("Error Dialog");
- alert.setHeaderText("NO INTERNET CONNECTION");
- alert.setContentText("Ooops, there was an error!");
- alert.showAndWait();
- }
- current_date = new Date();
- JSONObject tt = new JSONObject(List);
- try {
- JSONObject pp = tt.getJSONObject("city");
- s2 = pp.getString("name");
- countryY = pp.getString("country");
- JSONArray ar = tt.getJSONArray("list");
- tempP[0] = ar.getJSONObject(0).getJSONObject("temp").getDouble("day");
- temp_max[0] = ar.getJSONObject(0).getJSONObject("temp").getDouble("max");
- temp_min[0] = ar.getJSONObject(0).getJSONObject("temp").getDouble("min");
- press[0] = ar.getJSONObject(0).getDouble("pressure");
- hum[0] = ar.getJSONObject(0).getDouble("humidity");
- des1[0] = ar.getJSONObject(0).getJSONArray("weather").getJSONObject(0).getString("description");
- weather_icon[0] = ar.getJSONObject(0).getJSONArray("weather").getJSONObject(0).getString("icon");
- clouds[0] = ar.getJSONObject(0).getDouble("clouds");
- WS[0] = ar.getJSONObject(0).getDouble("speed");
- WD1[0] = ar.getJSONObject(0).getDouble("deg");
- WD[0] = dir(0);
- int ii;
- for (ii = 1; ii <= 6; ii++) {
- pp = tt.getJSONObject("city");
- s2 = pp.getString("name");
- countryY = pp.getString("country");
- ar = tt.getJSONArray("list");
- tempP[ii] = ar.getJSONObject(ii).getJSONObject("temp").getDouble("day");
- temp_max[ii] = ar.getJSONObject(ii).getJSONObject("temp").getDouble("max");
- temp_min[ii] = ar.getJSONObject(ii).getJSONObject("temp").getDouble("min");
- press[ii] = ar.getJSONObject(ii).getDouble("pressure");
- hum[ii] = ar.getJSONObject(ii).getDouble("humidity");
- des1[ii] = ar.getJSONObject(ii).getJSONArray("weather").getJSONObject(0).getString("description");
- weather_icon[ii] = ar.getJSONObject(ii).getJSONArray("weather").getJSONObject(0).getString("icon");
- clouds[ii] = ar.getJSONObject(ii).getDouble("clouds");
- WS[ii] = ar.getJSONObject(ii).getDouble("speed");
- WD1[ii] = ar.getJSONObject(ii).getDouble("deg");
- WD[ii] = dir(ii);
- }
- } catch (JSONException e) {
- System.out.println("JSON e somossha");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement