Skip to content

Commit

Permalink
fix(letterboxd): improved parsing of custom list csv files
Browse files Browse the repository at this point in the history
  • Loading branch information
damienhaynes committed Apr 24, 2022
1 parent abf8155 commit af7aa5a
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 6 deletions.
6 changes: 3 additions & 3 deletions Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("TraktRater")]
[assembly: AssemblyCopyright("Copyright © 2012-2020")]
[assembly: AssemblyCopyright("Copyright © 2012-2022")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

Expand All @@ -31,5 +31,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("2.3.10.2")]
[assembly: AssemblyFileVersion("2.3.10.2")]
[assembly: AssemblyVersion("2.3.11.0")]
[assembly: AssemblyFileVersion("2.3.11.0")]
36 changes: 33 additions & 3 deletions Sites/Letterboxd.cs
Original file line number Diff line number Diff line change
Expand Up @@ -357,10 +357,40 @@ private void SetCSVHelperOptions()
/// <returns>Records of type T</returns>
private List<T> ParseCsvFile<T>( string aFilename )
{
using ( var reader = new StreamReader( aFilename ) )
int lStartLine = 0;
bool lValidCsv = true;
using (var reader = new StreamReader(aFilename))
{
// skip over the first 4 records to where the list records start
for ( var i = 0; i < 4; i++ )
// skip over the first few records until the list records start
string lLine = string.Empty;
do
{
lLine = reader.ReadLine();
lStartLine++;

// protect against dodgy file
// typically there is 4 rows of meta data
if (lStartLine > 50)
{
lValidCsv = false;
break;
}
}
while (!lLine.Contains("Position,Name,Year,URL,Description"));
}

if (!lValidCsv)
{
FileLog.Info($"Unable to find header row of custom list after {lStartLine} rows");
return null;
}

FileLog.Info($"Found column headers on row {lStartLine}");

using (var reader = new StreamReader(aFilename))
{
// get to relavent part of file
for (int i = 0; i < lStartLine - 1; i++)
{
reader.ReadLine();
}
Expand Down

1 comment on commit af7aa5a

@damienhaynes
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolves: #141

Please sign in to comment.