Skip to content

Commit

Permalink
More localised forecasts
Browse files Browse the repository at this point in the history
  • Loading branch information
evilbunny2008 committed Apr 20, 2021
1 parent 7d82c2b commit c9b3a1a
Show file tree
Hide file tree
Showing 10 changed files with 155 additions and 8 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ android {
minSdkVersion 19
//noinspection OldTargetApi
targetSdkVersion 29
versionCode 9005
versionName "0.9.5"
versionCode 9006
versionName "0.9.6"
}
buildTypes {
release {
Expand Down
111 changes: 110 additions & 1 deletion app/src/main/java/com/odiousapps/weewxweather/Common.java
Original file line number Diff line number Diff line change
Expand Up @@ -1707,6 +1707,89 @@ String[] processILMETEO(String data, boolean showHeader)
return new String[]{generateForecast(days, timestamp, showHeader), desc};
}

String[] processTempoItalia(String data)
{
return processTempoItalia(data, false);
}

String[] processTempoItalia(String data, boolean showHeader)
{
if (data == null || data.equals(""))
return null;

boolean metric = GetBoolPref("metric", true);
boolean use_icons = GetBoolPref("use_icons", false);
List<Day> days = new ArrayList<>();
String desc = "";
long timestamp, lastTS;

try
{
String stuff = data.split("<div id=\"weatherDayNavigator\">", 2)[1].trim();
stuff = stuff.split("<h2>", 2)[1].trim();
desc = stuff.split(" <span class=\"day\">")[0].trim();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm", Locale.getDefault());
String ftime = sdf.format(System.currentTimeMillis());
sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm", Locale.getDefault());
lastTS = timestamp = sdf.parse(ftime).getTime();

data = data.split("<tbody>")[1].trim();
String[] bits = data.split("<tr>");
for(int i = 1; i < bits.length; i++)
{
Day day = new Day();
String bit = bits[i].trim();
String icon;
day.day = bit.split("<td class=\"timeweek\">")[1].split("\">")[1].split("</a></td>", 2)[0].trim();

day.timestamp = convertDaytoTS(day.day, new Locale("it", "IT"), lastTS);
if(day.timestamp != 0)
{
sdf = new SimpleDateFormat("EEE dd", Locale.getDefault());
day.day = sdf.format(day.timestamp) + " " + day.day.substring(day.day.lastIndexOf(" ") + 1);
}

icon = bit.split("<td class=\"skyIcon\"><img src=\"", 2)[1].split("\" alt=\"",2)[0].trim();
String[] ret = checkFilesIt(icon);
if(ret[0] != null)
day.icon = "file://" + ret[1];
else
return ret;
LogMessage("day.icon=" + day.icon);

day.max = bit.split("<td class=\"tempmax\">", 2)[1].split("°C</td>", 2)[0].trim();
day.min = bit.split("<td class=\"tempmin\">", 2)[1].split("°C</td>", 2)[0].trim();

day.text = bit.split("<td class=\"skyDesc\">")[1].split("</td>")[0].trim();

if(use_icons)
{
String fileName = day.icon;
LogMessage("day.icon=" + day.icon);
} else {
day.icon = "wi wi-tempoitalia-" + icon;
}

if(metric)
{
day.max += "&deg;C";
day.min += "&deg;C";
} else {
day.max = round((Double.parseDouble(day.max) * 9.0 / 5.0) + 32.0) + "&deg;F";
day.min = round((Double.parseDouble(day.min) * 9.0 / 5.0) + 32.0) + "&deg;F";
}

days.add(day);
lastTS = day.timestamp;
}
} catch (Exception e) {
e.printStackTrace();
return null;
}

return new String[]{generateForecast(days, timestamp, showHeader), desc};
}

String[] processAEMET(String data)
{
return processAEMET(data, false);
Expand Down Expand Up @@ -2312,7 +2395,33 @@ private String[] checkFiles(String url) throws Exception
LogMessage("File not found: " + "yahoo-" + filename);
LogMessage("downloading...");

String new_url = "http://delungra.com/weewx/yahoo-missing.php?filename=" + filename;
String new_url = "https://delungra.com/weewx/yahoo-missing.php?filename=" + filename;
f = downloadBinary(f, new_url);
if(f == null)
return new String[]{null, "f is invalid."};

if(f.exists())
return new String[]{"", f.getAbsolutePath()};
} else {
LogMessage(filename);
return new String[]{"", f.getAbsolutePath()};
}

return new String[]{null, "Failed to load or download icon: " + filename};
}

private String[] checkFilesIt(String url) throws Exception
{
String filename = "tempoitalia-" + new File(url).getName();
File f = new File(context.getExternalFilesDir(""), "weeWX");
f = new File(f,"icons");
f = new File(f, filename);
if(!f.exists())
{
LogMessage("File not found: " + "tempoitalia-" + filename);
LogMessage("downloading...");

String new_url = "https://delungra.com/weewx/TempoItalia-missing.php?filename=" + filename;
f = downloadBinary(f, new_url);
if(f == null)
return new String[]{null, "f is invalid."};
Expand Down
10 changes: 10 additions & 0 deletions app/src/main/java/com/odiousapps/weewxweather/Forecast.java
Original file line number Diff line number Diff line change
Expand Up @@ -677,6 +677,13 @@ public void run()
updateForecast(content[0], content[1]);
break;
}
case "tempoitalia.it":
{
String[] content = common.processTempoItalia(data, true);
if(content != null && content.length >= 2)
updateForecast(content[0], content[1]);
break;
}
}

