DEV Community

Mariano Gobea Alcoba
Mariano Gobea Alcoba

Posted on • Originally published at mgatc.com

CLI RSS/Atom feed reader inspired by Taskwarrior, synced using Git!

Introduction

In the realm of command-line tools, there is a growing trend towards creating lightweight, efficient, and user-friendly applications that can handle complex tasks with minimal overhead. One such tool is blogtato, a CLI RSS/Atom feed reader inspired by Taskwarrior and synchronized using Git. This article delves into the technical aspects of blogtato, exploring its architecture, implementation details, and the benefits it offers over traditional web-based feed readers.

Overview of blogtato

blogtato is designed to be a powerful yet simple command-line interface (CLI) for managing and reading RSS and Atom feeds. It draws inspiration from Taskwarrior, a popular task management tool known for its robustness and flexibility. The key features of blogtato include:

  • CLI Interface: A text-based interface that allows users to manage their feeds and read articles without leaving the terminal.
  • Git Syncing: Synchronization of feed data across multiple devices using Git, ensuring that users have access to their feeds wherever they go.
  • Customizability: Extensive configuration options to tailor the tool to individual preferences.
  • Efficiency: Optimized performance for quick loading and smooth navigation.

Architecture

Data Storage

blogtato stores feed data in a structured format that is easy to manage and sync. The primary storage mechanism is a combination of JSON files and a Git repository. Here’s a breakdown of the data storage architecture:

  • Feeds File: A JSON file (feeds.json) that contains a list of all subscribed feeds, including their URLs and metadata.
  • Articles Directory: A directory (articles/) where each article is stored as a separate JSON file. Each file contains the article's content, publication date, and other relevant information.
  • State File: A JSON file (state.json) that keeps track of read/unread status, bookmarks, and other user-specific data.

Git Synchronization

One of the standout features of blogtato is its use of Git for synchronization. This approach offers several advantages:

  • Version Control: Git provides a robust version control system, allowing users to track changes and revert to previous states if necessary.
  • Cross-Device Syncing: By pushing changes to a remote Git repository, users can easily sync their feed data across multiple devices.
  • Collaboration: Multiple users can collaborate on a shared feed list, making it suitable for team environments.

The synchronization process involves the following steps:

  1. Local Changes: Users make changes to their feed data (e.g., adding a new feed, marking an article as read).
  2. Commit: The changes are committed to the local Git repository.
  3. Push: The committed changes are pushed to a remote Git repository (e.g., GitHub, GitLab).
  4. Pull: On other devices, users pull the latest changes from the remote repository to update their local data.

Command-Line Interface

The CLI of blogtato is designed to be intuitive and efficient. It supports a variety of commands to manage feeds and articles. Here are some of the key commands:

  • Adding a Feed:
  blogtato add <feed_url>
Enter fullscreen mode Exit fullscreen mode
  • Listing Feeds:
  blogtato list
Enter fullscreen mode Exit fullscreen mode
  • Reading Articles:
  blogtato read <feed_name>
Enter fullscreen mode Exit fullscreen mode
  • Marking Articles as Read:
  blogtato mark-read <article_id>
Enter fullscreen mode Exit fullscreen mode
  • Syncing Data:
  blogtato sync
Enter fullscreen mode Exit fullscreen mode

Implementation Details

Parsing Feeds

blogtato uses a feed parser library to fetch and parse RSS and Atom feeds. The choice of library depends on the programming language used. For example, in Python, the feedparser library is commonly used. Here’s a sample code snippet for parsing a feed:

import feedparser

def parse_feed(url):
    feed = feedparser.parse(url)
    articles = []
    for entry in feed.entries:
        article = {
            'title': entry.title,
            'link': entry.link,
            'published': entry.published,
            'summary': entry.summary
        }
        articles.append(article)
    return articles
Enter fullscreen mode Exit fullscreen mode

Storing and Retrieving Data

Data is stored in JSON files, which are easy to read and write. The json module in Python can be used to handle JSON data. Here’s an example of how to store and retrieve feed data:

import json

def save_feeds(feeds, filename='feeds.json'):
    with open(filename, 'w') as f:
        json.dump(feeds, f, indent=4)

def load_feeds(filename='feeds.json'):
    try:
        with open(filename, 'r') as f:
            return json.load(f)
    except FileNotFoundError:
        return []

def save_articles(articles, filename='articles/'):
    for article in articles:
        article_id = article['id']
        with open(f'{filename}/{article_id}.json', 'w') as f:
            json.dump(article, f, indent=4)

def load_articles(filename='articles/'):
    articles = []
    for file in os.listdir(filename):
        if file.endswith('.json'):
            with open(os.path.join(filename, file), 'r') as f:
                articles.append(json.load(f))
    return articles
Enter fullscreen mode Exit fullscreen mode

Git Integration

Git integration is handled using the git command-line tool. The subprocess module in Python can be used to execute Git commands. Here’s an example of how to commit and push changes:

import subprocess

def git_commit(message):
    subprocess.run(['git', 'add', '.'])
    subprocess.run(['git', 'commit', '-m', message])

def git_push():
    subprocess.run(['git', 'push'])

def git_pull():
    subprocess.run(['git', 'pull'])
Enter fullscreen mode Exit fullscreen mode

Customization and Configuration

blogtato allows users to customize various aspects of the tool through a configuration file (config.json). This file can specify settings such as the default feed directory, the remote Git repository URL, and custom keybindings. Here’s an example of a configuration file:

{
    "feed_directory": "feeds/",
    "article_directory": "articles/",
    "git_remote": "https://github.com/user/blogtato-data.git",
    "keybindings": {
        "next_article": "j",
        "prev_article": "k",
        "mark_read": "r"
    }
}
Enter fullscreen mode Exit fullscreen mode

Performance Optimization

To ensure optimal performance, blogtato employs several strategies:

  • Caching: Feeds are cached locally to reduce the number of network requests and improve load times.
  • Incremental Updates: Only new articles are fetched and added to the local database, minimizing data transfer.
  • Asynchronous Operations: Network operations are performed asynchronously to keep the user interface responsive.

Benefits and Use Cases

Benefits

  • Cross-Platform Compatibility: blogtato can be used on any platform that supports a terminal and Git, making it highly versatile.
  • Offline Access: Since data is stored locally, users can access their feeds even when offline.
  • Privacy: Unlike web-based feed readers, blogtato does not require users to share their feed data with third-party services.
  • Customizability: Users can tailor the tool to their specific needs through extensive configuration options.

Use Cases

  • Personal Use: Individuals who prefer a minimalist, text-based interface for managing their feeds.
  • Team Collaboration: Teams that need to share and manage a common set of feeds.
  • Automation: Integrating blogtato into scripts and workflows for automated feed processing.

Conclusion

blogtato is a powerful and flexible CLI RSS/Atom feed reader that leverages the strengths of Taskwarrior and Git to provide a seamless and efficient user experience. Its modular architecture, robust synchronization capabilities, and extensive customization options make it a valuable tool for both personal and professional use. Whether you are a power user looking for a lightweight feed reader or a team needing a collaborative solution, blogtato is worth considering.

For more information on how to integrate blogtato into your workflow or for consulting services, visit https://www.mgatc.com.


Originally published in Spanish at www.mgatc.com/blog/blogtato/

Top comments (0)