You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Something I did when I first installed the application was to make a script to parse the FoxClocks configuration file* and convert each clock into a SQL statement to then insert them into the app database (since adding the clocks manually was going to be very time consuming).
The problem with this is that it's impractical since it requires having a rooted phone, so it could be very useful to have an option to import the FoxClocks clocks directly into the app.
For what it's worth, the parser could be done with this code (adapted version of the Python script I originally made):
importjava.util.regex.Pattern;
importjava.util.regex.Matcher;
importjava.io.BufferedReader;
importjava.io.FileReader;
importjava.io.IOException;
publicclassFoxclocksDataParser {
privatestaticfinalPatternextractor = Pattern.compile(
"id=\"([^\"]+)\"/>(?:<Name>([^<]+)</Name>)?<Coordinates latitude=\"([^\"]+)\" longitude=\"([^\"]+)\"|<Location><Zone id=\"([^\"]+)\"/></Location>"
);
publicstaticvoiddataParser(Stringdata) {
Matchermatcher = extractor.matcher(data);
while (matcher.find()) {
StringtimezoneId = matcher.group(1);
Stringname = matcher.group(2) == null ? "" : matcher.group(2);
Stringlatitude = matcher.group(3);
Stringlongitude = matcher.group(4);
Stringcity = "";
if (timezoneId != null) {
String[] parts = timezoneId.split("/");
if (parts.length > 1) {
city = parts[1].replace("_", " ");
}
}
// UTC is a special caseif (matcher.group(0).indexOf("Etc/UTC") > -1) {
timezoneId = "GMT";
city = "UTC";
name = "Coordinated Universal Time";
latitude = longitude = "0.0";
}
System.out.printf(
"insert into clocks (time_diff, timezone_id, city, area, latitude, longitude) " +
"values (0, '%s', '%s', '%s', '%s', '%s');%n",
timezoneId, city, name, latitude, longitude
);
}
}
publicstaticvoidmain(String[] args) {
// Use exampleif (args.length >= 1) {
BufferedReaderobjReader = null;
try {
StringstrCurrentLine;
objReader = newBufferedReader(newFileReader(args[0]));
StringBuilderstringBuilder = newStringBuilder();
while ((strCurrentLine = objReader.readLine()) != null) {
stringBuilder.append(strCurrentLine);
stringBuilder.append("\n");
}
dataParser(stringBuilder.toString());
} catch (IOExceptione) {
e.printStackTrace();
} finally {
try {
if (objReader != null) { objReader.close(); }
}
catch (IOExceptionex) { ex.printStackTrace(); }
}
}
else { System.out.println("A file is needed to parse. Exiting"); }
}
}
To test it just save it as FoxclocksDataParser.java and run the following:
Which returns an insert statement for each clock found. When inserting that in /data/data/ch.corten.aha.worldclock/databases/worldclock, the result is the following after restarting the application:
I also take the opportunity to leave the configuration file* with which I did this and to be able to test the example code.
The file is from an old/legacy version of FoxClocks, since when they migrated it to WebExtensions the option to import/export the configuration disappeared or was never integrated (at least in the Firefox extension, but it is possible that it is the same in other browsers).
The text was updated successfully, but these errors were encountered:
Something I did when I first installed the application was to make a script to parse the FoxClocks configuration file* and convert each clock into a SQL statement to then insert them into the app database (since adding the clocks manually was going to be very time consuming).
The problem with this is that it's impractical since it requires having a rooted phone, so it could be very useful to have an option to import the FoxClocks clocks directly into the app.
For what it's worth, the parser could be done with this code (adapted version of the Python script I originally made):
To test it just save it as FoxclocksDataParser.java and run the following:
Which returns an insert statement for each clock found. When inserting that in /data/data/ch.corten.aha.worldclock/databases/worldclock, the result is the following after restarting the application:
I also take the opportunity to leave the configuration file* with which I did this and to be able to test the example code.
The text was updated successfully, but these errors were encountered: