* A little agenda printer script
@ 2007-05-21 13:39 Jason F. McBrayer
2007-05-21 23:32 ` Bastien
` (2 more replies)
0 siblings, 3 replies; 9+ messages in thread
From: Jason F. McBrayer @ 2007-05-21 13:39 UTC (permalink / raw)
To: emacs-orgmode
[-- Attachment #1: Type: text/plain, Size: 592 bytes --]
Taking advantage of the new org-batch-agenda-csv functionality, I've
written a little Python script for exporting an org agenda to PDF,
using LaTeX as an intermediary. Currently, it's a bit of a crude
'worksforme' implementation that could be cleaned up a lot and made
more general. Quite a bit of stuff is hardcoded into some LaTeX
headers/footers that are stored as python strings at the top of the
file. Still, it's at the point that it is, in principle, useful, and
I thought I'd post it here for some feedback before putting it on my
website, announcing on the 43Folders board, etc.
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: org agenda to pdf python script --]
[-- Type: text/x-python, Size: 4626 bytes --]
#!/usr/bin/python
#
# pyagenda -- export an org agenda to PDF
#
# (c) 2007, Jason F. McBrayer
# Version: 1.0
# This file is a stand-alone program.
#
# Legalese:
# pyagenda 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, or (at your option)
# any later version.
#
# pyagenda 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.
#
# Documentation:
# pyagenda is a short python program for taking a formatted agenda
# from org-mode (via org-batch-agenda-csv) and producing a PDF-format
# planner page that can be inserted in a planner binder. Run
# 'pyagenda --help' for usage.
#
# Currently, this is only a crude 'worksforme' implementation, with
# many things being hardcoded. It produces an output file named
# cmdkey.pdf where 'cmdkey' is the key given to
# org-agenda-custom-commands. Not all arbitrary searches will work.
# Be aware that it may overwrite cmdkey.tex, cmdkey.log, cmdkey.aux,
# etc. The output size is hardcoded to 5.5x8.0in, which is suitable
# for a Circa or Rollabind junior sized planner. The output is not
# suitable for daily/weekly agenda views, and does not present all the
# information it could. If you want to change any of the output, edit
# the TEX_* constants.
#
# TODO:
# 1. Use safer tmpfile handling.
# 2. Nicer command-line handling.
# 3. Prettier output, including use of more of the information
# passed by org-batch-agenda-csv.
#
import csv
import sys
import os
from subprocess import Popen, PIPE, call
EMACS = 'emacs'
INIT_FILE = "~/.emacs.d/init.el" # Most people should use "~/.emacs" instead
AGENDA_COMMAND = '(org-batch-agenda-csv "%s")'
TEX_HEADER = """
\\documentclass[twoside, american]{article}
\\usepackage[T1]{fontenc}
\\usepackage[latin1]{inputenc}
\\usepackage{pslatex}
\\usepackage{geometry}
\\geometry{verbose,paperwidth=5.5in,paperheight=8in,tmargin=0.25in,bmargin=0.25in,lmargin=0.5in,rmargin=0.25in}
\\pagestyle{empty}
\\setlength{\\parskip}{\\medskipamount}
\\setlength{\\parindent}{0pt}
\\usepackage{calc}
\\makeatletter
\\newcommand{\\myline}[1]{
{#1 \\hrule width \\columnwidth }
}
\\usepackage{babel}
\\makeatother
\\begin{document}
\\part*{\\textsf{Actions}\\hfill{}%%
\\framebox{\\begin{minipage}[t][1em][t]{0.25\\paperwidth}%%
\\textsf{%s} \\hfill{}%%
\\end{minipage}}%%
\\protect \\\\
}
\\myline{\\normalsize}
"""
TEX_FOOTER = """
\\end{document}
"""
TEX_ITEM = """
%%
\\framebox{\\begin{minipage}[c][0.5em][c]{0.5em}%%
\\hfill{}%%
\\end{minipage}}%%
%%
\\begin{minipage}[c][1em]{1em}%%
\\hfill{}%%
\\end{minipage}%%
\\textsf{%s}\\\\
\\myline{\\normalsize}
"""
class AgendaItem(object):
def __init__(self, data=None):
if data:
self.category = data[0]
self.headline = data[1]
self.type = data[2]
self.todo = data[3]
self.tags = data[4].split(':')
self.date = data[5]
self.time = data[6]
self.extra = data[7]
self.prio = data[8]
self.fullprio = data[9]
def get_agenda_items(cmdkey):
output = Popen([EMACS, "-batch", "-l", INIT_FILE,
"-eval", AGENDA_COMMAND % cmdkey ],
stdout=PIPE, stderr=PIPE)
reader = csv.reader(output.stdout)
items = []
for row in reader:
items.append(AgendaItem(row))
return items
def usage():
print "Usage: pyagenda 'cmd-key' [label]"
print " cmd-key is an org agenda custom command key, or an "
print " org-agenda tags/todo match string."
print " label (optional) is a context label to be printed "
print " at the top of your agenda page."
def main():
try:
search = sys.argv[1]
except IndexError:
usage()
sys.exit(1)
if search == "--help" or search == "-h":
usage()
sys.exit(0)
try:
label = sys.argv[2]
except IndexError:
label = ""
texfile = file(search + ".tex", 'w')
texfile.write(TEX_HEADER % label + "\n")
for item in get_agenda_items(search):
texfile.write(TEX_ITEM %
item.headline.replace('&', r'\&') + "\n" )
texfile.write(TEX_FOOTER)
texfile.close()
call(['pdflatex', texfile.name], stdout=PIPE, stderr=PIPE)
os.unlink(texfile.name)
os.unlink(search + ".aux")
os.unlink(search + ".log")
if __name__ == '__main__':
main()
[-- Attachment #3: Type: text/plain, Size: 316 bytes --]
--
+-----------------------------------------------------------+
| Jason F. McBrayer jmcbray@carcosa.net |
| If someone conquers a thousand times a thousand others in |
| battle, and someone else conquers himself, the latter one |
| is the greatest of all conquerors. --- The Dhammapada |
[-- Attachment #4: Type: text/plain, Size: 149 bytes --]
_______________________________________________
Emacs-orgmode mailing list
Emacs-orgmode@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-orgmode
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: A little agenda printer script
2007-05-21 13:39 A little agenda printer script Jason F. McBrayer
@ 2007-05-21 23:32 ` Bastien
2007-05-22 13:16 ` Jason F. McBrayer
2007-05-22 5:00 ` Carsten Dominik
2007-05-24 21:45 ` Xavier Maillard
2 siblings, 1 reply; 9+ messages in thread
From: Bastien @ 2007-05-21 23:32 UTC (permalink / raw)
To: emacs-orgmode
jmcbray@carcosa.net (Jason F. McBrayer) writes:
> Taking advantage of the new org-batch-agenda-csv functionality, I've
> written a little Python script for exporting an org agenda to PDF,
> using LaTeX as an intermediary.
I like it, thanks! Here pdflatex is complaining about "_" and "#" chars
that are not escaped. Can you fix this?
--
Bastien
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: A little agenda printer script
2007-05-21 13:39 A little agenda printer script Jason F. McBrayer
2007-05-21 23:32 ` Bastien
@ 2007-05-22 5:00 ` Carsten Dominik
2007-05-22 13:11 ` Jason F. McBrayer
2007-05-24 21:45 ` Xavier Maillard
2 siblings, 1 reply; 9+ messages in thread
From: Carsten Dominik @ 2007-05-22 5:00 UTC (permalink / raw)
To: Jason F. McBrayer; +Cc: emacs-orgmode
Great, I am happy to see an application so soon!
I have problems to run it, I guess because of python.
My installation did not have the subprocess module...
- Carsten
On May 21, 2007, at 15:39, Jason F. McBrayer wrote:
> Taking advantage of the new org-batch-agenda-csv functionality, I've
> written a little Python script for exporting an org agenda to PDF,
> using LaTeX as an intermediary. Currently, it's a bit of a crude
> 'worksforme' implementation that could be cleaned up a lot and made
> more general. Quite a bit of stuff is hardcoded into some LaTeX
> headers/footers that are stored as python strings at the top of the
> file. Still, it's at the point that it is, in principle, useful, and
> I thought I'd post it here for some feedback before putting it on my
> website, announcing on the 43Folders board, etc.
>
> <mime-attachment>
>
> --
> +-----------------------------------------------------------+
> | Jason F. McBrayer jmcbray@carcosa.net |
> | If someone conquers a thousand times a thousand others in |
> | battle, and someone else conquers himself, the latter one |
> | is the greatest of all conquerors. --- The Dhammapada |
> _______________________________________________
> Emacs-orgmode mailing list
> Emacs-orgmode@gnu.org
> http://lists.gnu.org/mailman/listinfo/emacs-orgmode
>
--
Carsten Dominik
Sterrenkundig Instituut "Anton Pannekoek"
Universiteit van Amsterdam
Kruislaan 403
NL-1098SJ Amsterdam
phone: +31 20 525 7477
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: A little agenda printer script
2007-05-22 5:00 ` Carsten Dominik
@ 2007-05-22 13:11 ` Jason F. McBrayer
2007-05-23 8:13 ` Carsten Dominik
0 siblings, 1 reply; 9+ messages in thread
From: Jason F. McBrayer @ 2007-05-22 13:11 UTC (permalink / raw)
To: emacs-orgmode
Carsten Dominik <dominik@science.uva.nl> writes:
> Great, I am happy to see an application so soon!
> I have problems to run it, I guess because of python.
> My installation did not have the subprocess module...
It's in the standard library, but it's new to Python 2.4 (latest
Python is 2.5). Odds are you've got Python 2.3, which is still widely
deployed. Perhaps I'll rewrite in terms of os.popen, instead.
--
+-----------------------------------------------------------+
| Jason F. McBrayer jmcbray@carcosa.net |
| If someone conquers a thousand times a thousand others in |
| battle, and someone else conquers himself, the latter one |
| is the greatest of all conquerors. --- The Dhammapada |
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: A little agenda printer script
2007-05-21 23:32 ` Bastien
@ 2007-05-22 13:16 ` Jason F. McBrayer
0 siblings, 0 replies; 9+ messages in thread
From: Jason F. McBrayer @ 2007-05-22 13:16 UTC (permalink / raw)
To: Bastien; +Cc: emacs-orgmode
Bastien <bzg@altern.org> writes:
> jmcbray@carcosa.net (Jason F. McBrayer) writes:
>
>> Taking advantage of the new org-batch-agenda-csv functionality, I've
>> written a little Python script for exporting an org agenda to PDF,
>> using LaTeX as an intermediary.
>
> I like it, thanks! Here pdflatex is complaining about "_" and "#" chars
> that are not escaped. Can you fix this?
It's doable. I knew about the issue but didn't bother to fix it for
characters that I didn't actually use in headlines. I'll have a
little fix out soon.
--
+-----------------------------------------------------------+
| Jason F. McBrayer jmcbray@carcosa.net |
| If someone conquers a thousand times a thousand others in |
| battle, and someone else conquers himself, the latter one |
| is the greatest of all conquerors. --- The Dhammapada |
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: A little agenda printer script
2007-05-22 13:11 ` Jason F. McBrayer
@ 2007-05-23 8:13 ` Carsten Dominik
0 siblings, 0 replies; 9+ messages in thread
From: Carsten Dominik @ 2007-05-23 8:13 UTC (permalink / raw)
To: Jason F. McBrayer; +Cc: emacs-orgmode
On May 22, 2007, at 15:11, Jason F. McBrayer wrote:
> Carsten Dominik <dominik@science.uva.nl> writes:
>
>> Great, I am happy to see an application so soon!
>> I have problems to run it, I guess because of python.
>> My installation did not have the subprocess module...
>
> It's in the standard library, but it's new to Python 2.4 (latest
> Python is 2.5). Odds are you've got Python 2.3, which is still widely
> deployed. Perhaps I'll rewrite in terms of os.popen, instead.
Well, that is one idea, another would be to put a few pdf examples on
a webpage for us to look at it.
- Carsten
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: A little agenda printer script
2007-05-21 13:39 A little agenda printer script Jason F. McBrayer
2007-05-21 23:32 ` Bastien
2007-05-22 5:00 ` Carsten Dominik
@ 2007-05-24 21:45 ` Xavier Maillard
2007-06-03 20:05 ` Jason F. McBrayer
2 siblings, 1 reply; 9+ messages in thread
From: Xavier Maillard @ 2007-05-24 21:45 UTC (permalink / raw)
To: Jason F. McBrayer; +Cc: emacs-orgmode
Hi,
I love the idea though I'd rather have it as an inside-emacs
stuff.
Is there a way to see what does it looks like when formatted ? (I
do not have python installed here).
Anyway, great thanks !
Xavier
--
http://www.gnu.org
http://www.april.org
http://www.lolica.org
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: A little agenda printer script
2007-05-24 21:45 ` Xavier Maillard
@ 2007-06-03 20:05 ` Jason F. McBrayer
2007-06-03 20:17 ` Leo
0 siblings, 1 reply; 9+ messages in thread
From: Jason F. McBrayer @ 2007-06-03 20:05 UTC (permalink / raw)
To: emacs-orgmode
[-- Attachment #1: Type: text/plain, Size: 641 bytes --]
Xavier Maillard <xma@gnu.org> writes:
> I love the idea though I'd rather have it as an inside-emacs
> stuff.
> Is there a way to see what does it looks like when formatted ? (I
> do not have python installed here).
For those who have asked about the output from this script, I'm
attaching a sample of LaTeX output (1.5K) and a sample of PDF output
(17K). Hope that isn't too big for the list. I'll post an updated
copy of the script a bit later. The new version does a bit better
escaping of characters that might be a problem in the produced LaTeX,
and should also work with older versions of python that lack the
subprocess module.
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: Example LaTeX output --]
[-- Type: text/x-tex, Size: 1466 bytes --]
\documentclass[twoside, american]{article}
\usepackage[T1]{fontenc}
\usepackage[latin1]{inputenc}
\usepackage{pslatex}
\usepackage{geometry}
\geometry{verbose,paperwidth=5.5in,paperheight=8in,tmargin=0.25in,bmargin=0.25in,lmargin=0.5in,rmargin=0.25in}
\pagestyle{empty}
\setlength{\parskip}{\medskipamount}
\setlength{\parindent}{0pt}
\usepackage{calc}
\makeatletter
\newcommand{\myline}[1]{
{#1 \hrule width \columnwidth }
}
\usepackage{babel}
\makeatother
\begin{document}
\part*{\textsf{Actions}\hfill{}%
\framebox{\begin{minipage}[t][1em][t]{0.25\paperwidth}%
\textsf{@Example} \hfill{}%
\end{minipage}}%
\protect \\
}
\myline{\normalsize}
%
\framebox{\begin{minipage}[c][0.5em][c]{0.5em}%
\hfill{}%
\end{minipage}}%
%
\begin{minipage}[c][1em]{1em}%
\hfill{}%
\end{minipage}%
\textsf{Post LaTeX output to list}\\
\myline{\normalsize}
%
\framebox{\begin{minipage}[c][0.5em][c]{0.5em}%
\hfill{}%
\end{minipage}}%
%
\begin{minipage}[c][1em]{1em}%
\hfill{}%
\end{minipage}%
\textsf{Post PDF output to list or website}\\
\myline{\normalsize}
%
\framebox{\begin{minipage}[c][0.5em][c]{0.5em}%
\hfill{}%
\end{minipage}}%
%
\begin{minipage}[c][1em]{1em}%
\hfill{}%
\end{minipage}%
\textsf{Post updated pyagenda script to list}\\
\myline{\normalsize}
%
\framebox{\begin{minipage}[c][0.5em][c]{0.5em}%
\hfill{}%
\end{minipage}}%
%
\begin{minipage}[c][1em]{1em}%
\hfill{}%
\end{minipage}%
\textsf{Fill out TPS reports}\\
\myline{\normalsize}
\end{document}
[-- Attachment #3: Example PDF output --]
[-- Type: application/pdf, Size: 16983 bytes --]
[-- Attachment #4: Type: text/plain, Size: 316 bytes --]
--
+-----------------------------------------------------------+
| Jason F. McBrayer jmcbray@carcosa.net |
| If someone conquers a thousand times a thousand others in |
| battle, and someone else conquers himself, the latter one |
| is the greatest of all conquerors. --- The Dhammapada |
[-- Attachment #5: Type: text/plain, Size: 149 bytes --]
_______________________________________________
Emacs-orgmode mailing list
Emacs-orgmode@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-orgmode
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: A little agenda printer script
2007-06-03 20:05 ` Jason F. McBrayer
@ 2007-06-03 20:17 ` Leo
0 siblings, 0 replies; 9+ messages in thread
From: Leo @ 2007-06-03 20:17 UTC (permalink / raw)
To: emacs-orgmode
----- Jason F. McBrayer (2007-06-03) wrote:-----
>> I love the idea though I'd rather have it as an inside-emacs stuff.
>> Is there a way to see what does it looks like when formatted ? (I do
>> not have python installed here).
>
> For those who have asked about the output from this script, I'm
> attaching a sample of LaTeX output (1.5K) and a sample of PDF output
> (17K). Hope that isn't too big for the list. I'll post an updated
> copy of the script a bit later. The new version does a bit better
> escaping of characters that might be a problem in the produced LaTeX,
> and should also work with older versions of python that lack the
> subprocess module.
The pdf output looks great ;)
--
Leo <sdl.web AT gmail.com> (GPG Key: 9283AA3F)
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2007-06-03 20:18 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-05-21 13:39 A little agenda printer script Jason F. McBrayer
2007-05-21 23:32 ` Bastien
2007-05-22 13:16 ` Jason F. McBrayer
2007-05-22 5:00 ` Carsten Dominik
2007-05-22 13:11 ` Jason F. McBrayer
2007-05-23 8:13 ` Carsten Dominik
2007-05-24 21:45 ` Xavier Maillard
2007-06-03 20:05 ` Jason F. McBrayer
2007-06-03 20:17 ` Leo
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).