omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular

    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.


    CSV to mmd table

    Editorial
    2
    11
    6844
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • NikkiSchwartzVB
      NikkiSchwartzVB last edited by ccc

      Someone has, wonderfully, already written a workflow to do this... but I'm not sure how to make it read/parse whathaveyou, this... ?dialect? of csv. http://www.editorial-workflows.com/workflow/5314152700575744/irQIEue3ZJ4

      I'm exporting a spreadsheet from iOS numbers to CSV and then attempting to turn that into a multi markdown table.

      It's not exactly working. I keep thinking I to edit something in the script. I've tried several things, but I get console errors or a table with only one column (these tables need two columns).

      Note: very little knowledge of python...

      Here's a small example of the csv format produced by numbers: (Could this be the problem? The format seems like it might be inconsistent?)

      ,,,,,,"CLIENT'S SHORT-TERM BEHAVIORAL GOALS","
      THERAPIST'S INTERVENTIONS ",,,,,
      "Parents collaborate with therapist in development of a treatment plan, include child in planning, if appropriate.",Establish therapeutic alliance with parents to enhance outcome of treatment.,,,,,
      Help therapist understand child’s development to get a complete picture,Assess problem with parents and record a comprehensive history of the child’s development in order to accurately assess problems.,,,,,
      Help parents become aware of the diagnosis and what to appropriately expect from the child.,Educate parents about the diagnosis,,,,,
      Learn about diagnosis and develop alternative problem solving strategies.,Educate client about the diagnosis and discuss symptomology in order to develop alternate problem solving strategies.,,,,,
      Cooperate in building a genogram to identify familial history and its relationship to ADHD.,Construct a genogram to better understand the family history and its impact on the child.,,,,,
      Improve communication among family members.,Conduct family sessions or refer for family therapy to reduce anger and/or alienation and improve communication skills within the family.,,,,,
      Develop awareness of how parents’ personal theories of ADHD influence their cognition of the problem,Explore parental theories of the problem.,,,,,
      Recognize fears and feelings of negative self-blame related to the problem.,Evaluate parents’ fears and negative feelings of self-blame for the child’s problem.,,,,,
      Parents learn to reach beyond automatic cognitive reactions in viewing the problem.,Expand parental perspective beyond limited cognitive reactions.,,,,,
      Family focus shifts from problem to possible solutions.,"If appropriate, have family imagine a future without the problem and suggest actions that can be taken now to make the future possible.",,,,,
      Parents undergo treatment for underlying problems that may exacerbate child’s condition.,"Explore for underlying problems in parents, (e.g. anxiety, depression) and treat or refer for therapy.",,,,,
      
      1 Reply Last reply Reply Quote 0
      • NikkiSchwartzVB
        NikkiSchwartzVB last edited by

        That's part of the problem, at least.

        Here is a test version, instead of my spreadsheet of goals... it is more consistent by far... but it still isn't creating a table correctly. :-/

        CLIENT'S SHORT-TERM BEHAVIORAL GOALS,THERAPIST'S INTERVENTIONS,,,,,
        Some goal to accomplish something. Someone's got to do something. Just sayin'.,Try everything and do what works. Because something has got to get better sometime. ,,,,,
        Some goal to accomplish something. Someone's got to do something. Just sayin'.,Try everything and do what works. Because something has got to get better sometime. ,,,,,
        Some goal to accomplish something. Someone's got to do something. Just sayin'.,Try everything and do what works. Because something has got to get better sometime. ,,,,,
        Some goal to accomplish something. Someone's got to do something. Just sayin'.,Try everything and do what works. Because something has got to get better sometime. ,,,,,
        Some goal to accomplish something. Someone's got to do something. Just sayin'.,Try everything and do what works. Because something has got to get better sometime. ,,,,,

        1 Reply Last reply Reply Quote 0
        • ccc
          ccc last edited by

          It might be helpful to simplify your data initially so you can see the forest from the trees... Consider this Numbers CSV export:

          A,B,C,D,E,F
          0,1,2,3,4,5
          a,b,c,d,e,f
          ,,,,,
          ,,,,,
          ,,,,,
          

          CSVs are not rocket science as long as your data (in each cell) does not include commas or quotes. If commas and quotes are present Numbers and the Python CSV module will do a pretty good job of properly escaping them in consistent ways.

          With a simpler dataset, can you demonstrate where the Tabify workflow is doing the wrong thing?

          1 Reply Last reply Reply Quote 0
          • NikkiSchwartzVB
            NikkiSchwartzVB last edited by

            @ccc Simplifying would be fantastic. I have all of these treatment plans already written up for a variety of diagnoses in word files as tables. So, to simplify, I might as well rewrite them anyways... which I (really) don't want to do. I have about 10-12 treatment plans I use on a regular basis, but 30 or so treatment plans I would need to rewrite to simplify.

            I copy and pasted them into numbers and then exported to CSV.

            I am not sure how to make this work in a simple, not effort intensive fashion.

            Think. Think. Think.

            1 Reply Last reply Reply Quote 0
            • NikkiSchwartzVB
              NikkiSchwartzVB last edited by

              Here is something simpler:
              Some data here,Some data there,,,,,
              Do something.,Try something else,,,,,
              Do a.,Try something a,,,,,
              Do b.,Try something b,,,,,
              Do c.,Try something c,,,,,
              Do d.,Try something d,,,,,
              Do e.,Try something e,,,,,

              Produces:
              (Even if the 5 commas are shortened first to 1 comma... had to replace some text... got flagged as spam?)

              ''' Some data here,Some data there,
              Do something.,Try something else,
              Do something.,Try something else,
              Do something.,Try something else,
              Do something.,Try something else,
              Do something.,Try something else,
              Do something.,Try something else,
              Do something.,Try something else,
              Do something.,Try something else,
              Do something.,Try something else,
              Do something.,Try something else, '''
              1 Reply Last reply Reply Quote 0
              • ccc
                ccc last edited by

                Perfect. I will work up something.

                1 Reply Last reply Reply Quote 0
                • NikkiSchwartzVB
                  NikkiSchwartzVB last edited by

                  I did find a workaround of sorts... I can copy and paste the table into tablesgenerator.com, which converts nicely, even with all of the potential issues.

                  I have one final issue on this front. I need this table to have some kind of visible borders when converted to PDF. Currently the PDF converter shows no borders for mmd tables. Ideas?

                  1 Reply Last reply Reply Quote 0
                  • ccc
                    ccc last edited by ccc

                    Workflow: csv_to_md_table http://www.editorial-workflows.com/workflow/5903925597175808/9VyhSkEy50k

                    # coding: utf-8
                    import csv
                    import workflow
                    
                    
                    def md_table_row(row):
                        return '| {} |'.format(' | '.join(row))
                    
                    
                    def csv_to_md_table(data):
                        assert data.strip(), 'Select some csv data to be converted.'
                        rows = []
                        for i, row in enumerate(csv.reader(x.rstrip(',') for x in data.splitlines()
                                                           if x.rstrip(','))):
                            rows.append(md_table_row(row))
                            if i == 0:
                                rows.append(md_table_row('---' for cell in row))
                        return '\n'.join(('---', '\n'.join(rows), '---'))
                    
                    
                    workflow.set_output(csv_to_md_table(workflow.get_input()))
                    
                    1 Reply Last reply Reply Quote 0
                    • NikkiSchwartzVB
                      NikkiSchwartzVB last edited by

                      That did a much better job of creating the table... 2 things... I need grid lines the be throughout the table. It's not very readable without that. I thought about trying to make the table into two numbered lists, so each line could be matched that way. But it would be much easier if it could be matched visually with grid lines or thin lines between each row.

                      I also need it to be part of the overall final report in PDF, not a file by itself... I could just take out the last action in the workflow, I think to get the md table, but then I wouldn't be able to set it up to have the borders/grid... any ideas?

                      I've finished the first version of this process and am starting to write these reports today. We'll see how it goes.

                      1 Reply Last reply Reply Quote 0
                      • ccc
                        ccc last edited by ccc

                        Borders are easy... You add them at the HTML step...

                        workflow.set_output(workflow.get_input().replace('<table>', '<table border=1>'))
                        

                        See updates at http://www.editorial-workflows.com/workflow/5903925597175808/9VyhSkEy50k

                        1 Reply Last reply Reply Quote 1
                        • NikkiSchwartzVB
                          NikkiSchwartzVB last edited by

                          And soooooooo.....

                          Here is a workflow for this step of my process. http://www.editorial-workflows.com/workflow/5771846762889216/xI4LXsctvGg

                          The csv is exported from iOS Numbers into editorial. This workflow takes the file contents of that csv (which is default named Blank.csv) and converts it to a mmd table, adds borders in the HTML step. Replaces the csv text with the mmd table... and in the shared workflow outputs to a PDF file. I'll save that step until I'm done with the whole report.

                          All python thanks to @ccc , who is effing fantastic.

                          💃🏻🕺🏼💥🌟✨💫🍾🥂🎆🎇🎉

                          1 Reply Last reply Reply Quote 1
                          • First post
                            Last post
                          Powered by NodeBB Forums | Contributors