Can CN import my TXT note files (generated by ResophNotes) ?

SFdude
Posts: 4
Joined: Sun Apr 15, 2012 2:57 am
Contact:

Can CN import my TXT note files (generated by ResophNotes) ?

Postby SFdude » Sun Apr 15, 2012 3:14 am

Hi,

Q:
How can I import all my existing .TXT note files into CN?
(all these .TXT files were previously generated by ResophNotes) ;)

All my current Resoph-generated .txt files,
(about 500 .TXT files),
are stored in a Folder, on my PC.

I need to "migrate" them into CN...

tks!
SFdude
XP Pro SP3 - 32bit
FF 11
CN Free -latest version.
User avatar
CintaNotes Developer
Site Admin
Posts: 4708
Joined: Fri Dec 12, 2008 4:45 pm
Contact:

Re: Can CN import my TXT note files (generated by ResophNote

Postby CintaNotes Developer » Mon Apr 16, 2012 12:07 pm

Hi!

OK this seems to be a VERY frequent demand, so I've cooked a simple program
to do just that: iterate over a folder, read all .TXT files and create a single XML file
which is importable into CN.

Example:
You have a directory with .txt files, say it is D:\SNIPPETS.
You download the file below and unpack it into D:\, then run
txtdir2xml D:\SNIPPETS snippets.xml


If your text snippet directory contains subdirs with more .txt files, add the -r switch ("recurse").
If your text file encoding is not UTF-8 but UTF-16, then add the "-e utf-16" switch:
txtdir2xml -e utf-16 -r D:\SNIPPETS snippets.xml


After that you run CintaNotes and import the resulting XML file.
Actually the program is self-explanatory, just run txtdir2xml.exe without any arguments.

Please let me know how did the import go.
Cheers
Attachments
txtdir2xml.zip
(2.53 MiB) Downloaded 715 times
Alex
SFdude
Posts: 4
Joined: Sun Apr 15, 2012 2:57 am
Contact:

Re: Can CN import my TXT note files (generated by ResophNote

Postby SFdude » Tue Apr 17, 2012 12:58 am

Hi Alex,

Thanks for the quick response.

A brief follow-up question
before I test your new XML converter pgm.,
(if you don't mind, of course):

( a ) The unzipped file size
of the main program:
.... "CintaNotes.EXE" (version 1.6),
is ~ 1.5 MBs.

( b ) The unzipped file size
of the new XML converter program:
.... "txtdir2xml.EXE"
is ...over 4.5 MBs !.
(ie: 3 times larger than the main prog...).

Why is that?
Does the new XML converter program:
"txtdir2xml.EXE"
install any libraries or add any changes in my PC?
(ie: Java, .NET, Python, Win registry changes, etc.)?

Reason I'm asking:
- I want to make sure the new converter pgm.
is totally portable,
and will not change or add anything
to my Win XP, when I run it... :roll:

Thanks!
SFdude
User avatar
CintaNotes Developer
Site Admin
Posts: 4708
Joined: Fri Dec 12, 2008 4:45 pm
Contact:

Re: Can CN import my TXT note files (generated by ResophNote

Postby CintaNotes Developer » Tue Apr 17, 2012 1:25 am

Great question! :)

I think you're aware of app vs. programmer productivity dilemma?)

Absolutely no libraries get installed, the app is 100% portable.
I've created the app using Python 3.2.3 and cx_Freeze.
The file size is large because it contains, it packed form, the whole Python runtime.

If you're still suspicious, here is the source Python script, you are welcome to try/use/modify it :)

Code: Select all

import argparse as ap
import os, os.path
from xml.dom.minidom import Document as XmlDocument
import time

VERSION  = "1.0"
GREETING = "CintaNotes TXT folder importer V%s.\n" % VERSION

def main():
   print(GREETING)
   argsParser = createArgsParser()
   argsParser.print_help()
   args = argsParser.parse_args()
   print('Processing..')
   count = convert(args.inputFolder, args.outputXML, args.encoding, args.recurse)
   print('\n-> Converted %d file(s).' % count)


def createArgsParser():
   parser = ap.ArgumentParser(description = "Converts folders with text files to importable XML. Only files with .txt extension are read.")

   parser.add_argument("inputFolder",
                        help = 'Folder with TXT files to be converted.',
                        type = str)

   parser.add_argument("outputXML",
                        help = 'Resulting XML file name',
                        type = str)

   parser.add_argument("-e", "--encoding", dest="encoding", help = 'Encoding of TXT files: utf-8 (default) or utf-16', type = str, default = 'utf-8')
   parser.add_argument("-r", "--recurse", dest="recurse", help = 'Recurse into subdirectories', action = 'store_true', default = False)

   return parser


def convert(inputFolder, outputXML, encoding, recurse):
   xml = XmlDocument()
   root = xml.createElement('notebook')
   root.setAttribute('version', '1600')
   xml.appendChild(root)

   count = convertFiles(inputFolder, xml, encoding, recurse)
   output = open(outputXML, 'w', encoding = 'utf-16le')
   output.write(xml.toprettyxml())
   return count


def convertFiles(inputFolder, xmlDocument, encoding, recurse):
   count = 0
   for root, dirs, files in os.walk(inputFolder):
      for file in files:
         (name, ext) = os.path.splitext(file)
         if ext == '.txt':
            addTextFileToXml(os.path.join(root, file), xmlDocument, encoding)
            count = count + 1
      if not recurse:
         break

   return count


def addTextFileToXml(filePath, xmlDocument, encoding):
   filePath = os.path.abspath(filePath)
   file = open(filePath, encoding = encoding)
   (_, filename) = os.path.split(filePath)
   (title, _) = os.path.splitext(filename)
   body = removeBOM(file.read())

   note = xmlDocument.createElement('note')
   note.setAttribute('title', title)
   note.setAttribute('link', 'file://' + filePath)
   note.setAttribute('tags', '')
   note.setAttribute('source', filePath)
   note.setAttribute('created', getCreatedTime(filePath))
   note.setAttribute('modified', getModifiedTime(filePath))

   noteBody = xmlDocument.createCDATASection(body)
   note.appendChild(noteBody)

   xmlDocument.documentElement.appendChild(note)


def getCreatedTime(filePath):
   return timeToStr(os.path.getctime(filePath))

def getModifiedTime(filePath):
   return timeToStr(os.path.getmtime(filePath))

def timeToStr(tm):
   return time.strftime('%Y%m%dT%H%M%S', time.gmtime(tm))

def removeBOM(s):
   if s.startswith('\uFEFF') or s.startswith('\uFFFE') or s.startswith('\uEFBBBF'):
      return s[1:]
   return s

if __name__ == '__main__': main()
Alex
Thomas Lohrum
Posts: 1310
Joined: Tue Mar 08, 2011 11:15 am

Re: Can CN import my TXT note files (generated by ResophNote

Postby Thomas Lohrum » Tue Apr 17, 2012 1:26 am

Hi SFdude,

SFdude wrote:Hi Alex,( a ) The unzipped file size
of the main program: ... "CintaNotes.EXE" (version 1.6), is ~ 1.5 MBs. ( b ) The unzipped file size of the new XML converter program: .... "txtdir2xml.EXE" is ...over 4.5 MBs !. (ie: 3 times larger than the main prog...). Why is that?
Cintanotes.exe is packed. I guess the converter program is not, thus it appears to be larger.

SFdude wrote:Does the new XML converter program:
"txtdir2xml.EXE"
install any libraries or add any changes in my PC?
(ie: Java, .NET, Python, Win registry changes, etc.)?
I don't expect the app to do so, since CN itself is highly portable. However, only Alex can tell.

Thomas
Thomas Lohrum
Posts: 1310
Joined: Tue Mar 08, 2011 11:15 am

Re: Can CN import my TXT note files (generated by ResophNote

Postby Thomas Lohrum » Tue Apr 17, 2012 1:32 am

CintaNotes Developer wrote:I've created the app using Python 3.2.3 and cx_Freeze.

Nice program Alex :) Maybe you should allow a tag-list (plain string) to be passed by the command line?!

Thomas
User avatar
CintaNotes Developer
Site Admin
Posts: 4708
Joined: Fri Dec 12, 2008 4:45 pm
Contact:

Re: Can CN import my TXT note files (generated by ResophNote

Postby CintaNotes Developer » Tue Apr 17, 2012 3:31 am

Do you mean that all notes will be tagged with same tags?
Alex
Thomas Lohrum
Posts: 1310
Joined: Tue Mar 08, 2011 11:15 am

Re: Can CN import my TXT note files (generated by ResophNote

Postby Thomas Lohrum » Tue Apr 17, 2012 9:42 am

CintaNotes Developer wrote:Do you mean that all notes will be tagged with same tags?

Yes. I can use a file filter to convert a group or a single file and tag it while converting, e.g. convert cintanotes*.txt -tags:"cintanotes outliner", convert word*.txt -tags:"word faq". That requests converting files in separate steps, but adds more flexibility. It's optional and should be fairly easy to implement ;)
User avatar
CintaNotes Developer
Site Admin
Posts: 4708
Joined: Fri Dec 12, 2008 4:45 pm
Contact:

Re: Can CN import my TXT note files (generated by ResophNote

Postby CintaNotes Developer » Tue Apr 17, 2012 10:48 am

I see. Well, for 1.7 I'm planning an "Add Tags" field for the Import dialog, so this will become a non-issue anyway - I guess it can wait till then.
Also there is a simple workaround: just create a new notebook, import the XML into it, select all notes and tag them, and after that switch to target notebook and import the new notebook into it (or just copy-paste the notes).
Alex
Thomas Lohrum
Posts: 1310
Joined: Tue Mar 08, 2011 11:15 am

Re: Can CN import my TXT note files (generated by ResophNote

Postby Thomas Lohrum » Tue Apr 17, 2012 10:53 am

CintaNotes Developer wrote:I see. Well, for 1.7 I'm planning an "Add Tags" field for the Import dialog, so this will become a non-issue anyway - I guess it can wait till then.
Also there is a simple workaround: just create a new notebook, import the XML into it, select all notes and tag them, and after that switch to target notebook and import the new notebook into it (or just copy-paste the notes).

Fine. That should handle the issue :)

Thomas
SFdude
Posts: 4
Joined: Sun Apr 15, 2012 2:57 am
Contact:

Re: Can CN import my TXT note files (generated by ResophNote

Postby SFdude » Tue Apr 17, 2012 8:47 pm

Ahh! Understood.

Thanks Alex & Thomas Lohrum,
for explaining the big file size difference.

Just to confirm:
So, running "txtdir2xml.EXE",
will not change, add or install Python (or other libs)
on my PC, right?

(...it's as if I'm running a "portable", self-contained pgm...).

Thanks for you patience guys!
SFdude
Thomas Lohrum
Posts: 1310
Joined: Tue Mar 08, 2011 11:15 am

Re: Can CN import my TXT note files (generated by ResophNote

Postby Thomas Lohrum » Tue Apr 17, 2012 8:56 pm

SFdude wrote:So, running "txtdir2xml.EXE", will not change, add or install Python (or other libs) on my PC, right?

Yes. See Alex's answer:
CintaNotes Developer wrote:Absolutely no libraries get installed, the app is 100% portable.
SFdude
Posts: 4
Joined: Sun Apr 15, 2012 2:57 am
Contact:

Re: Can CN import my TXT note files (generated by ResophNote

Postby SFdude » Thu Apr 19, 2012 12:39 am

ok -
thanks for the reassurance, Thomas.

Really look forward
to trying out CintaNotes.

SFdude
User avatar
CintaNotes Developer
Site Admin
Posts: 4708
Joined: Fri Dec 12, 2008 4:45 pm
Contact:

Re: Can CN import my TXT note files (generated by ResophNote

Postby CintaNotes Developer » Sun Apr 22, 2012 1:50 am

SFDude,
Thomas is right, the program won't insall anything on your system.
Please share with us how did the import go.
Alex
Dude
Posts: 4
Joined: Thu Apr 19, 2012 6:14 am
Contact:

Re: Can CN import my TXT note files (generated by ResophNote

Postby Dude » Sun May 06, 2012 12:39 pm

Now this is lovely. I've got a bunch of text files from my phone (notes here and there), my primary notetaker on the go, and this would make it easier to import to Cinta.
Mark B.

Re: Can CN import my TXT note files (generated by ResophNote

Postby Mark B. » Tue May 15, 2012 12:07 pm

txtdir2xml does not work on my XP SP3 system. I get this error message:

UnicodeDecodeError: 'utf-8' codec can't decode byte 0xa3 in position 657: invalid start byte
User avatar
CintaNotes Developer
Site Admin
Posts: 4708
Joined: Fri Dec 12, 2008 4:45 pm
Contact:

Re: Can CN import my TXT note files (generated by ResophNote

Postby CintaNotes Developer » Tue May 15, 2012 3:05 pm

Hi Mark B.,

please check that all your TXT files have UTF-8 encoding.
If they are UTF-16 (2 bytes per character), please add the "-e utf-16" parameter.
Alex
Guest

Re: Can CN import my TXT note files (generated by ResophNote

Postby Guest » Tue May 15, 2012 11:40 pm

Hello Alex,

They're all utf-8 according the Notepad++. But I still get the same problem, with one slight difference: position 660 instead of 657.
(the -e parameter doesn't help, as expected).

Also Avira AV doesn't like the program, it claims to detect the presence of the "TR/Crypt.ULPM.Gen2" virus in it.
Thomas Lohrum
Posts: 1310
Joined: Tue Mar 08, 2011 11:15 am

Re: Can CN import my TXT note files (generated by ResophNote

Postby Thomas Lohrum » Tue May 15, 2012 11:50 pm

Hi Guest,

CintaNotes Developer wrote:Also Avira AV doesn't like the program, it claims to detect the presence of the "TR/Crypt.ULPM.Gen2" virus in it.

I can not confirm your alert. I use Avira Pro with the latest signatures and CintaNotes 1.6.2.

Which version of CN are you running?

Thomas

[EDIT]As of May 15 Aviras ProActiv Module was giving false alerts. A fix was released last night.
Last edited by Thomas Lohrum on Wed May 16, 2012 7:53 am, edited 1 time in total.
User avatar
CintaNotes Developer
Site Admin
Posts: 4708
Joined: Fri Dec 12, 2008 4:45 pm
Contact:

Re: Can CN import my TXT note files (generated by ResophNote

Postby CintaNotes Developer » Wed May 16, 2012 7:06 am

Guest wrote:They're all utf-8 according the Notepad++. But I still get the same problem, with one slight difference: position 660 instead of 657.
(the -e parameter doesn't help, as expected).

Are you sure that the file is not corrupt? Have you tried excluding this file from import? If you could send this file to me to support@cintanotes.com, it would greatly help in fixing this problem. Thanks!
Alex

Return to “CintaNotes Personal Notes Manager”