Welcome!
This is the community forum for my apps Pythonista and Editorial.
For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.
Pythonista, iOS Shortcuts, & UTF-16LE! Oh my!
-
I’m working on an iOS shortcut that imports a CSV into Apple Health from a CGM that doesn’t connect directly to Apple Health.
I’m new to iOS shortcuts and Pythonista, but I thought this would be a nice project to get familiar with both.
I’ve got the logic of processing the CSV with Shortcuts and adding the data to Apple Health. The problem is that the source file is a CSV which iOS shortcuts appears to choke on. It literally crashes.
If I pre-process the file using bash on macOS with something similar to the following everything works fine:
iconv -f UTF-16LE -t UTF-8 data.csv > conv_data.csv
I can use the resulting conv_data.csv file with Shortcuts easily. I can read the file, remove unneeded lines, read the header and import each line as an Apple Health entry.
But I obviously don’t want to go to my Mac every time I do an import.
Enter Pythonista...
Should I look at Pythonista to pre-process the file? If so, what’s the code look like?
Any help for a newbie would be greatly appreciated!!!
-
@melmaninga try this, not tested
# iconv -f UTF-16LE -t UTF-8 data.csv > conv_data.csv import shutil with open("data.csv", mode="r", encoding="utf-16-le") as inp: #f = fil.read() with open("conv_data.csv", mode="w", encoding="utf-8") as out: #fil.write(f) shutil.copyfileobj(inp, out)
-
@cvp you nailed it. Thanks, mate!