mHandler.post(new Runnable()
Expand Down Expand Up @@ -822,6 +829,9 @@ public void run()
case "ilmeteo.it":
im.setImageResource(R.drawable.ilmeteo_it);
break;
case "tempoitalia.it":
im.setImageResource(R.drawable.tempoitalia_it);
break;
}
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -728,6 +728,10 @@ public void run()
Common.LogMessage("forecast=" + forecast);
Common.LogMessage("fctype=" + fctype);
break;
case "tempoitalia.it":
Common.LogMessage("forecast=" + forecast);
Common.LogMessage("fctype=" + fctype);
break;
default:
common.SetStringPref("lastError", "forecast type " + fctype + " is invalid, check your settings file and try again.");
handlerForecast.sendEmptyMessage(0);
Expand Down
10 changes: 5 additions & 5 deletions app/src/main/java/com/odiousapps/weewxweather/Stats.java
Original file line number Diff line number Diff line change
Expand Up @@ -374,13 +374,13 @@ public void run()
}

String rain = bits[20];
String since = "since mn";
String since = common.context.getString(R.string.since) + " mn";

if (bits.length > 160 && !bits[160].equals(""))
rain = bits[158];

if (bits.length > 160 && !bits[158].equals("") && !bits[160].equals(""))
since = "since " + bits[160];
since = common.context.getString(R.string.since) + " " + bits[160];

stmp = "<tr><td><i style='font-size:" + iw + "px;' class='flaticon-windy'></i></td><td colspan='3'>" + bits[19] + bits[61] + " " + bits[32] + " " + convert(bits[33]) +
"</td><td>" + rain + bits[62] + "</td><td><i style='font-size:" + iw + "px;' class='wi wi-umbrella'></i></td></tr>";
Expand Down Expand Up @@ -434,7 +434,7 @@ public void run()
}

rain = bits[21];
since = "before mn";
String before = common.context.getString(R.string.before) + " mn";

if (bits.length > 160 && !bits[159].equals(""))
rain = bits[159];
Expand All @@ -444,9 +444,9 @@ public void run()
sb.append(stmp);

if (bits.length > 160 && !bits[159].equals("") && !bits[160].equals(""))
since = "before " + bits[160];
before = common.context.getString(R.string.before) + " " + bits[160];

stmp = "<tr><td colspan='4'>&nbsp;</td><td colspan='2'>" + since + "</td></tr>";
stmp = "<tr><td colspan='4'>&nbsp;</td><td colspan='2'>" + before + "</td></tr>";
sb.append(stmp);

stmp = "</table><br>";
Expand Down
18 changes: 18 additions & 0 deletions app/src/main/java/com/odiousapps/weewxweather/Weather.java
Original file line number Diff line number Diff line change
Expand Up @@ -821,6 +821,24 @@ public void run()
tmp = "<head>" + Common.ssheader + "</head>";
sb.append(tmp);

tmp = "<body style='text-align:center'>" + logo + content[0] + "</body></html>";
sb.append(tmp);
break;
}
case "tempoitalia.it":
{
String[] content = common.processTempoItalia(data);
if (content == null || content.length <= 0)
return;

String logo = "<img src='tempoitalia_it.png' height='29px'/><br/>";
sb.append("<html>");
if(dark_theme)
tmp = "<head><style>body{color: #fff; background-color: #000;}</style>" + Common.ssheader + "</head>";
else
tmp = "<head>" + Common.ssheader + "</head>";
sb.append(tmp);

tmp = "<body style='text-align:center'>" + logo + content[0] + "</body></html>";
sb.append(tmp);
break;
Expand Down
Binary file added app/src/main/res/drawable/tempoitalia_it.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions app/src/main/res/values-it/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,6 @@
<string name="this_months_stats">Questo Mese</string>
<string name="this_year_stats">Anno in corso</string>
<string name="all_time_stats">Assoluti</string>
<string name="since">dal</string>
<string name="before">prima</string>
</resources>
2 changes: 2 additions & 0 deletions app/src/main/res/values-nl/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,6 @@
<string name="this_months_stats">This Month\'s Statistics</string>
<string name="this_year_stats">This Year\'s Statistics</string>
<string name="all_time_stats">All Time Statistics</string>
<string name="since">since</string>
<string name="before">before</string>
</resources>
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,6 @@
<string name="this_months_stats">This Month\'s Statistics</string>
<string name="this_year_stats">This Year\'s Statistics</string>
<string name="all_time_stats">All Time Statistics</string>
<string name="since">since</string>
<string name="before">before</string>
</resources>

0 comments on commit c9b3a1a

Please sign in to comment.