CreateImportFiles
This commit is contained in:
parent
22797ad4bf
commit
3888ae1083
5
.vscode/launch.json
vendored
5
.vscode/launch.json
vendored
@ -44,6 +44,7 @@
|
|||||||
// dotnet run "s" "D:/Documents/Obsidian/Infineon/.kanbn"
|
// dotnet run "s" "D:/Documents/Obsidian/Infineon/.kanbn"
|
||||||
// dotnet run "s" "L:/Git/View-by-Distance-MKLink-Console/.kanbn"
|
// dotnet run "s" "L:/Git/View-by-Distance-MKLink-Console/.kanbn"
|
||||||
// dotnet run "s" "T:/MESAFIBACKLOG/06_SourceCode/MESAFIBACKLOG/Adaptation/.kanbn"
|
// dotnet run "s" "T:/MESAFIBACKLOG/06_SourceCode/MESAFIBACKLOG/Adaptation/.kanbn"
|
||||||
// dotnet run "s" "D:/Documents/Projects/EC Documentation - Foam/.kanbn"
|
// dotnet run "s" "D:/Documents/Projects/EC-Documentation - Foam/.kanbn"
|
||||||
// dotnet run "s" "D:/Documents/Notes/Infineon"
|
// dotnet run "s" "D:/Documents/Notes/Infineon"
|
||||||
// dotnet run "s" "D:/5-Other-Small/Notes/Infineon/.kanbn"
|
// dotnet run "s" "D:/5-Other-Small/Notes/Infineon/.kanbn"
|
||||||
|
// dotnet run "s" "D:/Documents/Projects/EC-Documentation"
|
@ -1,4 +1,5 @@
|
|||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
namespace File_Folder_Helper.Helpers;
|
namespace File_Folder_Helper.Helpers;
|
||||||
|
|
||||||
@ -52,14 +53,12 @@ internal static class HelperCreateNoteFiles
|
|||||||
_ = HelperDeleteEmptyDirectories.DeleteEmptyDirectories(directory);
|
_ = HelperDeleteEmptyDirectories.DeleteEmptyDirectories(directory);
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static void CreateNoteFiles(string argsZero)
|
private static void CreateDailyNotes(string argsZero, long ticks)
|
||||||
{
|
{
|
||||||
string file;
|
string file;
|
||||||
string directory;
|
string directory;
|
||||||
string weekOfYear;
|
string weekOfYear;
|
||||||
DateTime dateTime;
|
DateTime dateTime;
|
||||||
long ticks = DateTime.Now.Ticks;
|
|
||||||
CleanExistingFiles(argsZero, ticks);
|
|
||||||
string lastDirectory = string.Empty;
|
string lastDirectory = string.Empty;
|
||||||
DateTime startDateTime = DateTime.Now.AddDays(1);
|
DateTime startDateTime = DateTime.Now.AddDays(1);
|
||||||
Calendar calendar = new CultureInfo("en-US").Calendar;
|
Calendar calendar = new CultureInfo("en-US").Calendar;
|
||||||
@ -97,4 +96,112 @@ internal static class HelperCreateNoteFiles
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void CreateImportFiles(long ticks, List<string> importFiles)
|
||||||
|
{
|
||||||
|
bool csv;
|
||||||
|
bool tsv;
|
||||||
|
string file;
|
||||||
|
string type;
|
||||||
|
string title;
|
||||||
|
string[] lines;
|
||||||
|
string[] links;
|
||||||
|
int bodyKey = 4;
|
||||||
|
int typeKey = 0;
|
||||||
|
string linkText;
|
||||||
|
int linksKey = 3;
|
||||||
|
int titleKey = 1;
|
||||||
|
string[] columns;
|
||||||
|
string? directory;
|
||||||
|
string[] segments;
|
||||||
|
int descriptionKey = 2;
|
||||||
|
string destinationDirectory;
|
||||||
|
DateTime dateTime = new(ticks);
|
||||||
|
StringBuilder stringBuilder = new();
|
||||||
|
string csvHeader = "type,title,description,links,body";
|
||||||
|
string tsvHeader = "type\ttitle\tdescription\tlinks\tbody";
|
||||||
|
int expectedCount = csvHeader.Length - csvHeader.Replace(",", string.Empty).Length + 1;
|
||||||
|
foreach (string importFile in importFiles)
|
||||||
|
{
|
||||||
|
csv = false;
|
||||||
|
tsv = false;
|
||||||
|
directory = Path.GetDirectoryName(importFile);
|
||||||
|
if (directory is null)
|
||||||
|
continue;
|
||||||
|
lines = File.ReadAllLines(importFile);
|
||||||
|
for (int i = 0; i < lines.Length; i++)
|
||||||
|
{
|
||||||
|
if (i == 0)
|
||||||
|
{
|
||||||
|
if (lines[i] == csvHeader)
|
||||||
|
(csv, tsv) = (true, false);
|
||||||
|
else if (lines[i] == tsvHeader)
|
||||||
|
(csv, tsv) = (false, true);
|
||||||
|
else
|
||||||
|
break;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (csv)
|
||||||
|
columns = lines[i].Split(',');
|
||||||
|
else if (tsv)
|
||||||
|
columns = lines[i].Split('\t');
|
||||||
|
else
|
||||||
|
continue;
|
||||||
|
if (columns.Length != expectedCount)
|
||||||
|
continue;
|
||||||
|
_ = stringBuilder.Clear();
|
||||||
|
title = columns[titleKey].Trim();
|
||||||
|
linkText = columns[linksKey].Trim();
|
||||||
|
type = columns[typeKey].Trim().ToLower().Replace(' ', '-');
|
||||||
|
if (string.IsNullOrEmpty(linkText))
|
||||||
|
links = Array.Empty<string>();
|
||||||
|
else
|
||||||
|
links = linkText.Split(';', StringSplitOptions.RemoveEmptyEntries);
|
||||||
|
foreach (string link in links)
|
||||||
|
{
|
||||||
|
segments = link.Split(':');
|
||||||
|
if (segments.Length == 1)
|
||||||
|
_ = stringBuilder.AppendLine($"- [[{segments.First()}]]");
|
||||||
|
else if (segments.Length == 2)
|
||||||
|
_ = stringBuilder.AppendLine($"- [{segments.First()}]({segments.Last()})");
|
||||||
|
else
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
destinationDirectory = Path.Combine(directory, type);
|
||||||
|
if (!Directory.Exists(destinationDirectory))
|
||||||
|
_ = Directory.CreateDirectory(destinationDirectory);
|
||||||
|
file = Path.Combine(destinationDirectory, $"{title.ToLower().Replace(' ', '-')}.md");
|
||||||
|
File.WriteAllLines(file, new string[]
|
||||||
|
{
|
||||||
|
"---",
|
||||||
|
$"type: '{type}'",
|
||||||
|
$"title: '{title}'",
|
||||||
|
$"description: '{columns[descriptionKey].Trim()}'",
|
||||||
|
$"created: {dateTime:yyyy-MM-ddTHH:mm:ss.fffZ}",
|
||||||
|
$"updated: {dateTime:yyyy-MM-ddTHH:mm:ss.fffZ}",
|
||||||
|
"---",
|
||||||
|
string.Empty,
|
||||||
|
$"# {title}",
|
||||||
|
string.Empty,
|
||||||
|
stringBuilder.ToString(),
|
||||||
|
string.Empty,
|
||||||
|
columns[bodyKey].Trim(),
|
||||||
|
string.Empty,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
internal static void CreateNoteFiles(string argsZero)
|
||||||
|
{
|
||||||
|
long ticks = DateTime.Now.Ticks;
|
||||||
|
CleanExistingFiles(argsZero, ticks);
|
||||||
|
List<string> importFiles = new();
|
||||||
|
importFiles.AddRange(Directory.GetFiles(argsZero, "*.csv", SearchOption.TopDirectoryOnly));
|
||||||
|
importFiles.AddRange(Directory.GetFiles(argsZero, "*.tsv", SearchOption.TopDirectoryOnly));
|
||||||
|
if (!importFiles.Any())
|
||||||
|
CreateDailyNotes(argsZero, ticks);
|
||||||
|
else
|
||||||
|
CreateImportFiles(ticks, importFiles);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user