diff --git a/README.md b/README.md index 1ce4820..8b4f28c 100644 --- a/README.md +++ b/README.md @@ -37,3 +37,4 @@ python3 -m pip -r requirements.txt ``` +A convenience bash wrapper script `./python/report.sh` is meant to be called by the xmpp-bot directly, activating the virtual environment and calling `report.py` diff --git a/python/report.py b/python/report.py index a4597f3..427f89e 100644 --- a/python/report.py +++ b/python/report.py @@ -1,5 +1,7 @@ #!/usr/bin/python3 +# TODO format output + import pandas as pd import argparse diff --git a/src/core/handlers.c b/src/core/handlers.c index d08401c..3079df2 100644 --- a/src/core/handlers.c +++ b/src/core/handlers.c @@ -50,6 +50,28 @@ return 1; } +GString* bot_exec_report(gchar * const reportScript, gchar * const csvfile) +{ + FILE *fp; + size_t cap; + char *buf = NULL; + GString *command = g_string_new(""); + GString *output = g_string_new(""); + + g_string_printf(command, "%s %s 10 it", reportScript, csvfile); // TODO variable number of expenses, daily ecc + + fp = popen(command->str,"r"); + while( getline(&buf, &cap, fp) != -1 ){ + g_string_append(output, buf); + } + + pclose(fp); + + printf("%s\n", output->str); + + return output; +} + int message_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void * const userdata) { @@ -101,6 +123,9 @@ g_string_printf(replytext, "Ho cancellato il reminder, %s.\n", strtok(strdup(reminder->from->str), "@")); } break; + case BOT_CMD_REPORT: + replytext = bot_exec_report("./python/report.sh", "./test2.csv"); + break; default: g_string_printf(replytext, "Non ho riconosciuto il comando: %s", intext->str); break; diff --git a/src/expenses/grammar.y b/src/expenses/grammar.y index 8cbb460..6a73067 100644 --- a/src/expenses/grammar.y +++ b/src/expenses/grammar.y @@ -71,7 +71,11 @@ bot_set_last_reminder(abs($2)); } | TOK_CMD_DEL TOK_INT { printf("delete: %d\n", $2); $$ = 0; } - | TOK_CMD_REPORT ts { printf("report: %d\n", $2); $$ = 0; } + | TOK_CMD_REPORT ts { printf("report: %d\n", $2); $$ = 0; } // TODO + | TOK_CMD_REPORT + { bot_set_last_command($1); + printf("standard report"); $$ = 0; + } value: TOK_INT { $$ = (double)$1; } | TOK_DOUBLE