Importing a tiddler written with python?

191 views
Skip to first unread message

Jimmy Sweeney

unread,
Aug 27, 2020, 4:24:38 PM8/27/20
to TiddlyWiki
Hi there,

Would anyone have any clues why this file isn't importing nice and cleanly into my TiddlyWiki? It imports but not nice and clean like dragging and dropping a tiddler from another TiddlyWiki site does.

I'm trying to create a python script that creates tiddler files. I input the ISBN (a book ID number essentially) and spits out a tiddler file with the title, author, cover image, etc.


What magic ingredients am I missing?


Eric Shulman

unread,
Aug 27, 2020, 4:39:39 PM8/27/20
to TiddlyWiki
On Thursday, August 27, 2020 at 1:24:38 PM UTC-7, Jimmy Sweeney wrote:
Would anyone have any clues why this file isn't importing nice and cleanly into my TiddlyWiki? It imports but not nice and clean like dragging and dropping a tiddler from another TiddlyWiki site does.

The first thing I noticed is that the "created" field is not the correct format.

It's supposed to be a 17-digit value, YYYYMMDDhhmmssXXX, where:
* YYYY is the year number
* MM is the month number
* DD is the date 
* hh is the hours
* mm is the minutes
* ss is the seconds
* XXX is the milliseconds
(note that all values are zero-padded as needed)

The second thing I notice is that there is no "modified" field.
Without this field, the tiddler won't appear in the "recent" sidebar tab list.

Hope this helps...

-e

Saq Imtiaz

unread,
Aug 27, 2020, 4:47:36 PM8/27/20
to TiddlyWiki
Make sure the text field in the JSON does not contain linebreaks or other characters that need to be escaped.

Jimmy Sweeney

unread,
Aug 27, 2020, 5:24:59 PM8/27/20
to tiddl...@googlegroups.com
Hi Saq - why would that be? When I export other tiddlers as json files they have line breaks as "\n". 

Thanks Eric, I fixed those two things but still no luck.

--
You received this message because you are subscribed to a topic in the Google Groups "TiddlyWiki" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/tiddlywiki/VCn3kDOmTD4/unsubscribe.
To unsubscribe from this group and all its topics, send an email to tiddlywiki+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/tiddlywiki/50f4ba7a-2c94-41a2-a87d-2185aaf8fe30n%40googlegroups.com.


--

dieg...@gmail.com

unread,
Aug 27, 2020, 5:46:53 PM8/27/20
to TiddlyWiki
Hi,

When I take that raw string, save it as a .json file and upload that to tiddlywiki.com I can see the imported tiddler just fine!

Mark S.

unread,
Aug 27, 2020, 6:11:34 PM8/27/20
to TiddlyWiki


On Thursday, August 27, 2020 at 2:24:59 PM UTC-7, Jimmy Sweeney wrote:
Hi Saq - why would that be? When I export other tiddlers as json files they have line breaks as "\n". 


I don't think they have line breaks in the middle of text strings, as yours does. Wherever there was a line break, there needs to be a \n instead.

TW Tones

unread,
Aug 27, 2020, 6:51:38 PM8/27/20
to TiddlyWiki
FYI: Someone has already done an ISBN tiddler, Not sure where, sorry.

Tones

Jimmy Sweeney

unread,
Aug 28, 2020, 11:04:01 AM8/28/20
to tiddl...@googlegroups.com
Thanks all! I figured it out! 

Mark - you were correct. I needed to get rid of any line breaks so that the resulting file was all just one line.

If anyone else wants to use my program, here it is: https://github.com/sweenejp/files/blob/master/isbn_to_json_for_tiddlywiki.py and an example of an output file here:https://github.com/sweenejp/files/blob/master/Cosmos.json

Sorry the python code is a little messy (I'm very much a beginner at coding). I made everything a field and then had certain fields transcluded into the text field. You can change the fields to whatever you want (for instance the "tags" field). 

Pretty cool to know that TiddlyWiki files are basically like Python dictionaries. Now that I say that, I'm sure there would have been a much cleaner way to write my code. I could have just created a dictionary based on the keys and values that a Tiddler requires. Oh well. 

Thanks for all the help!

--
You received this message because you are subscribed to a topic in the Google Groups "TiddlyWiki" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/tiddlywiki/VCn3kDOmTD4/unsubscribe.
To unsubscribe from this group and all its topics, send an email to tiddlywiki+...@googlegroups.com.


--

Mark S.

unread,
Aug 28, 2020, 12:29:38 PM8/28/20
to TiddlyWiki


Nice Work!

It's been a long time since using Python, but it was one of my favorite languages.

Comments

Since python has a library for everything, I'm thinking they must have a library for JSON. This way you don't have to build your own strings, which is subject to error (as you discovered). Just a thought.

I don't see any error handling. What happens if someone mis-types an ISBN number? Or if "meta" can't find a number (I was just looking for an obscure ISBN yesterday -- it wasn't on Amazon).

It appears you're hard-coding {{!!title}} etc. into the text field. That means if you want to change the appearance you will have to go back to every single tiddler and change it. You might want to consider using tiddlywiki templates instead. 


Have fun!

Jimmy Sweeney

unread,
Aug 28, 2020, 5:17:10 PM8/28/20
to tiddl...@googlegroups.com
Thanks Mark! Adding those things to my TODO. 

This is literally my first ever program that I wrote on my own. So this little script is the equivalent of that first wobbly table that a kid makes in woodworking. I’m just happy that it works!

I actually noticed that there are some not-so-obscure ISBNs that meta can’t find. But there are some other tools in isbnlib for finding books so I’ll look into that as well.  

A little background on why I made this. I have a list of books read/to read on Goodreads that I wanted to import easily into my TiddlyWiki. I also have an xml file of exported posts from Wordpress that I’d like to import to my TW. Now that I know it’s possible I’ll get working on a script that can do that next (unless someone knows of something that can already do that). 

--
You received this message because you are subscribed to a topic in the Google Groups "TiddlyWiki" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/tiddlywiki/VCn3kDOmTD4/unsubscribe.
To unsubscribe from this group and all its topics, send an email to tiddlywiki+...@googlegroups.com.
--
Sent from Gmail Mobile

amreus

unread,
Aug 30, 2020, 11:35:32 AM8/30/20
to TiddlyWiki
Just a suggestion: I wouldn't build the json string manually. I would use a python dict and add the key/value pairs, then let the JSON library serialize it as a json string.

It's the same idea I use only in Ruby for converting my gedcom files to tiddlers.
Reply all
Reply to author
Forward
0 new messages