|
| 1 | +/* |
| 2 | +
|
| 3 | + Copyright 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020, 2021, 2022, 2023, 2024 joshua.tee@gmail.com |
| 4 | +
|
| 5 | + This file is part of wX. |
| 6 | +
|
| 7 | + wX is free software: you can redistribute it and/or modify |
| 8 | + it under the terms of the GNU General Public License as published by |
| 9 | + the Free Software Foundation, either version 3 of the License, or |
| 10 | + (at your option) any later version. |
| 11 | +
|
| 12 | + wX is distributed in the hope that it will be useful, |
| 13 | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | + GNU General Public License for more details. |
| 16 | +
|
| 17 | + You should have received a copy of the GNU General Public License |
| 18 | + along with wX. If not, see <http://www.gnu.org/licenses/>. |
| 19 | +
|
| 20 | + */ |
| 21 | + |
| 22 | +package joshuatee.wx.util |
| 23 | + |
| 24 | +import joshuatee.wx.settings.Location |
| 25 | + |
| 26 | +object WeatherStory { |
| 27 | + |
| 28 | + fun getUrl(): String { |
| 29 | + var productUrl = "" |
| 30 | + val site = Location.wfo.lowercase() |
| 31 | + var url = "https://www.weather.gov/$site/weatherstory" |
| 32 | + val html = UtilityIO.getHtml(url) |
| 33 | + var scrapeUrl = UtilityString.parse( |
| 34 | + html, |
| 35 | + "src=.(https://www.weather.gov//images/.../wxstory/Tab.FileL.png). " |
| 36 | + ) |
| 37 | + if (scrapeUrl.isNotEmpty()) { |
| 38 | + productUrl = scrapeUrl |
| 39 | + } else { |
| 40 | + scrapeUrl = |
| 41 | + UtilityString.parse(html, "a href=.(/images/\\w{3}/features/weatherstory.png).") |
| 42 | + if (scrapeUrl.isNotEmpty()) { |
| 43 | + productUrl = "https://www.weather.gov/$scrapeUrl" |
| 44 | + } else { |
| 45 | + url = "https://weather.gov/$site" |
| 46 | + val html = UtilityIO.getHtml(url) |
| 47 | + // <div class="image"><img src="http://www.weather.gov/images//mob/graphicast/image8.png" style="max-width: 100%;"></div> |
| 48 | + // <div class="image"><img src="http://www.weather.gov/images/abq/graphicast/image1.gif" style="max-width: 100%;"></div> |
| 49 | + var scrapeUrls = UtilityString.parseColumn( |
| 50 | + html, |
| 51 | + "src=.(https?://www.weather.gov/images/?/.../graphicast/\\S*?[0-9].png). " |
| 52 | + ) |
| 53 | + if (scrapeUrls.isNotEmpty()) { |
| 54 | + productUrl = scrapeUrls[0] |
| 55 | + } else { |
| 56 | + scrapeUrls = UtilityString.parseColumn( |
| 57 | + html, |
| 58 | + "src=.(https?://www.weather.gov/images/?/.../graphicast/\\S*?[0-9].gif). " |
| 59 | + ) |
| 60 | + if (scrapeUrls.isNotEmpty()) { |
| 61 | + productUrl = scrapeUrls[0] |
| 62 | + } else { |
| 63 | + scrapeUrls = UtilityString.parseColumn( |
| 64 | + html, |
| 65 | + "src=.(https?://www.weather.gov/?/images/?/.../WxStory/\\S*?[0-9].png). " |
| 66 | + ) |
| 67 | + if (scrapeUrls.isNotEmpty()) { |
| 68 | + productUrl = scrapeUrls[0] |
| 69 | + } |
| 70 | + } |
| 71 | + } |
| 72 | + } |
| 73 | + } |
| 74 | + return productUrl |
| 75 | + } |
| 76 | +} |
0 commit comments