rifterm 0.2.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- rifterm-0.2.0/.gitignore +11 -0
- rifterm-0.2.0/CHANGELOG.md +37 -0
- rifterm-0.2.0/CONTRIBUTING.md +43 -0
- rifterm-0.2.0/LICENSE +21 -0
- rifterm-0.2.0/PKG-INFO +112 -0
- rifterm-0.2.0/README.md +83 -0
- rifterm-0.2.0/SECURITY.md +29 -0
- rifterm-0.2.0/pyproject.toml +74 -0
- rifterm-0.2.0/src/rifterm/__init__.py +8 -0
- rifterm-0.2.0/src/rifterm/cache.py +90 -0
- rifterm-0.2.0/src/rifterm/cli.py +212 -0
- rifterm-0.2.0/src/rifterm/client.py +87 -0
- rifterm-0.2.0/src/rifterm/config.py +41 -0
- rifterm-0.2.0/src/rifterm/render.py +193 -0
- rifterm-0.2.0/tests/test_cache.py +143 -0
- rifterm-0.2.0/tests/test_cli.py +68 -0
- rifterm-0.2.0/tests/test_client.py +69 -0
- rifterm-0.2.0/tests/test_config.py +28 -0
- rifterm-0.2.0/tests/test_heat.py +244 -0
- rifterm-0.2.0/tests/test_pepites.py +145 -0
- rifterm-0.2.0/tests/test_report.py +140 -0
rifterm-0.2.0/.gitignore
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
Tous les changements notables de rifterm sont documentés ici.
|
|
4
|
+
Format : [Keep a Changelog](https://keepachangelog.com/fr/1.1.0/) — versions
|
|
5
|
+
[SemVer](https://semver.org/lang/fr/).
|
|
6
|
+
|
|
7
|
+
## [0.2.0] — 2026-11-17
|
|
8
|
+
|
|
9
|
+
### Ajouté
|
|
10
|
+
|
|
11
|
+
- `rifterm report` — agrégat côté CLI de `heat` et `pepites`, avec lecture
|
|
12
|
+
normale, `--json` et export `--out report.md` / `--out report.json`.
|
|
13
|
+
|
|
14
|
+
### Note
|
|
15
|
+
|
|
16
|
+
- L'endpoint serveur `/cli/report` n'est pas encore branché; la commande
|
|
17
|
+
appelle pour l'instant `/cli/heat` + `/cli/pepites`.
|
|
18
|
+
|
|
19
|
+
## [0.1.0] — 2026-09-14
|
|
20
|
+
|
|
21
|
+
Première version fonctionnelle du CLI — données Heat Index et pépites
|
|
22
|
+
depuis l'API RIF.
|
|
23
|
+
|
|
24
|
+
### Ajouté
|
|
25
|
+
|
|
26
|
+
- `rifterm login <clé>` — sauvegarde de la clé API RIF (config locale,
|
|
27
|
+
permissions 600).
|
|
28
|
+
- `rifterm heat` — Heat Index quotidien : score global + tickers les plus
|
|
29
|
+
chauds, rendu riche en terminal.
|
|
30
|
+
- `rifterm pepites` — pépites récentes : ticker, score, heat, signaux.
|
|
31
|
+
- `rifterm status` — validité de la clé + quota quotidien restant.
|
|
32
|
+
- `--json` (global ou par commande) — sortie JSON brute pour scripts et
|
|
33
|
+
pipes, `--days N` (1–30), `--no-cache`.
|
|
34
|
+
- Cache local TTL 5 min par endpoint — économise le quota de 1000 appels/jour.
|
|
35
|
+
|
|
36
|
+
[0.2.0]: https://github.com/soloofboom/rifterm/releases/tag/v0.2.0
|
|
37
|
+
[0.1.0]: https://github.com/soloofboom/rifterm/releases/tag/v0.1.0
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# Contribuer à rifterm
|
|
2
|
+
|
|
3
|
+
Merci de vouloir contribuer ! Le projet est petit — le processus l'est aussi.
|
|
4
|
+
|
|
5
|
+
## Setup
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
git clone https://github.com/soloofboom/rifterm
|
|
9
|
+
cd rifterm
|
|
10
|
+
pip install -e ".[dev]"
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Avant de proposer un changement
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
pytest
|
|
17
|
+
ruff check .
|
|
18
|
+
ruff format --check .
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
Tout doit être vert. La CI rejoue exactement ces trois commandes.
|
|
22
|
+
|
|
23
|
+
## Flow
|
|
24
|
+
|
|
25
|
+
1. Branche nommée `feature/<slug>` ou `fix/<slug>` depuis `main`.
|
|
26
|
+
2. Une PR par sujet, petite et focalisée. Les tests nouveaux accompagnent
|
|
27
|
+
chaque comportement nouveau.
|
|
28
|
+
3. Le français est bienvenu (messages d'erreur, docs) — le code et les
|
|
29
|
+
identifiants restent en anglais.
|
|
30
|
+
|
|
31
|
+
## Conventions du code
|
|
32
|
+
|
|
33
|
+
- Stack : Typer (CLI), httpx (HTTP), rich (rendu terminal).
|
|
34
|
+
- Aucune dépendance nouvelle sans discussion préalable dans une issue.
|
|
35
|
+
- Le CLI consomme uniquement les endpoints `/api/v1/cli/*` (clé API PRO+) —
|
|
36
|
+
jamais de scraping direct du site.
|
|
37
|
+
- Aucun secret dans le code ou l'historique : la clé API vit chez
|
|
38
|
+
l'utilisateur final (`~/.config/rifterm/`), jamais dans ce repo.
|
|
39
|
+
|
|
40
|
+
## Signaler un bug ou proposer une idée
|
|
41
|
+
|
|
42
|
+
Ouvre une [issue](https://github.com/soloofboom/rifterm/issues) avec :
|
|
43
|
+
la commande exacte lancée, la sortie, et la version (`rifterm --version`).
|
rifterm-0.2.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 soloofboom
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
rifterm-0.2.0/PKG-INFO
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: rifterm
|
|
3
|
+
Version: 0.2.0
|
|
4
|
+
Summary: rifterm — le marché, dans votre terminal. CLI open source de rif (Heat Index, pépites, rapports).
|
|
5
|
+
Project-URL: Homepage, https://lerif.ca/rifterm
|
|
6
|
+
Project-URL: Repository, https://github.com/soloofboom/rifterm
|
|
7
|
+
Project-URL: Changelog, https://github.com/soloofboom/rifterm/blob/main/CHANGELOG.md
|
|
8
|
+
Author: soloofboom
|
|
9
|
+
License-Expression: MIT
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
Keywords: cli,finance,market,rif
|
|
12
|
+
Classifier: Development Status :: 4 - Beta
|
|
13
|
+
Classifier: Environment :: Console
|
|
14
|
+
Classifier: Intended Audience :: Financial and Insurance Industry
|
|
15
|
+
Classifier: Operating System :: OS Independent
|
|
16
|
+
Classifier: Programming Language :: Python :: 3
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
20
|
+
Classifier: Topic :: Office/Business :: Financial :: Investment
|
|
21
|
+
Requires-Python: >=3.11
|
|
22
|
+
Requires-Dist: httpx>=0.27
|
|
23
|
+
Requires-Dist: rich>=13.7
|
|
24
|
+
Requires-Dist: typer>=0.12
|
|
25
|
+
Provides-Extra: dev
|
|
26
|
+
Requires-Dist: pytest>=8.0; extra == 'dev'
|
|
27
|
+
Requires-Dist: ruff>=0.5; extra == 'dev'
|
|
28
|
+
Description-Content-Type: text/markdown
|
|
29
|
+
|
|
30
|
+
# rifterm
|
|
31
|
+
|
|
32
|
+
> Le marché, dans votre terminal.
|
|
33
|
+
|
|
34
|
+
CLI open source (MIT) de [rif](https://lerif.ca) — Heat Index, pépites et
|
|
35
|
+
données de marché en ligne de commande. Le CLI est gratuit, les données sont
|
|
36
|
+
payantes.
|
|
37
|
+
|
|
38
|
+
**Statut : v0.2.** Disponible sur PyPI :
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
pipx install rifterm
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## Utilisation
|
|
45
|
+
|
|
46
|
+
```text
|
|
47
|
+
rifterm login <clé> Sauvegarde ta clé API RIF (format rif_…)
|
|
48
|
+
rifterm heat Heat Index quotidien — score global + tickers
|
|
49
|
+
rifterm pepites Pépites récentes — ticker, score, heat, signaux
|
|
50
|
+
rifterm report Agrégat heat + pépites — lecture ou export
|
|
51
|
+
rifterm status État de ta clé + quota quotidien
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
Options utiles (sur `heat`, `pepites` et `report`) :
|
|
55
|
+
|
|
56
|
+
- `--days N` — fenêtre en jours (1–30, défaut 1)
|
|
57
|
+
- `--no-cache` — force l'appel API en ignorant le cache local (TTL 5 min)
|
|
58
|
+
- `--json` — sortie JSON brute, sans styles ni emoji (global ou par commande)
|
|
59
|
+
- `--out report.md` / `--out report.json` — export fichier pour `report`
|
|
60
|
+
|
|
61
|
+
Exemples :
|
|
62
|
+
|
|
63
|
+
```bash
|
|
64
|
+
rifterm heat # tableau riche dans le terminal
|
|
65
|
+
rifterm heat --json | jq '.data[0]'
|
|
66
|
+
rifterm pepites --days 3 --json
|
|
67
|
+
rifterm report --days 2 --out report.md
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
> `report` n'appelle pas encore un endpoint serveur `/cli/report` : celui-ci
|
|
71
|
+
> n'est pas branché. La commande agrège pour l'instant côté CLI
|
|
72
|
+
> `/cli/heat` + `/cli/pepites`; ça devra évoluer quand l'endpoint existera.
|
|
73
|
+
|
|
74
|
+
Les données nécessitent une clé API (abonnement PRO+ sur
|
|
75
|
+
[lerif.ca/rifterm](https://lerif.ca/rifterm)). Le CLI lui-même est gratuit et
|
|
76
|
+
open source.
|
|
77
|
+
|
|
78
|
+
Le cache local (5 min, par endpoint + paramètres, dans le dossier de config)
|
|
79
|
+
économise ton quota quotidien de 1000 appels ; `--no-cache` pour forcer.
|
|
80
|
+
|
|
81
|
+
## Développement
|
|
82
|
+
|
|
83
|
+
```bash
|
|
84
|
+
git clone https://github.com/soloofboom/rifterm
|
|
85
|
+
cd rifterm
|
|
86
|
+
pip install -e ".[dev]"
|
|
87
|
+
pytest
|
|
88
|
+
ruff check .
|
|
89
|
+
ruff format --check .
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
Architecture :
|
|
93
|
+
|
|
94
|
+
- `src/rifterm/cli.py` — commandes Typer
|
|
95
|
+
- `src/rifterm/client.py` — client HTTP (`X-API-Key`, erreurs FR, quotas)
|
|
96
|
+
- `src/rifterm/cache.py` — cache TTL local (5 min, quota 1000/jour)
|
|
97
|
+
- `src/rifterm/render.py` — rendu rich vs JSON
|
|
98
|
+
- `src/rifterm/config.py` — clé API locale (`~/.config/rifterm/config.toml`, 0600)
|
|
99
|
+
|
|
100
|
+
Variables d'environnement :
|
|
101
|
+
|
|
102
|
+
- `RIFTERM_API_URL` — URL de base de l'API (défaut : `https://lerif.ca`)
|
|
103
|
+
- `RIFTERM_CONFIG` — chemin de la config (défaut : `~/.config/rifterm/config.toml`)
|
|
104
|
+
|
|
105
|
+
## Feuille de route
|
|
106
|
+
|
|
107
|
+
Un endpoint serveur `/cli/report` reste possible plus tard — suivi dans
|
|
108
|
+
l'issue [#3](https://github.com/soloofboom/rifterm/issues/3).
|
|
109
|
+
|
|
110
|
+
## Licence
|
|
111
|
+
|
|
112
|
+
[MIT](LICENSE) — forkez, auditez, contribuez.
|
rifterm-0.2.0/README.md
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
# rifterm
|
|
2
|
+
|
|
3
|
+
> Le marché, dans votre terminal.
|
|
4
|
+
|
|
5
|
+
CLI open source (MIT) de [rif](https://lerif.ca) — Heat Index, pépites et
|
|
6
|
+
données de marché en ligne de commande. Le CLI est gratuit, les données sont
|
|
7
|
+
payantes.
|
|
8
|
+
|
|
9
|
+
**Statut : v0.2.** Disponible sur PyPI :
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
pipx install rifterm
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Utilisation
|
|
16
|
+
|
|
17
|
+
```text
|
|
18
|
+
rifterm login <clé> Sauvegarde ta clé API RIF (format rif_…)
|
|
19
|
+
rifterm heat Heat Index quotidien — score global + tickers
|
|
20
|
+
rifterm pepites Pépites récentes — ticker, score, heat, signaux
|
|
21
|
+
rifterm report Agrégat heat + pépites — lecture ou export
|
|
22
|
+
rifterm status État de ta clé + quota quotidien
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
Options utiles (sur `heat`, `pepites` et `report`) :
|
|
26
|
+
|
|
27
|
+
- `--days N` — fenêtre en jours (1–30, défaut 1)
|
|
28
|
+
- `--no-cache` — force l'appel API en ignorant le cache local (TTL 5 min)
|
|
29
|
+
- `--json` — sortie JSON brute, sans styles ni emoji (global ou par commande)
|
|
30
|
+
- `--out report.md` / `--out report.json` — export fichier pour `report`
|
|
31
|
+
|
|
32
|
+
Exemples :
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
rifterm heat # tableau riche dans le terminal
|
|
36
|
+
rifterm heat --json | jq '.data[0]'
|
|
37
|
+
rifterm pepites --days 3 --json
|
|
38
|
+
rifterm report --days 2 --out report.md
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
> `report` n'appelle pas encore un endpoint serveur `/cli/report` : celui-ci
|
|
42
|
+
> n'est pas branché. La commande agrège pour l'instant côté CLI
|
|
43
|
+
> `/cli/heat` + `/cli/pepites`; ça devra évoluer quand l'endpoint existera.
|
|
44
|
+
|
|
45
|
+
Les données nécessitent une clé API (abonnement PRO+ sur
|
|
46
|
+
[lerif.ca/rifterm](https://lerif.ca/rifterm)). Le CLI lui-même est gratuit et
|
|
47
|
+
open source.
|
|
48
|
+
|
|
49
|
+
Le cache local (5 min, par endpoint + paramètres, dans le dossier de config)
|
|
50
|
+
économise ton quota quotidien de 1000 appels ; `--no-cache` pour forcer.
|
|
51
|
+
|
|
52
|
+
## Développement
|
|
53
|
+
|
|
54
|
+
```bash
|
|
55
|
+
git clone https://github.com/soloofboom/rifterm
|
|
56
|
+
cd rifterm
|
|
57
|
+
pip install -e ".[dev]"
|
|
58
|
+
pytest
|
|
59
|
+
ruff check .
|
|
60
|
+
ruff format --check .
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
Architecture :
|
|
64
|
+
|
|
65
|
+
- `src/rifterm/cli.py` — commandes Typer
|
|
66
|
+
- `src/rifterm/client.py` — client HTTP (`X-API-Key`, erreurs FR, quotas)
|
|
67
|
+
- `src/rifterm/cache.py` — cache TTL local (5 min, quota 1000/jour)
|
|
68
|
+
- `src/rifterm/render.py` — rendu rich vs JSON
|
|
69
|
+
- `src/rifterm/config.py` — clé API locale (`~/.config/rifterm/config.toml`, 0600)
|
|
70
|
+
|
|
71
|
+
Variables d'environnement :
|
|
72
|
+
|
|
73
|
+
- `RIFTERM_API_URL` — URL de base de l'API (défaut : `https://lerif.ca`)
|
|
74
|
+
- `RIFTERM_CONFIG` — chemin de la config (défaut : `~/.config/rifterm/config.toml`)
|
|
75
|
+
|
|
76
|
+
## Feuille de route
|
|
77
|
+
|
|
78
|
+
Un endpoint serveur `/cli/report` reste possible plus tard — suivi dans
|
|
79
|
+
l'issue [#3](https://github.com/soloofboom/rifterm/issues/3).
|
|
80
|
+
|
|
81
|
+
## Licence
|
|
82
|
+
|
|
83
|
+
[MIT](LICENSE) — forkez, auditez, contribuez.
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# Sécurité
|
|
2
|
+
|
|
3
|
+
## Signaler une vulnérabilité
|
|
4
|
+
|
|
5
|
+
**Ne pas ouvrir d'issue publique pour une faille de sécurité.** Utilise le
|
|
6
|
+
signalement privé : onglet *Security* → *Report a vulnerability* du repo
|
|
7
|
+
GitHub, ou contacte le mainteneur via la page du profil soloofboom.
|
|
8
|
+
|
|
9
|
+
Une réponse sous 7 jours, une correction prioritaire pour tout ce qui touche
|
|
10
|
+
les clés API des utilisateurs.
|
|
11
|
+
|
|
12
|
+
## Périmètre
|
|
13
|
+
|
|
14
|
+
- **Dans le périmètre** : le code de ce repo (`src/rifterm/`), le workflow
|
|
15
|
+
de publication, la gestion locale de la clé API (`~/.config/rifterm/`).
|
|
16
|
+
- **Hors périmètre** : l'API RIF elle-même (lerif.ca) et ses endpoints —
|
|
17
|
+
les failles côté serveur se rapportent séparément au mainteneur, pas via
|
|
18
|
+
les issues publiques de ce repo.
|
|
19
|
+
|
|
20
|
+
## Bonnes pratiques en vigueur
|
|
21
|
+
|
|
22
|
+
- Publication PyPI par [Trusted Publishing](https://docs.pypi.org/trusted-publishers/)
|
|
23
|
+
(OIDC) — aucun token PyPI stocké dans le repo, aucun secret dans le
|
|
24
|
+
workflow. La publication ne se déclenche que sur push de tag.
|
|
25
|
+
- La clé API RIF est stockée localement avec permissions 600 et envoyée
|
|
26
|
+
uniquement à `https://lerif.ca` (HTTPS, header `X-API-Key`). Elle n'est
|
|
27
|
+
jamais journalisée ni transmise ailleurs.
|
|
28
|
+
- `RIFTERM_API_URL` permet de pointer ailleurs pour le développement —
|
|
29
|
+
un utilisateur qui le fait sait ce qu'il fait.
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "rifterm"
|
|
7
|
+
description = "rifterm — le marché, dans votre terminal. CLI open source de rif (Heat Index, pépites, rapports)."
|
|
8
|
+
readme = "README.md"
|
|
9
|
+
license = "MIT"
|
|
10
|
+
license-files = ["LICENSE"]
|
|
11
|
+
requires-python = ">=3.11"
|
|
12
|
+
authors = [{ name = "soloofboom" }]
|
|
13
|
+
keywords = ["cli", "market", "finance", "rif"]
|
|
14
|
+
classifiers = [
|
|
15
|
+
"Development Status :: 4 - Beta",
|
|
16
|
+
"Environment :: Console",
|
|
17
|
+
"Intended Audience :: Financial and Insurance Industry",
|
|
18
|
+
"Operating System :: OS Independent",
|
|
19
|
+
"Programming Language :: Python :: 3",
|
|
20
|
+
"Programming Language :: Python :: 3.11",
|
|
21
|
+
"Programming Language :: Python :: 3.12",
|
|
22
|
+
"Programming Language :: Python :: 3.13",
|
|
23
|
+
"Topic :: Office/Business :: Financial :: Investment",
|
|
24
|
+
]
|
|
25
|
+
dependencies = [
|
|
26
|
+
"typer>=0.12",
|
|
27
|
+
"httpx>=0.27",
|
|
28
|
+
"rich>=13.7",
|
|
29
|
+
]
|
|
30
|
+
dynamic = ["version"]
|
|
31
|
+
|
|
32
|
+
[project.scripts]
|
|
33
|
+
rifterm = "rifterm.cli:app"
|
|
34
|
+
|
|
35
|
+
[project.urls]
|
|
36
|
+
Homepage = "https://lerif.ca/rifterm"
|
|
37
|
+
Repository = "https://github.com/soloofboom/rifterm"
|
|
38
|
+
Changelog = "https://github.com/soloofboom/rifterm/blob/main/CHANGELOG.md"
|
|
39
|
+
|
|
40
|
+
[project.optional-dependencies]
|
|
41
|
+
dev = [
|
|
42
|
+
"pytest>=8.0",
|
|
43
|
+
"ruff>=0.5",
|
|
44
|
+
]
|
|
45
|
+
|
|
46
|
+
# Source unique de la version : src/rifterm/__init__.py (__version__) — le tag
|
|
47
|
+
# git et le paquet construit ne peuvent pas diverger.
|
|
48
|
+
[tool.hatch.version]
|
|
49
|
+
path = "src/rifterm/__init__.py"
|
|
50
|
+
|
|
51
|
+
[tool.hatch.build.targets.wheel]
|
|
52
|
+
packages = ["src/rifterm"]
|
|
53
|
+
|
|
54
|
+
# sdist à contenu déterministe : uniquement ces fichiers (aucun .github/, cache
|
|
55
|
+
# ou artefact local ne peut finir dans le paquet publié).
|
|
56
|
+
[tool.hatch.build.targets.sdist]
|
|
57
|
+
include = [
|
|
58
|
+
"src/rifterm",
|
|
59
|
+
"tests",
|
|
60
|
+
"README.md",
|
|
61
|
+
"LICENSE",
|
|
62
|
+
"CHANGELOG.md",
|
|
63
|
+
"CONTRIBUTING.md",
|
|
64
|
+
"SECURITY.md",
|
|
65
|
+
"pyproject.toml",
|
|
66
|
+
]
|
|
67
|
+
|
|
68
|
+
[tool.ruff]
|
|
69
|
+
line-length = 100
|
|
70
|
+
src = ["src", "tests"]
|
|
71
|
+
|
|
72
|
+
[tool.pytest.ini_options]
|
|
73
|
+
testpaths = ["tests"]
|
|
74
|
+
addopts = "-q"
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"""rifterm — le marché, dans votre terminal.
|
|
2
|
+
|
|
3
|
+
CLI open source (MIT) de rif : Heat Index, pépites et rapports quotidiens,
|
|
4
|
+
directement en ligne de commande. Les données RIF sont servies par
|
|
5
|
+
https://lerif.ca (abonnement PRO+, clé API).
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
__version__ = "0.2.0"
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
"""Cache local TTL — économise le quota quotidien (1000 appels par clé).
|
|
2
|
+
|
|
3
|
+
Les réponses sont stockées en JSON dans ``<dossier de config>/cache/`` : une
|
|
4
|
+
entrée par (endpoint + paramètres), TTL court (5 min par défaut). Un échec
|
|
5
|
+
d'écriture ou de lecture est silencieux — le cache est un plus, jamais un
|
|
6
|
+
blocage.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
from __future__ import annotations
|
|
10
|
+
|
|
11
|
+
import hashlib
|
|
12
|
+
import json
|
|
13
|
+
import time
|
|
14
|
+
from pathlib import Path
|
|
15
|
+
from typing import Any
|
|
16
|
+
|
|
17
|
+
import httpx
|
|
18
|
+
|
|
19
|
+
from rifterm.client import RifApiError, get
|
|
20
|
+
from rifterm.config import config_path
|
|
21
|
+
|
|
22
|
+
CACHE_TTL_SECONDS = 300
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def cache_dir() -> Path:
|
|
26
|
+
"""Dossier du cache : à côté du fichier de config (``RIFTERM_CONFIG`` respecté)."""
|
|
27
|
+
return config_path().parent / "cache"
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def cache_key(path: str, params: dict[str, object] | None) -> str:
|
|
31
|
+
"""Clé stable pour un (endpoint + paramètres), indépendante de l'ordre."""
|
|
32
|
+
normalise = json.dumps(params or {}, sort_keys=True, separators=(",", ":"))
|
|
33
|
+
return hashlib.sha256(f"{path}?{normalise}".encode()).hexdigest()
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def cache_get(path: str, params: dict[str, object] | None) -> dict[str, Any] | None:
|
|
37
|
+
"""Payload en cache si le TTL est valide, sinon ``None`` (entrée expirée supprimée)."""
|
|
38
|
+
fichier = cache_dir() / f"{cache_key(path, params)}.json"
|
|
39
|
+
try:
|
|
40
|
+
entree = json.loads(fichier.read_text(encoding="utf-8"))
|
|
41
|
+
except (OSError, ValueError):
|
|
42
|
+
return None
|
|
43
|
+
if not isinstance(entree, dict) or time.time() >= float(entree.get("expires", 0)):
|
|
44
|
+
try:
|
|
45
|
+
fichier.unlink(missing_ok=True)
|
|
46
|
+
except OSError:
|
|
47
|
+
pass
|
|
48
|
+
return None
|
|
49
|
+
payload = entree.get("payload")
|
|
50
|
+
return payload if isinstance(payload, dict) else None
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def cache_put(path: str, params: dict[str, object] | None, payload: dict[str, Any]) -> None:
|
|
54
|
+
"""Écrit le payload dans le cache avec un TTL ; échec silencieux."""
|
|
55
|
+
dossier = cache_dir()
|
|
56
|
+
fichier = dossier / f"{cache_key(path, params)}.json"
|
|
57
|
+
entree = {"expires": time.time() + CACHE_TTL_SECONDS, "payload": payload}
|
|
58
|
+
try:
|
|
59
|
+
dossier.mkdir(parents=True, exist_ok=True)
|
|
60
|
+
fichier.write_text(json.dumps(entree, ensure_ascii=False), encoding="utf-8")
|
|
61
|
+
except OSError:
|
|
62
|
+
pass
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def fetch(
|
|
66
|
+
path: str,
|
|
67
|
+
*,
|
|
68
|
+
api_key: str | None = None,
|
|
69
|
+
params: dict[str, object] | None = None,
|
|
70
|
+
use_cache: bool = True,
|
|
71
|
+
transport: httpx.BaseTransport | None = None,
|
|
72
|
+
) -> tuple[dict[str, Any], httpx.Response | None]:
|
|
73
|
+
"""``GET`` avec cache TTL : ``(payload, réponse)`` — ``réponse`` est ``None`` en cache hit.
|
|
74
|
+
|
|
75
|
+
Lève :py:class:`RifApiError` sur erreur API (401/403/429/5xx, réseau)
|
|
76
|
+
ou corps JSON illisible.
|
|
77
|
+
"""
|
|
78
|
+
if use_cache:
|
|
79
|
+
cached = cache_get(path, params)
|
|
80
|
+
if cached is not None:
|
|
81
|
+
return cached, None
|
|
82
|
+
resp = get(path, api_key=api_key, params=params, transport=transport)
|
|
83
|
+
try:
|
|
84
|
+
payload = resp.json()
|
|
85
|
+
except ValueError as exc:
|
|
86
|
+
raise RifApiError("Réponse inattendue de l'API RIF (JSON invalide).") from exc
|
|
87
|
+
if not isinstance(payload, dict):
|
|
88
|
+
raise RifApiError("Réponse inattendue de l'API RIF (payload inattendu).")
|
|
89
|
+
cache_put(path, params, payload)
|
|
90
|
+
return payload, resp
|