diff --git a/URLNotesGrabberCORE/DataAccess.cs b/URLNotesGrabberCORE/DataAccess.cs index 30c6bcb..c12f78c 100644 --- a/URLNotesGrabberCORE/DataAccess.cs +++ b/URLNotesGrabberCORE/DataAccess.cs @@ -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> 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 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 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); diff --git a/URLNotesGrabberCORE/Program.cs b/URLNotesGrabberCORE/Program.cs index 6ae07ea..bb9fad2 100644 --- a/URLNotesGrabberCORE/Program.cs +++ b/URLNotesGrabberCORE/Program.cs @@ -74,6 +74,38 @@ namespace URLNotesGrabberCORE var response = APIAccess.GrabNotes(blogName, postID).GetAwaiter().GetResult(); List> notes = new List>(); + // 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; diff --git a/URLNotesGrabberCORE/TL.db b/URLNotesGrabberCORE/TL.db index 877b2cd..c8b6a85 100644 Binary files a/URLNotesGrabberCORE/TL.db and b/URLNotesGrabberCORE/TL.db differ diff --git a/URLNotesGrabberCORE/TL.db-journal b/URLNotesGrabberCORE/TL.db-journal deleted file mode 100644 index 906fd7d..0000000 Binary files a/URLNotesGrabberCORE/TL.db-journal and /dev/null differ