Skip to content

Commit 89d0bae

Browse files
committed
#1 Starting work on this Issue. Got the user prompt and creation of csv-import status page created
1 parent 6ea4d99 commit 89d0bae

File tree

2 files changed

+35
-12
lines changed

2 files changed

+35
-12
lines changed

CSV-to-Roam-table-md.ps1

+35-12
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
#v0.2.1
2-
#Version Comments: First working version to be tested
1+
#v0.2.2
2+
#Version Comments: Starting creation of page names for each CSV table row
33
#Repository: https://github.com/GitMurf/csv-to-roam-table-md
44
#Code written by: Murf
55
#Design/Concept by: Rob Haisfield @RobertHaisfield on Twitter
@@ -16,10 +16,21 @@ $bulletType = "-"
1616
#Set the delimiter variable (default is "," comma)
1717
$strDelim = ","
1818

19+
#Add a blank line for easier reading of prompts in powershell window
20+
Write-Host
21+
22+
#Ask for user input to create pages for each row, otherwise will just default to creating a single markdown file with the table markdown for Roam
23+
$respPages = Read-Host "Do you want to create a Page for each Row in the CSV file? (Enter y or n)"
24+
25+
#Check if user decided to create new pages (e.g., a CRM import)
26+
if($respPages -eq "y" -or $respPages -eq "Y" -or $respPages -eq "yes" -or $respPages -eq "Yes"){$bPages = $true}else{$bPages = $false}
27+
28+
#Add a blank line for easier reading of prompts in powershell window
29+
Write-Host
30+
1931
#Ask for user input. If left blank and user presses ENTER, then continue with default (comma). Otherwise they can enter their own option.
2032
$respDelim = Read-Host "Default CSV Delimiter is '$strDelim' (comma). Press ENTER to Continue or input 'n' to change it."
2133

22-
#Add a blank line for easier reading of prompts in powershell window
2334
Write-Host
2435

2536
#Check if user decided to change to a different delimiter
@@ -29,7 +40,6 @@ if($respDelim -eq "n" -or $respDelim -eq "N" -or $respDelim -eq "'n'" -or $respD
2940
if($strDelim -eq "TAB" -or $strDelim -eq "tab" -or $strDelim -eq "'TAB'" -or $strDelim -eq "'tab'"){$strDelim = "`t"}
3041
}
3142

32-
#Add a blank line for easier reading of prompts in powershell window
3343
Write-Host
3444

3545
#Get path where script is running from so you can target CSV
@@ -38,7 +48,6 @@ $scriptPath = split-path -parent $MyInvocation.MyCommand.Definition
3848
#Ask for user input. If left blank and user presses ENTER, then use the script path. Otherwise they can enter their own custom path.
3949
$respPath = Read-Host "Is your target CSV file located here: '$scriptPath'? Press ENTER to Continue or input 'n' to change it."
4050

41-
#Add a blank line for easier reading of prompts in powershell window
4251
Write-Host
4352

4453
#Check if user decided to change to a different path
@@ -47,34 +56,48 @@ if($respPath -eq "n" -or $respPath -eq "N" -or $respPath -eq "'n'" -or $respPath
4756
$scriptPath = Read-Host "Enter the folder path of your CSV file (do NOT include the file name)"
4857
}
4958

50-
#Add a blank line for easier reading of prompts in powershell window
5159
Write-Host
5260

5361
#Get the file name from user and create the full path
5462
$fileNameStr = Read-Host "Name of CSV file with extension? Do NOT include path. Example: FileName.csv"
5563
$fileNameStrPath = $scriptPath + "\" + $fileNameStr
5664

57-
#Add a blank line for easier reading of prompts in powershell window
5865
Write-Host
5966

67+
#Set the Results folder to store all the outputs from the script
68+
$resultsFolder = "$scriptPath\Results"
69+
6070
#Get a date string down to the second we can add to new markdown file we will be creating so no duplicates if we run multiple times
6171
$fullDateStr = get-date
6272
$dateStrName = $fullDateStr.ToString("yyyy_MM_dd-HH_mm_ss")
63-
$newMarkdownFile = "$scriptPath\" + "$fileNameStr" + "_$dateStrName.md"
73+
$csvFileName = "$fileNameStr" + "_$dateStrName"
74+
$newMarkdownFile = "$resultsFolder\" + "csvFileName" + ".md"
6475

76+
#If $bPages -eq $true, then create the csv-import page name to store all the info about this import and the pages it creates
77+
if($bPages)
78+
{
79+
$csvImportName = "[[csv-import]] - " + $csvFileName
80+
$csvImportNamePath = "$resultsFolder\" + "$csvImportName" + ".md"
81+
#Create Results folder if it doesn't already exist
82+
if(!(Test-Path $resultsFolder)){New-Item -ItemType Directory -Force -Path $resultsFolder | Out-Null}
83+
#Write attribute for csv-import to first line of this new .md file (need to use LiteralPath parameter because of [[]] characters in path)
84+
Add-content -LiteralPath $csvImportNamePath -value ("csv-import:: " + "[[April 25th, 2020]]")
85+
}
86+
Read-Host -Prompt "Script complete. Press any key to exit."
87+
Exit
6588
#Import .CSV file into a Variable to loop through and parse
6689
$csvObject = Import-Csv -Delimiter $strDelim -Path "$fileNameStrPath"
6790

6891
#Collapse the entire table under a parent bullet with name of the CSV file
6992
$tableCell = "TABLE IMPORT FROM CSV: " + $fileNameStr
7093
$tableCell = $bulletType + $tableCell
71-
Add-content $newMarkdownFile -value $tableCell
94+
Add-content -LiteralPath $newMarkdownFile -value $tableCell
7295

7396
#Add {{table}}
7497
$tableCell = "{{table}}"
7598
$tableCell = $bulletType + $tableCell
7699
$tableCell = $indentType + $tableCell
77-
Add-content $newMarkdownFile -value $tableCell
100+
Add-content -LiteralPath $newMarkdownFile -value $tableCell
78101

79102
#Start by adding the table header to the markdown results file
80103
$ctr = 2
@@ -90,7 +113,7 @@ foreach($col in $csvObject[0].psobject.properties.name)
90113
$tmpCtr = $tmpCtr - 1
91114
}
92115

93-
Add-content $newMarkdownFile -value $tableCell
116+
Add-content -LiteralPath $newMarkdownFile -value $tableCell
94117
$ctr = $ctr + 1
95118
}
96119

@@ -113,7 +136,7 @@ foreach($row in $csvObject)
113136
$tmpCtr = $tmpCtr - 1
114137
}
115138

116-
Add-content $newMarkdownFile -value $tableCell
139+
Add-content -LiteralPath $newMarkdownFile -value $tableCell
117140
$ctr = $ctr + 1
118141
}
119142
}

Roam testing TEMP - Shortcut.lnk

808 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)