Skip to content

Instantly share code, notes, and snippets.

@bzamecnik
Created November 19, 2013 20:23
Show Gist options
  • Save bzamecnik/7551920 to your computer and use it in GitHub Desktop.
Save bzamecnik/7551920 to your computer and use it in GitHub Desktop.
Personal journal template generator in Groovy. Generates a page of formated days in given month.
#!/usr/bin/env groovy
/*
Generates a template for journal (for a single month).
Example:
Journal 2013/11
2013-11-01 (Fri)
2013-11-02 (Sat)
...
Requirements:
Groovy (http://groovy.codehaus.org/)
Installation:
paste eg. to ~/bin/journal.groovy
chmod +x ~/bin/journal.groovy
Usage:
journal.groovy [YYYY-MM]
Generate template for a given month:
$ journal.groovy '2012-05' >> log-2012-05.txt
Or for the current one, if none given.
$ journal.groovy >> log-this-month.txt
Author: Bohumir Zamecnik (http://zamecnik.me)
License: MIT License
*/
import groovy.time.TimeCategory
def generateJournal(month) {
use (TimeCategory) {
def start = Date.parse('yyyy-MM', month)
def end = start + 1.month
println """Journal ${start.format('yyyy/MM')}
${(start..<end).collect {it.format('yyyy-MM-dd (E)')}.join('\n\n')}
"""
}
}
generateJournal(args ? args[0] : new Date().format('yyyy-MM'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment