Exemple #1
0
 public GhoplinApi(string apiUrl, string token)
 {
     _token  = token;
     _apiUrl = apiUrl;
     _joplin = new JoplinService(_apiUrl, _token);
     _ghost  = new GhostService();
 }
Exemple #2
0
        private async Task <int> ProcessSingleBlog(JoplinService joplin, GhostService ghost, BlogConfig blogConfig, List <Tag> allTags)
        {
            Log.Information("Processing blog {blogTitle} @ {blogUrl}", blogConfig.Title, blogConfig.BlogUrl);
            var now      = DateTime.UtcNow;
            int newPosts = 0;

            foreach (var note in await ghost.LoadBlogPostsSince(blogConfig.BlogUrl, blogConfig.ApiKey, blogConfig.LastFetch))
            {
                try
                {
                    Log.Information("Adding note {noteName}", note.Title);
                    var noteId = await joplin.CreateNote(blogConfig.NotebookId, note);

                    await Task.Delay(1900);

                    Log.Debug("Created note with ID {noteId}", noteId);
                    newPosts++;

                    await AddNoteTags(joplin, blogConfig, allTags, note);

                    blogConfig.LastFetch       = note.Timestamp ?? now;
                    blogConfig.LastFetchedPost = $"[{note.Title}](:/{note.Id})";
                }
                catch (Exception ex)
                {
                    Log.Error(ex, "Error while processing note {noteTitle}", note.Title);
                    continue;
                }
            }
            blogConfig.LastFetch   = now;
            blogConfig.NotesTotal += newPosts;
            return(newPosts);
        }