Workflow - file and texthandling

Did anyone know a good example for file- and/or text-handling?

I like to open the exported data from AutoSleep (saves only the last 12 weeks) (comes as csv) and separate the days week by week in a single file for each week.

Maybe / later combine the data from the seven days of a week and save a average for comparing over longer times.

Or get i better started and learn some Swift?

It is all possible with Workflow. But it isn’t geared towards parsing text so you would have to work at it a little bit.

Try starting with just saving and retrieving a text file in a Workflow. That’ll get you started with the file operations.

In terms of wokri;g with the CSV content I think you’ll either want to use some regular expressions or convert the CSV to JSON and use Workflow’s dictionary.

After that, it would be about looping and using the built in maths functions.

My advice would be to break it down into smaller challenges and build up to this. It shouldn’t take long but just bite off manageable bits before you try the whole solution.

I have a few Workflow examples, maybe the persistent variables will help you with files and there are regular expressions in a lot of the text ones. I’m sure there’s probably a dictionary example in there somewhere and there"s one about stats that might help too.

1 Like

Thanks @sylumer i will look into the examples.

You might consider an alternative with better text handling support. Pythonista maybe?

3 Likes

Just to add to @ChrisUpchurch’s comment, here is Pythonista’s documentation on the csv module. It should do exactly what you’re looking for and can be run as a share sheet extension as well.

1 Like

I’d read the title as the OP wanting to use Workflow to do this. I would absolutely agree that Pythonista would be better suited.

Hopefully the switch to Shortcuts will make the term “Workflow” less ambiguous :laughing:

1 Like

I read it the same way. I just wanted to suggest that Workflow might not be the best tool for what he wants to do.

A quote often attributed to Henry Ford:

If I had asked people what they wanted, they would have said faster horses.

I would personally agree that Pythonista is the better tool for the job, though this can be done in Workflow it’s nowhere near as efficient or flexible.

Agreed.

Just to play devil’s advocate for a monent :japanese_ogre:

But if you have a horse, know how to ride and want to get there as soon as possible, sometimes it can be quicker to just go by horse because that’s what you have right now and know how to use. The time it would take to get the car, learn how to use it and get there would be longer. Worth it in the longer term, possibly (almost certainly), but sometimes you just need to get there.

FWIW I don’t drive :rofl:

1 Like

Thanks guys, downloading Pythonista right now to my iPad. :slight_smile: Looks like the better way to manage text/csv than Workflow-app. Why not learn a new language right now.

1 Like