Fixed pulling of notes when API returns NULL
This commit is contained in:
@@ -109,6 +109,7 @@ namespace URLNotesGrabberCORE
|
||||
connection.Close();
|
||||
}
|
||||
}
|
||||
|
||||
public static void AddPost(string blogName, long postID, string reblogURL, string postDate, string postURL, string slug, string reblogKey, string reblogName, string summary, string quote, string body, string tags, string link, string photoURL, string photoCaption, string downloadedFiles, string audioCaption, string question, string answer, string title, bool hasImage, string DBPath = @"TL.db")
|
||||
{
|
||||
try { AddBlog(blogName, DBPath); } catch { }
|
||||
@@ -208,7 +209,6 @@ namespace URLNotesGrabberCORE
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static bool AddNote(string rootBlogName, string noteBlogName, long postID, long timestamp, string type, string DBPath = @"TL.db")
|
||||
{
|
||||
//try { AddPost(rootBlogName, postID, DBPath); } catch { }
|
||||
@@ -323,6 +323,7 @@ namespace URLNotesGrabberCORE
|
||||
}
|
||||
return posts;
|
||||
}
|
||||
|
||||
public static List<Tuple<string, long>> GetReplies(string DBPath = @"TL.db")
|
||||
{
|
||||
SQLiteConnection connection = new SQLiteConnection("Data Source=" + DBPath);
|
||||
@@ -365,7 +366,6 @@ namespace URLNotesGrabberCORE
|
||||
return posts;
|
||||
}
|
||||
|
||||
|
||||
public static int GetAPICount(string DBPath = @"TL.db")
|
||||
{
|
||||
SQLiteConnection connection = new SQLiteConnection("Data Source=" + DBPath);
|
||||
@@ -407,7 +407,6 @@ namespace URLNotesGrabberCORE
|
||||
return count;
|
||||
}
|
||||
|
||||
|
||||
public static List<string> GetBlogs(bool reblogsOnly, int from, int to, int top, string DBPath = @"TL.db")
|
||||
{
|
||||
SQLiteConnection connection = new SQLiteConnection("Data Source=" + DBPath);
|
||||
@@ -447,7 +446,6 @@ namespace URLNotesGrabberCORE
|
||||
return blogs;
|
||||
}
|
||||
|
||||
|
||||
public static List<string> GetBlogsAll(bool reblogsOnly, int from, int to, int top, string DBPath = @"TL.db")
|
||||
{
|
||||
SQLiteConnection connection = new SQLiteConnection("Data Source=" + DBPath);
|
||||
@@ -515,7 +513,6 @@ namespace URLNotesGrabberCORE
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static void UpdatePostMarkNotFound(string blogName, long postID, string DBPath = @"TL.db")
|
||||
{
|
||||
SQLiteConnection connection = new SQLiteConnection("Data Source=" + DBPath);
|
||||
@@ -540,7 +537,6 @@ namespace URLNotesGrabberCORE
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static void UpdatePostSetDate(string blogName, long postID, string postDate, string DBPath = @"TL.db")
|
||||
{
|
||||
SQLiteConnection connection = new SQLiteConnection("Data Source=" + DBPath);
|
||||
@@ -565,7 +561,6 @@ namespace URLNotesGrabberCORE
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static bool UpdateNote(string rootBlogName, string noteBlogName, long postID, long timestamp, string type, string DBPath = @"TL.db")
|
||||
{
|
||||
//try { AddPost(rootBlogName, postID, DBPath); } catch { }
|
||||
@@ -600,7 +595,6 @@ namespace URLNotesGrabberCORE
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public static void UpdatePost(string blogName, long postID, string reblogURL, string postDate, string postURL, string slug, string reblogKey, string reblogName, string summary, string quote, string body, string tags, string link, string photoURL, string photoCaption, string downloadedFiles, string audioCaption, string question, string answer, string title, bool hasImage, string DBPath = @"TL.db")
|
||||
{
|
||||
SQLiteConnection connection = new SQLiteConnection("Data Source=" + DBPath);
|
||||
@@ -646,7 +640,6 @@ namespace URLNotesGrabberCORE
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static void UpdateBlogOutput(string blogName, string DBPath = @"TL.db")
|
||||
{
|
||||
SQLiteConnection connection = new SQLiteConnection("Data Source=" + DBPath);
|
||||
@@ -671,7 +664,6 @@ namespace URLNotesGrabberCORE
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static int UpdateAPICount(string DBPath = @"TL.db")
|
||||
{
|
||||
SQLiteConnection connection = new SQLiteConnection("Data Source=" + DBPath);
|
||||
|
||||
@@ -74,6 +74,38 @@ namespace URLNotesGrabberCORE
|
||||
var response = APIAccess.GrabNotes(blogName, postID).GetAwaiter().GetResult();
|
||||
List<Tuple<string, string>> notes = new List<Tuple<string, string>>();
|
||||
|
||||
// Check for API errors
|
||||
if (response.statusCode == "NotFound")
|
||||
{
|
||||
Console.WriteLine($"ERROR: Post not found - {blogName}/{postID}");
|
||||
break;
|
||||
}
|
||||
if (response.statusCode == "TooManyRequests")
|
||||
{
|
||||
Console.WriteLine($"ERROR: Rate limited - retry in {response.retryInSeconds} seconds");
|
||||
break;
|
||||
}
|
||||
if (!string.IsNullOrEmpty(response.statusCode))
|
||||
{
|
||||
Console.WriteLine($"ERROR: API returned status code: {response.statusCode}");
|
||||
break;
|
||||
}
|
||||
|
||||
// Check for null response
|
||||
if (response.response == null)
|
||||
{
|
||||
Console.WriteLine("ERROR: API response is null");
|
||||
break;
|
||||
}
|
||||
|
||||
// Check for null notes
|
||||
if (response.response.notes == null)
|
||||
{
|
||||
Console.WriteLine("ERROR: Notes collection is null (post may have 0 notes)");
|
||||
break;
|
||||
}
|
||||
|
||||
Console.WriteLine($"Processing {response.response.notes.Count} notes...");
|
||||
foreach (var note in response.response.notes)
|
||||
{
|
||||
note.reblog_parent_blog_name = blogName; note.post_id = postID.ToString();
|
||||
@@ -86,6 +118,13 @@ namespace URLNotesGrabberCORE
|
||||
{
|
||||
response = APIAccess.GrabNotes(blogName, postID, response.response._links.next.query_params.before_timestamp).GetAwaiter().GetResult();
|
||||
|
||||
if (response.response?.notes == null)
|
||||
{
|
||||
Console.WriteLine("ERROR: Notes collection became null during pagination");
|
||||
break;
|
||||
}
|
||||
|
||||
Console.WriteLine($"Processing {response.response.notes.Count} more notes...");
|
||||
foreach (var note in response.response.notes)
|
||||
{
|
||||
note.reblog_parent_blog_name = blogName; note.post_id = postID.ToString(); ;
|
||||
@@ -94,6 +133,8 @@ namespace URLNotesGrabberCORE
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Console.WriteLine("Test completed successfully");
|
||||
#endregion
|
||||
|
||||
break;
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user