Advertisement
Guest User

Untitled

a guest
Jan 21st, 2018
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.72 KB | None | 0 0
  1. /*Call the OpenWeatherMap API
  2. Get the Json Data Of Corresponding City
  3. Search by City_ID
  4. */
  5. public void parser2() throws IOException, ParseException {
  6. String default1 = "http://api.openweathermap.org/data/2.5/forecast/daily?id=";
  7. String default2 = "&units=metric&cnt=7&APPID=a19e9f99d3ad3e8fe4a0c84367193dda";
  8. int cityID;
  9. String s21 = Scene1Controller.getInstance().cityY.toLowerCase();
  10. cityID = weather.app.WeatherApp.myMap.get(s21);
  11. System.out.println(" paisi -> " + cityID);
  12. List = "";
  13. hoise = false;
  14. URL Open_Weather = new URL(default1 + cityID + default2);
  15. URLConnection yc = Open_Weather.openConnection();
  16. try (BufferedReader in = new BufferedReader(
  17. new InputStreamReader(
  18. yc.getInputStream()))) {
  19. String inputLine;
  20.  
  21. while ((inputLine = in.readLine()) != null) {
  22. List += inputLine;
  23. //System.out.println(inputLine);
  24. }
  25. } catch (IOException e) {
  26. hoise = true;
  27. Alert alert = new Alert(Alert.AlertType.ERROR);
  28. alert.setTitle("Error Dialog");
  29. alert.setHeaderText("NO INTERNET CONNECTION");
  30. alert.setContentText("Ooops, there was an error!");
  31.  
  32. alert.showAndWait();
  33. }
  34.  
  35. current_date = new Date();
  36. JSONObject tt = new JSONObject(List);
  37.  
  38. try {
  39. JSONObject pp = tt.getJSONObject("city");
  40. s2 = pp.getString("name");
  41. countryY = pp.getString("country");
  42. JSONArray ar = tt.getJSONArray("list");
  43. tempP[0] = ar.getJSONObject(0).getJSONObject("temp").getDouble("day");
  44. temp_max[0] = ar.getJSONObject(0).getJSONObject("temp").getDouble("max");
  45. temp_min[0] = ar.getJSONObject(0).getJSONObject("temp").getDouble("min");
  46. press[0] = ar.getJSONObject(0).getDouble("pressure");
  47. hum[0] = ar.getJSONObject(0).getDouble("humidity");
  48. des1[0] = ar.getJSONObject(0).getJSONArray("weather").getJSONObject(0).getString("description");
  49. weather_icon[0] = ar.getJSONObject(0).getJSONArray("weather").getJSONObject(0).getString("icon");
  50. clouds[0] = ar.getJSONObject(0).getDouble("clouds");
  51. WS[0] = ar.getJSONObject(0).getDouble("speed");
  52. WD1[0] = ar.getJSONObject(0).getDouble("deg");
  53. WD[0] = dir(0);
  54. int ii;
  55. for (ii = 1; ii <= 6; ii++) {
  56. pp = tt.getJSONObject("city");
  57. s2 = pp.getString("name");
  58. countryY = pp.getString("country");
  59. ar = tt.getJSONArray("list");
  60. tempP[ii] = ar.getJSONObject(ii).getJSONObject("temp").getDouble("day");
  61. temp_max[ii] = ar.getJSONObject(ii).getJSONObject("temp").getDouble("max");
  62. temp_min[ii] = ar.getJSONObject(ii).getJSONObject("temp").getDouble("min");
  63. press[ii] = ar.getJSONObject(ii).getDouble("pressure");
  64. hum[ii] = ar.getJSONObject(ii).getDouble("humidity");
  65. des1[ii] = ar.getJSONObject(ii).getJSONArray("weather").getJSONObject(0).getString("description");
  66. weather_icon[ii] = ar.getJSONObject(ii).getJSONArray("weather").getJSONObject(0).getString("icon");
  67. clouds[ii] = ar.getJSONObject(ii).getDouble("clouds");
  68. WS[ii] = ar.getJSONObject(ii).getDouble("speed");
  69. WD1[ii] = ar.getJSONObject(ii).getDouble("deg");
  70. WD[ii] = dir(ii);
  71. }
  72. } catch (JSONException e) {
  73. System.out.println("JSON e somossha");
  74. }
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement