person-key-to-immich-import birthday json (Day-Helper-2024-05-18)
csharp_prefer_braces = true
This commit is contained in:
@ -1,8 +1,7 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Text.Json;
|
||||
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace File_Folder_Helper.ADO2025.PI5;
|
||||
|
||||
internal static partial class Helper20250228 {
|
||||
@ -15,18 +14,20 @@ internal static partial class Helper20250228 {
|
||||
string headerB = args[4].Replace('_', ' ');
|
||||
string sourceDirectory = Path.GetFullPath(args[0]);
|
||||
string[] files = Directory.GetFiles(sourceDirectory, searchPattern, SearchOption.AllDirectories);
|
||||
if (files.Length != 1)
|
||||
if (files.Length != 1) {
|
||||
logger.LogWarning("<{files}>(s)", files.Length);
|
||||
else
|
||||
} else {
|
||||
PostgresDumpToJson(logger, headerA, headerB, files[0]);
|
||||
}
|
||||
}
|
||||
|
||||
private static void PostgresDumpToJson(ILogger<Worker> logger, string headerA, string headerB, string file) {
|
||||
ReadOnlyCollection<Record> records = GetRecords(headerA, headerB, file);
|
||||
if (records.Count > 0)
|
||||
if (records.Count > 0) {
|
||||
WriteFile(file, records);
|
||||
else
|
||||
} else {
|
||||
logger.LogWarning("<{records}>(s)", records.Count);
|
||||
}
|
||||
}
|
||||
|
||||
private static ReadOnlyCollection<Record> GetRecords(string headerA, string headerB, string file) {
|
||||
@ -46,32 +47,38 @@ internal static partial class Helper20250228 {
|
||||
line = lines[i];
|
||||
if (tableName is null) {
|
||||
segmentsA = line.Split(headerA);
|
||||
if (segmentsA.Length != 2)
|
||||
if (segmentsA.Length != 2) {
|
||||
continue;
|
||||
}
|
||||
segmentsB = segmentsA[1].Split(headerB);
|
||||
if (segmentsB.Length != 2)
|
||||
if (segmentsB.Length != 2) {
|
||||
continue;
|
||||
}
|
||||
segmentsC = segmentsB[0].Split('(');
|
||||
if (segmentsC.Length != 2)
|
||||
if (segmentsC.Length != 2) {
|
||||
continue;
|
||||
}
|
||||
segmentsD = segmentsC[1].Split(')');
|
||||
if (segmentsD.Length != 2)
|
||||
if (segmentsD.Length != 2) {
|
||||
continue;
|
||||
}
|
||||
columns = segmentsD[0].Split(',').Select(l => l.Trim(' ').Trim('"')).ToArray().AsReadOnly();
|
||||
if (columns.Count == 0)
|
||||
if (columns.Count == 0) {
|
||||
continue;
|
||||
}
|
||||
segmentsE = segmentsB[0].Split(' ');
|
||||
tableName = segmentsE[0];
|
||||
} else if (columns is null)
|
||||
} else if (columns is null) {
|
||||
break;
|
||||
else {
|
||||
} else {
|
||||
rows = [];
|
||||
for (int j = i + 1; j < lines.Length; j++) {
|
||||
i = j;
|
||||
segmentsF = lines[j].Split('\t');
|
||||
if (segmentsF.Length != columns.Count) {
|
||||
if (rows.Count > 0)
|
||||
if (rows.Count > 0) {
|
||||
results.Add(new(TableName: tableName, Columns: columns, Rows: rows.AsReadOnly()));
|
||||
}
|
||||
break;
|
||||
}
|
||||
rows.Add(segmentsF);
|
||||
@ -93,10 +100,11 @@ internal static partial class Helper20250228 {
|
||||
foreach (string[] row in record.Rows) {
|
||||
keyValuePairs.Clear();
|
||||
for (int i = 0; i < row.Length; i++) {
|
||||
if (row[i] == "\\N")
|
||||
if (row[i] == "\\N") {
|
||||
keyValuePairs.Add(record.Columns[i], null);
|
||||
else
|
||||
} else {
|
||||
keyValuePairs.Add(record.Columns[i], row[i]);
|
||||
}
|
||||
}
|
||||
#pragma warning disable IL3050, IL2026
|
||||
json = JsonSerializer.Serialize(keyValuePairs);
|
||||
|
Reference in New Issue
Block a user