Handling text in Max. Using [text] to edit html files. CAN it be done?????

davidestevens's icon

It's starting to look like creating an auto video recorder/uploader in Max isn't going to work :(

The third bit of the process (after uploading, which works, and recording video, which has problems) is modifying an existing html file (on local disc) to add in filenames for newly recorded files, and modifying the page name to create a new page on the server.

So I load the page file into [text] and everything in there looks hunkydory.
The problem is that most (but not all) quote marks are stripped from the output of text. so<br />
becomes<br /><style type=text/css><br />
If [text] would output exactly what's in the file I could either convert each line to a single symbol, or use [atoi] and [itoa] to achieve a similar result, which I'm guessing would preserve the quote marks. I fact, thinking about it, it would probably work best to do the whole process as strings of integers, and then convert back to ascii at the input to the output [text] object (assuming that doesn't strip out any quote marks.)<br />
Are there any other ways of storing and modifying big chunks of text that I haven't thought of?</p><p>And it just now occurs to me that [text] would be saving a .txt file, and there's no way within max to change the file identifier to .html. Sigh.</p><p>(Summary - I want to load a template html file and replace specific lines with user input (page name and file name mostly). Then save the resulting new html file and upload it to my server.<br />
At the moment I've tried this by using [route] to send the specific lines I want to change via sprintf objects containing the whole of the modified line, (and escaping any quote marks with \ ), collecting the whole lot (modified and unmodified lines) in a coll, sorting the coll, and then dumping everything to a second [text] object.)</p><p>Here's the ptch (inc text of html file)</p><patcher data-format="juceb64_zip_json" data-id="8b9faae14a3d71ba2a922e4aa245d50f"></patcher>

Mike S's icon

Yeah, the text object probably isn't going to work here (happy to be corrected). I wonder if this would be better done in Python? Maybe Nick Rothwell can chime in... https://cycling74.com/tools/python/

davidestevens's icon

Do you think Python would be a better bet than JS? Given that I don't know either, which do you think I should attempt to get my head around?

Mike S's icon

I would have a go at whichever you feel comfortable with. I only mentioned Python as I wrote a little script in it recently and found it pretty simple to work with.

It also looks like you could use Java:

davidestevens's icon

ok, thanks Mike. Think I'll wait till I'm feeling a bit more energetic before I tackle that.

Rick's icon

Text will save as .html instead of .txt if you send a message like (write mytest.html)

davidestevens's icon

thanks for that Rick. Useful to know. Pity one can't handle html code in [text]. Hey ho.

Brecht's icon

I have never understood the obviousness with which some people suggest python/js/java/whatever scripting or typed programming language as a means to fix something that should but doesn't work as expected.
Like it is assumed that people just know these things or can pick it up with little to no effort, while the issue is the way the object functions and not whether the person looking for a solution should basically just learn another programming language to solve it.