Create Tiddler in Standalone TW5 using Python

Hi,

Is there a way to create a Tiddler in Standalone TW5 using Python?

Thanks,
Gt

Welcome @goldtiddler

Any method that allows you to edit the tiddlywiki.html file may work for you, however it all depends on the work flow and your implementation. Your python code could just generate appropriately formatted json files that the live wiki imports (or displays).

In recent releases the internal tiddler storage has changed to a JSON format.

If you are only trying to make something visible in your tiddlywiki you can use your python to create a text or html in a file in the same folder as the wiki that the wiki then displays such as with HTML object tag

The question I would ask is what does your python know that the browser or wiki does not and what do you want to do with this?

So perhaps to advance your question it would help if you explained what you want to achieve rather than a “can I do it this way” type of question.

This may be of interest. TiddlyWikiPharo and critical code/data literacy curriculum - #8 by pmario

Hello TW_Tones,

Python will extract information from a number of sources (text files, web scrapping, databases etc).

Python will process/manipulate this information and then need to create multiple (10 to 30) tiddlers in Standalone TW5.

Source1 -
Source2 |
Source3 |-----> Python ----> Standalone TW5 (TW5_test.html)
Source4 |
Source5 -

As there are many tiddlers to create at one time and each tiddler will include a number of fields/tags, its not feasible to create each tiddlers manually.

Python is the glue between the sources and TW5.

What I would do is to use python to create tiddlers inside a node instance. Then use the tiddlywiki node tools to build the standalone TW file. You can probably even invoke the node tools from one of the python libraries (os?).

It sounds like the approach of stitching the JSON tiddlers into an empty copy of TiddlyWiki (ie empty.html) is viable here. There is some documentation here:

https://tiddlywiki.com/dev/#Data%20Storage%20in%20Single%20File%20TiddlyWiki

There’s an example here (albeit written in JS, not Python):

If you can create a new wiki, as others have suggested their instructions are appropriate.

However if you want to accrue them in the same wiki you will need a way to add them. Your python script output could be the JSON file that is dropped/imported into tiddlywiki ( CSV and other formats are possible using the JSON mangler tools). This final step is manual but keeps the solution very simple.

I think if you want to automate this last step you will probably want a Node tiddlywiki where you can add tiddlers from programs and the shell.

If your python is a reoccurring process you could import the latest updates each time you open the stand alone wiki, perhaps triggering with a startup action the<$browse multiple/> widget to select more than one file for import. This may have the advantage of undertaking a backup before import, and permitting you to deefer import.

Speculation
There may be a way to open a tiddlywiki with a URL that includes an import filename (accessible to the wiki) for which startup actions prompt for import. This filename can be copied to the clipboard and in the file open dialogue use ctrl-V to past the folder or filename into it, then click to open.

As @jeremyruston says stitching the JSON tiddlers into an empty copy of TiddlyWiki, could perhaps be extended to any tiddlywiki file, however in any case you will need to ensure it is not already open in a browser and saved before loading the updated wiki. For this reason I see the manual upload if possible Gives the wiki owner control over the import process and reduces the risks.