2
#################################################################################################
4
# tzim.py - Simple conversion module to convert a Tomboy notes database to zim format. #
6
# If not alraeady executable, #
7
# $ chmod a+x tzim.py #
8
# cd to target directory, i.e. where the zim notes shall appear (for example #
10
# $ <dir-path to tzim.py>/tzim.py #
11
# follow instructions. When conversed, open zim and add repository (i.e. current dir) #
14
# This program is free software; you can redistribute it and/or modify #
15
# it under the terms of the GNU General Public License as published by #
16
# the Free Software Foundation; either version 3 of the License, or #
17
# (at your option) any later version. #
19
# This program is distributed in the hope that it will be useful, #
20
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
21
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
22
# GNU General Public License for more details. #
24
# You should have received a copy of the GNU General Public License #
25
# along with this program. If not, see <http://www.gnu.org/licenses/>. #
27
# Copyright 2007 Bengt J. Olsson #
34
#################################################################################################
42
tomboynotes = raw_input("Path to tomboy notes directory (default ~/.tomboy): ")
44
tomboynotes = os.path.expanduser('~')
45
tomboynotes += '/.tomboy/'
46
if not tomboynotes.rstrip == '/':
47
tomboynotes += '/*.note'
49
tomboynotes += '*.note'
50
files = glob.glob(tomboynotes) # Read tomboy notes file names
52
print "No note files." # Exit if no note files in directory
55
infile = open(fil,'r')
56
infile.readline() # get rid of first lines in tomboy note
57
line = infile.readline()
58
if not re.search('note version="0.2"',line):
59
print "Only tested with tomboy notes format version 0.2"
60
line = infile.readline() # Third line contains title of note
62
line = re.sub('<\/?title>','',line) # remove <title> and </title>
63
line = re.sub('^\s*','',line) # remove heading whitespaces
64
print "converting note ", line
65
outfilename = re.sub(' ','_',line) + '.txt' # zim file name for note
66
outfilename = re.sub('[/]','_',outfilename) # get rid of "dangerous" chars in filename
67
outfile = open(outfilename,'w')
68
line = '====== ' + line + ' ======' + '\n\n'
70
infile.readline() # get rid of two first lines more
72
line = infile.readline()
74
while not re.search('</text>$',line):
76
line = infile.readline()
78
line = re.sub('<\/note-content><\/text>','',line)
80
infile.readline() # throw away
81
line = infile.readline()
82
line = re.search('.*(\d\d\d\d-\d\d-\d\d).*',line)
84
line = "\nNote created " + line + "\n"
89
def format(line): #various format substitutions of lines
90
line = re.sub('</?bold>','**',line)
91
line = re.sub('</?italic>','//',line)
92
line = re.sub('</?strikethrough>','~~',line)
93
line = re.sub('</?highlight>','__',line)
94
line = re.sub('</?size:(small|large|huge)>','',line)# Can't handle tomboy sizes
95
line = re.sub('</?monospace>','',line) # or fixed-width
96
line = re.sub('<link:(internal|url)>','[[',line)
97
line = re.sub('</link:(internal|url)>',']]',line)
98
line = re.sub('<list-item dir="ltr">','* ',line)# List handling in tomboy to complexfor this
99
line = re.sub('(</?list>|</list-item>)','',line)# this simple converter; generating a one-level
100
return(line) # list only