Skip to content

Commit

Permalink
ENH: Only add new data to report.
Browse files Browse the repository at this point in the history
When the last reported values are identical to the current values, do not append the same information (just with a new timestamp) to the report. Instead, just print the last report line.

With this, the report action can be scheduled periodically (e.g. via cron) without artificially inflating the report file.
  • Loading branch information
inkarkat committed Jan 21, 2012
1 parent d46adad commit 7e525ee
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions todo.sh
Original file line number Diff line number Diff line change
Expand Up @@ -1222,9 +1222,18 @@ note: PRIORITY must be anywhere from A to Z."

TOTAL=$( sed -n '$ =' "$TODO_FILE" )
TDONE=$( sed -n '$ =' "$DONE_FILE" )
echo "$(date +%Y-%m-%dT%T) ${TOTAL:-0} ${TDONE:-0}" >> "$REPORT_FILE"
sed -ne '$p' "$REPORT_FILE"
[ $TODOTXT_VERBOSE -gt 0 ] && echo "TODO: Report file updated."
NEWDATA="${TOTAL:-0} ${TDONE:-0}"
LASTREPORT=$(sed -ne '$p' "$REPORT_FILE")
LASTDATA=${LASTREPORT#* } # Strip timestamp.
if [ "$LASTDATA" = "$NEWDATA" ]; then
echo "$LASTREPORT"
[ $TODOTXT_VERBOSE -gt 0 ] && echo "TODO: Report file is up-to-date."
else
NEWREPORT="$(date +%Y-%m-%dT%T) ${NEWDATA}"
echo "${NEWREPORT}" >> "$REPORT_FILE"
echo "${NEWREPORT}"
[ $TODOTXT_VERBOSE -gt 0 ] && echo "TODO: Report file updated."
fi
;;

"deduplicate" )
Expand Down

0 comments on commit 7e525ee

Please sign in to comment.