Python script to extract reminders to csv file
Extract reminders python script
I have been experimenting with the Python Interface Extension in MD 2015 and wrote the attached python script, extractreminderstocsv_v1.py as my first endeavour.
The script extracts reminders (Notes and Transactions) to a csv file suitable for opening in Excel. You will need to change the myfolder variable in the script and set it to your output folder location where the csv file will be created by the script.
To run the script start the Python Interface Extension in the Extensions Menu, click Read from File button and locate script and click the Open button. The script will read and extract the reminders to the folder location you set in the myfolder variable in the script.
My Experience so far creating Python Scripts
I am continuing to experiment with the Python Interface Extension which is based around Jython rather than pure python. I am new to Jython but have written a lot of python code over the years and found a couple of things that were unexpected (to me!)
1. The datetime module will not import
The first was trying to import the python datetime module which was not allowed. To do date manipulation I am using the java date functions. The following function adds months to Moneydance dates which are yyyymmdd integers
import java.util.Calendar
import java.util.GregorianCalendar
import java.text.SimpleDateFormat
def addtodate(period,numperiods,dateInt):
#add months to an integer date in yyyymmdd format
# (note python datetime module does not work in the Python extension which is Jython based)
#convert integer date to separate integers for y m and d
dateString=str(dateInt)
yyyy=int(dateString[0:4])
mm=int(dateString[4:6])-1
dd=int(dateString[6:8])
#use java date functions to add months
date = java.util.GregorianCalendar(yyyy,mm,dd)
if period=='MONTH':
newdate=date.add(java.util.Calendar.MONTH,numperiods)
if period=='WEEK':
newdate=date.add(java.util.Calendar.DATE,numperiods*7)
if period=='DAY':
newdate=date.add(java.util.Calendar.DATE,numperiods)
sdf=java.text.SimpleDateFormat("yyyyMMdd")
newdate = int(sdf.format(date.getTime()))
return newdate #returns integer date as number representing yyyymmdd
2. Python UI frameworks will not work with Jython
I have used the standard python UI - Tkinter and also wxPython libraries both of which will not work in Jython. It seems the best approach for any UI capabilities is to use java swing functions. Luckliy my Java is not too bad so I am now experimenting with various Swing widgets. One document I did find that was extremely helpful can be found here.
Allan
- extractreminderstocsv_v1.py 3.7 KB
Comments are currently closed for this discussion. You can start a new one.
Keyboard shortcuts
Generic
? | Show this help |
---|---|
ESC | Blurs the current field |
Comment Form
r | Focus the comment reply box |
---|---|
^ + ↩ | Submit the comment |
You can use Command ⌘
instead of Control ^
on Mac
System closed this discussion on 19 Mar, 2016 04:54 AM.