add experimental utility with which to enhance ghash/ with tzdata

This commit is contained in:
Jan-Piet Mens
2024-02-01 18:00:26 +01:00
parent ea36109d72
commit 1daec5116d
4 changed files with 103 additions and 0 deletions
+3
View File
@@ -0,0 +1,3 @@
*.o
.DS_Store
addtzname
+8
View File
@@ -0,0 +1,8 @@
CFLAGS=-I../.. \
-DTZDATADB="\"../../sundry/zonedetect/ZoneDetect/out/timezone16.bin\""
OBJS=../../json.o ../../zonedetect.o ../../geohash.o
addtzname: addtzname.c $(OBJS)
$(CC) $(CFLAGS) -o addtzname addtzname.c $(OBJS)
+20
View File
@@ -0,0 +1,20 @@
# addtzname
Use at your own risk.
Basically, after taking a backup, this is:
- `o` is the path to your existing STORAGEDIR
- `n` is a new directory
```console
$ mkdir n
$ ot-recorder -S n --initialize
$ ocat -S o --dump | ./addtzname | ocat -S n --load
$ ocat -S n --dump | head # verify JSON contains tzname
# when you're ready:
$ cp n/ghash/* ....../o/ghash/
```
+72
View File
@@ -0,0 +1,72 @@
/*
* OwnTracks Recorder
* Copyright (C) 2024 Jan-Piet Mens <jpmens@gmail.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include "json.h"
#include "geohash.h"
#include "zonedetect.h"
int main(int argc, char **argv)
{
char buf[BUFSIZ];
char *s, *geohash, *js;
JsonNode *json, *j;
static ZoneDetect *zdb = NULL;
zdb = ZDOpenDatabase(TZDATADB);
if (zdb == NULL) {
perror("Can't open zdb");
exit(2);
}
while (fgets(s = buf, sizeof(buf), stdin) != NULL) {
// find first space
if ((geohash = strtok(buf, " ")) != NULL) {
js = buf + strlen(geohash) + 1;
// puts(js);
if ((json = json_decode(js)) == NULL) {
if (strncmp(buf, "friends", 7) &&
strncmp(buf, "topic2tid", 9) &&
strncmp(buf, "wp", 2)) {
fprintf(stderr, "Can't decode %s\n", buf);
}
continue;
}
if ((j = json_find_member(json, "tzname")) == NULL) {
char *tz;
GeoCoord g = geohash_decode(geohash);
if ((tz = ZDHelperSimpleLookupString(zdb, g.latitude, g.longitude)) != NULL) {
json_append_member(json, "tzname", json_mkstring(tz));
ZDHelperSimpleLookupStringFree(tz);
}
}
js = json_stringify(json, NULL);
printf("%s %s\n", geohash, js);
free(js);
json_delete(json);
}
}
return 0;
}