server.nntp_article¶
Functions for building NNTP articles (RFC 5322 email messages) that carry OME metadata as MIME enclosures.
- Public API:
nntp_article() — low-level builder: title + arbitrary JSON attachments. make_plugin_article() — high-level helper: plugin + raw item JSON → article.
Attributes¶
Functions¶
|
Returns an NNTP article (EmailMessage) with the given subject, optional body text, |
|
Build an NNTP article from a plugin and a raw source-item JSON file. |
Module Contents¶
- server.nntp_article.nntp_article(title: str, attachments: collections.abc.Iterable[str | pathlib.Path], *, body: str = '') email.message.EmailMessage¶
Returns an NNTP article (EmailMessage) with the given subject, optional body text, and JSON file attachments (enclosures).
- Args:
title: The article subject line. attachments: Paths to JSON files to attach as NNTP enclosures. body: Optional plain-text body for the article (e.g., serialised OME JSON).
- server.nntp_article.make_plugin_article(plugin: server.plugins.ome_plugin.OMEPlugin, item_json_path: str | pathlib.Path, *, ome_json_path: str | pathlib.Path | None = None) email.message.EmailMessage¶
Build an NNTP article from a plugin and a raw source-item JSON file.
This is a convenience wrapper around
nntp_article()that handles the boilerplate required to turn a raw source JSON record into a publishable NNTP article:Reads item_json_path and calls
plugin.make_metadata_card_from_json()to produce anEducationResource.Serialises the resource to JSON and writes it to ome_json_path (
<stem>_ome_item.jsonin the same directory by default).Calls
nntp_article()with: - body = the OME JSON string - first attachment = the raw source-item JSON file - second attachment = the OME JSON file
- Args:
- plugin: The
OMEPluginsubclass instance to use for the metadata transformation.
- item_json_path: Path to the raw source-item JSON file
(e.g.
eric_item.json).- ome_json_path: Optional explicit path for the OME JSON output file.
When omitted the path is derived by replacing the
_itemsuffix of item_json_path’s stem with_ome_item(e.g.eric_item.json→eric_ome_item.json).
- plugin: The
- Returns:
An
email.message.EmailMessageready to be posted to INN or written to disk withPath(...).write_text(str(article)).
Example:
from pathlib import Path from server.nntp_article import make_plugin_article from server.plugins.eric.plugin import EricPlugin plugin = EricPlugin() here = Path(__file__).resolve().parent article = make_plugin_article(plugin, here / "eric_item.json") (here / "eric_article.eml").write_text(str(article))
- server.nntp_article.here¶