1
0
Fork 0
This repository is written in my native language, Japanese, as it is intended for learning how to use https://codeberg.org/ and for accurately describing a framework prototype that integrates Rust APIs, Python, and SQLite. If needed, please consider using a translation tool. Thank you for your understanding.
  • Rust 51%
  • Python 49%
Find a file
2025-07-31 08:33:45 +02:00
sample sample/csv-kakuninn.py を更新 2025-07-31 06:26:57 +02:00
src "src" にファイルをアップロード 2025-07-31 07:49:57 +02:00
Cargo.toml "/" にファイルをアップロード 2025-07-31 07:52:51 +02:00
LICENSE Initial commit 2025-07-31 00:26:02 +02:00
news_titles.db "/" にファイルをアップロード 2025-07-31 01:24:58 +02:00
README.md README.md を更新 2025-07-31 08:33:45 +02:00
rss_sqlite_email.py "/" にファイルをアップロード 2025-07-31 07:58:30 +02:00

Prototype Framework: Rust API for Python and SQLite


About this repository

This repository is written in my native language, Japanese, as it is intended for learning how to use https://codeberg.org/ and for accurately describing a framework prototype that integrates Rust APIs, Python, and SQLite. If needed, please consider using a translation tool. Thank you for your understanding.


This RSS aggregation system retrieves information from a list of RSS feeds defined in rss_sqlite_email.py. The database news_titles.db contains only metadata such as titles and URLs, and does not redistribute any original content. All rights to the information belong to each respective source.


About Security

For convenience in using Lubuntu’s Systemd, the email address and Gmail app password are hard-coded in rss_sqlite_email.py. Since this is running on a secure home server, this setup is used here; however, it is strongly recommended to use environment variables or other secure methods.



これは何?

任意のRSSソース(報道など)をSystemdで自動で取得し自分宛てに、SQLで指定した単語を含むCSVと含まないCSVファイルをメール送信する仕組みです。

CSVファイルの使用例 → note

学習も兼ねて、Node.jsの哲学から仕様を考え、RustでAPIサーバーを立てることでPythonが直接SQLiteを触らない仕組みを作りました。

学習用、プロトタイプ、また多言語連携システムのリファレンス実装としてもご活用いただけるフレームワークのプロトタイプです。


クイックスタート

  1. RustとPythonの処理系(仮想環境などでpipを設定)を用意する
  2. 以下の構成で任意のフォルダにインストールする
  3. メールアドレスとGmaklアプリパスワードをrss_sqlite_email.pyに設定する
  4. /rust-api-4-py-and-sqlで以下のコマンドを実行する(初回のみRustがビルドされます)
  5. Python仮想環境でrss_sqlite_email.pyを実行する
コマンド モード 場所 用途
cargo run デバッグ target/debug/news-gateway 開発・テスト
cargo run --release リリース target/release/news-gateway 本番・systemd
cargo build --release リリース target/release/news-gateway ビルドのみ

各要素の役割・流れ

1. システム管理者

keywordsテーブルだけを直接SQLite操作(手動で追加/編集/削除)。

newsテーブルは直接触らない。

2. Pythonスクリプト

RSSを収集し、記事を整形。

keywordsリストはAPI経由(GET /api/keywords)で読み取り専用。

新しい記事はAPI経由(POST /api/articles)でnewsテーブルへ登録。

newsテーブルに直接書き込みはしない。

3. Rust APIサーバー

SQLiteのkeywordsとnewsの両テーブルの「唯一のAPIゲートウェイ」。

GET /api/keywords … キーワード一覧取得(Pythonが使う)

POST /api/articles … ニュース登録(Pythonが使う)

GET /api/news/recent … 最新ニュース取得(PythonがCSV作成などで使う)


ポイント整理

キーワード管理(keywordsテーブル)

→「管理者のみ手動で直接SQLite編集」


ニュース記事(newsテーブル)

→「PythonがRSS収集後、Rust API経由で登録」

→ Pythonも管理者も直接newsテーブルを書かない(API経由のみ)

APIサーバーは両テーブルの唯一の窓口

→ セキュリティ・役割分離・可視性のため

権限まとめ(誰がどのテーブルに何できるか)

keywordsテーブル newsテーブル
管理者 手動編集(直接) 触らない
Python 読み取り(API) 登録・参照(API)
Rust API 全操作(API化) 全操作(API化)

背景思想

Node.jsの迅速な開発や、ファイルの分割などの哲学から学び、indexとルーティングとロジックとデータの役割を分離しました。RustのAPIサーバーを使うことで、擬似的なサンドボックスが作れるため、個人やNPOが迅速にプロトタイプを作り、スケールして引き継いだり機能や言語を置き換えることを念頭に置いています。RSS取得とSQLiteの操作とメール送信ならRustは不要ですが、勉強を兼ねて作りました。自分用のツールを作るついでにRustのAPIサーバーとPythonとSQLiteの連携のプロトタイプを作ることは、公共に資すると考えました。

MITライセンスで公開しているので、過不足があれば拡張してくださると嬉しいです。


なぜ世界の情報を集めるのか。Pythonのライブラリの関係で英語の情報源に偏ってしまいますが、我々が普段接する報道とは異なる視点に触れられます。記事タイトルと情報源と日時からの分析だから限界はあります。けれど、世界の俯瞰(全体像の流れ・大局観)と、メガトレンドに隠れて見落とされる歴史的な予兆(パターン)をAIで分析することで、例えば「グローバルな問題を、ローカルに解決しようとしている」など、気付きを得られます。

SQLはサンプルです。RSSのリストもご自由に足したり減らしたりなさって下さい。

情報が多すぎる時代に、我々が何が出来るかを考え、制作しました。



License

MIT License


Repository Policy

  • I develop prototypes with a focus on ethics.
  • There are no plans for maintenance or support.
  • The project is released under the MIT License, so feel free to modify it within the scope of the license.
  • Instead of providing support, I create new prototypes to solve emerging problems.

Author Declaration

I am an unaffiliated volunteer individual, and there is no conflict of interest in this project.