fork download
  1. public void doParseWeather(int timeTester) {
  2. if (this.weatherTries != 0 || this.weatherTries != 1 || this.weatherTries != 2 || this.weatherTries != 3 || this.weatherTries != 4) {
  3. this.weatherTries = 0;
  4. }
  5.  
  6. String result = "";
  7. getOverrides();
  8. try {
  9. if (timeTester >= 5) {
  10. DefaultHttpClient httpclient = new DefaultHttpClient();
  11.  
  12. HttpGet get = new HttpGet("http://a...content-available-to-author-only...d.com/api/Key Here/conditions/q/" + getZIP() + ".xml"); // Pulls zip from child object
  13.  
  14. HttpResponse response = httpclient.execute(get);
  15. //System.out.println("Http Status Code: " + response.getStatusLine().getStatusCode()); //HTTP status returned off request
  16. InputStream in = response.getEntity().getContent();
  17.  
  18. // Create an XML reader
  19. DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance();
  20. DocumentBuilder builder = domFactory.newDocumentBuilder();
  21. Document doc = builder.parse(in);
  22.  
  23. //Parse the Xml.
  24. XPathFactory factory = XPathFactory.newInstance();
  25. XPath xpath = factory.newXPath();
  26. XPathExpression expr = xpath.compile("//response/current_observation/display_location/full/text()");
  27.  
  28. result = (String) expr.evaluate(doc, XPathConstants.STRING);
  29. setWeatherZoneName(result);
  30.  
  31. expr = xpath.compile("//response/current_observation/temp_f/text()");
  32.  
  33. result = (String) expr.evaluate(doc, XPathConstants.STRING);
  34. setTemp(Double.parseDouble(result));
  35.  
  36. expr = xpath.compile("//response/current_observation/relative_humidity/text()");
  37.  
  38. result = (String) expr.evaluate(doc, XPathConstants.STRING);
  39. result = handleHumidity(result);
  40. setHumidity(Double.parseDouble(result));
  41.  
  42. expr = xpath.compile("//response/current_observation/weather/text()");
  43.  
  44. result = (String) expr.evaluate(doc, XPathConstants.STRING);
  45. setCurrentConditions(result);
  46. precipCheck(result);
  47.  
  48. expr = xpath.compile("//response/current_observation/dewpoint_f/text()");
  49.  
  50. result = (String) expr.evaluate(doc, XPathConstants.STRING);
  51. setDewpoint(Double.parseDouble(result));
  52.  
  53. dayAhead();
  54. DateTime now = DateTime.now(TimeZone.getTimeZone("UTC"));
  55. setwTimeStamp(now);
  56. didWeather = true;
  57. } else {
  58. didWeather = false;
  59. }
  60.  
  61.  
  62. } catch (Exception e) {
  63. System.err.println("Weather " + getZIP() + " :" + e.getMessage());
  64. e.printStackTrace();
  65. if (this.weatherTries < 3) {
  66. this.weatherTries++;
  67. try {
  68. Thread.sleep(1000);
  69. doParseWeather(currentTime);
  70. } catch (Exception f) {
  71. System.err.println("Thread Error: " + getPID() + " - " + f.getMessage());
  72. }
  73. }
  74. }
  75. }
Not running #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout
Standard output is empty