Support output of location between s_lo and s_hi; add isodt

This commit is contained in:
Jan-Piet Mens
2015-08-22 10:01:50 +02:00
parent 786a8c1788
commit 6d53ef6fae
3 changed files with 22 additions and 5 deletions
+2 -2
View File
@@ -134,7 +134,7 @@ int main(int argc, char **argv)
int n;
for (n = 0; n < argc; n++) {
locations(argv[n], obj, locs);
locations(argv[n], obj, locs, s_lo, s_hi);
}
} else {
JsonNode *arr, *f;
@@ -143,7 +143,7 @@ int main(int argc, char **argv)
if ((arr = json_find_member(json, "results")) != NULL) { // get array
json_foreach(f, arr) {
printf("%s\n", f->string_);
locations(f->string_, obj, locs);
locations(f->string_, obj, locs, s_lo, s_hi);
}
}
json_delete(json);
+19 -2
View File
@@ -262,7 +262,7 @@ JsonNode *lister(char *user, char *device, time_t s_lo, time_t s_hi)
* contains `arr'.
*/
void locations(char *filename, JsonNode *obj, JsonNode *arr)
void locations(char *filename, JsonNode *obj, JsonNode *arr, time_t s_lo, time_t s_hi)
{
JsonNode *o, *json, *j;
FILE *fp;
@@ -272,7 +272,9 @@ void locations(char *filename, JsonNode *obj, JsonNode *arr)
static char *numbers[] = { "lat", "lon", "batt", "vel", "cog", "tst", "alt", "dist", "trip", NULL };
static char *strings[] = { "tid", "t", NULL };
extern int errno;
static UT_string *tstamp = NULL;
utstring_renew(tstamp);
if (!strcmp(filename, "-")) {
fp = stdin;
@@ -294,8 +296,22 @@ void locations(char *filename, JsonNode *obj, JsonNode *arr)
while (fgets(buf, sizeof(buf)-1, fp) != NULL) {
char *bp, *ghash;
char *bp, *ghash, *p;
double lat, lon;
struct tm tmline;
time_t secs;
if ((p = strptime(buf, "%Y-%m-%dT%H:%M:%SZ", &tmline)) == NULL) {
fprintf(stderr, "no strptime on %s", buf);
continue;
}
utstring_clear(tstamp);
utstring_printf(tstamp, "%-20.20s", buf);
secs = mktime(&tmline);
if (secs <= s_lo || secs >= s_hi) {
continue;
}
if ((bp = strstr(buf, "Z\t* ")) != NULL) {
if ((bp = strrchr(bp, '\t')) == NULL) {
@@ -340,6 +356,7 @@ void locations(char *filename, JsonNode *obj, JsonNode *arr)
ghash = geohash_encode(lat, lon, GEOHASH_PREC);
json_append_member(o, "ghash", json_mkstring(ghash));
json_append_member(o, "isodt", json_mkstring(utstring_body(tstamp)));
get_geo(o, ghash);
+1 -1
View File
@@ -6,7 +6,7 @@
JsonNode *lister(char *username, char *device, time_t s_lo, time_t s_hi);
void locations(char *filename, JsonNode *obj, JsonNode *arr);
void locations(char *filename, JsonNode *obj, JsonNode *arr, time_t s_lo, time_t s_hi);
int make_times(char *time_from, time_t *s_lo, char *time_to, time_t *s_to);
#endif