tool-harvest 0.1.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.
- tool_harvest-0.1.0/LICENSE +21 -0
- tool_harvest-0.1.0/PKG-INFO +159 -0
- tool_harvest-0.1.0/README.md +109 -0
- tool_harvest-0.1.0/pyproject.toml +54 -0
- tool_harvest-0.1.0/setup.cfg +4 -0
- tool_harvest-0.1.0/src/harvest/__init__.py +0 -0
- tool_harvest-0.1.0/src/harvest/cli.py +56 -0
- tool_harvest-0.1.0/src/harvest/sources/__init__.py +0 -0
- tool_harvest-0.1.0/src/harvest/sources/ina/__init__.py +1 -0
- tool_harvest-0.1.0/src/harvest/sources/ina/client.py +71 -0
- tool_harvest-0.1.0/src/harvest/sources/ina/discover.py +231 -0
- tool_harvest-0.1.0/src/harvest/sources/ina/parser.py +54 -0
- tool_harvest-0.1.0/src/harvest/sources/ina/process.py +169 -0
- tool_harvest-0.1.0/src/harvest/sources/ina/validation.py +30 -0
- tool_harvest-0.1.0/src/harvest/sources/registry.py +24 -0
- tool_harvest-0.1.0/src/harvest/utils.py +38 -0
- tool_harvest-0.1.0/src/tool_harvest.egg-info/PKG-INFO +159 -0
- tool_harvest-0.1.0/src/tool_harvest.egg-info/SOURCES.txt +21 -0
- tool_harvest-0.1.0/src/tool_harvest.egg-info/dependency_links.txt +1 -0
- tool_harvest-0.1.0/src/tool_harvest.egg-info/entry_points.txt +2 -0
- tool_harvest-0.1.0/src/tool_harvest.egg-info/requires.txt +10 -0
- tool_harvest-0.1.0/src/tool_harvest.egg-info/top_level.txt +1 -0
- tool_harvest-0.1.0/tests/test_utils.py +85 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Gwendal Minguy-Pèlerin
|
|
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.
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: tool-harvest
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Data acquisition and extraction tool.
|
|
5
|
+
Author-email: Gwendal Minguy-Pèlerin <gwendalminguy@outlook.fr>
|
|
6
|
+
Maintainer-email: Gwendal Minguy-Pèlerin <gwendalminguy@outlook.fr>
|
|
7
|
+
License: MIT License
|
|
8
|
+
|
|
9
|
+
Copyright (c) 2026 Gwendal Minguy-Pèlerin
|
|
10
|
+
|
|
11
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
12
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
13
|
+
in the Software without restriction, including without limitation the rights
|
|
14
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
15
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
16
|
+
furnished to do so, subject to the following conditions:
|
|
17
|
+
|
|
18
|
+
The above copyright notice and this permission notice shall be included in all
|
|
19
|
+
copies or substantial portions of the Software.
|
|
20
|
+
|
|
21
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
22
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
23
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
24
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
25
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
26
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
27
|
+
SOFTWARE.
|
|
28
|
+
|
|
29
|
+
Project-URL: Homepage, https://github.com/gwendalminguy/tool-harvest
|
|
30
|
+
Project-URL: Repository, https://github.com/gwendalminguy/tool-harvest
|
|
31
|
+
Project-URL: Changelog, https://github.com/gwendalminguy/tool-harvest/blob/main/CHANGELOG.md
|
|
32
|
+
Keywords: cli,devtools,acquisition,extraction,productivity
|
|
33
|
+
Classifier: Programming Language :: Python :: 3
|
|
34
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
35
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
36
|
+
Classifier: Operating System :: OS Independent
|
|
37
|
+
Requires-Python: >=3.10
|
|
38
|
+
Description-Content-Type: text/markdown
|
|
39
|
+
License-File: LICENSE
|
|
40
|
+
Requires-Dist: beautifulsoup4<4.16.0,>=4.15.0
|
|
41
|
+
Requires-Dist: httpx<0.29.0,>=0.28.0
|
|
42
|
+
Requires-Dist: typer<0.30.0,>=0.29.0
|
|
43
|
+
Provides-Extra: dev
|
|
44
|
+
Requires-Dist: pytest<9.3.0,>=9.2.0; extra == "dev"
|
|
45
|
+
Requires-Dist: pytest-mock<3.18.0,>=3.17.0; extra == "dev"
|
|
46
|
+
Requires-Dist: pytest-asyncio<1.6.0,>=1.5.0; extra == "dev"
|
|
47
|
+
Requires-Dist: respx<0.24.0,>=0.23.0; extra == "dev"
|
|
48
|
+
Requires-Dist: ruff<0.18.0,>=0.17.0; extra == "dev"
|
|
49
|
+
Dynamic: license-file
|
|
50
|
+
|
|
51
|
+
# Harvest
|
|
52
|
+
|
|
53
|
+
<div align="center">
|
|
54
|
+
<a href="https://pypi.org/project/tool-harvest">
|
|
55
|
+
<img src="https://img.shields.io/pypi/v/tool-harvest?color=blue">
|
|
56
|
+
</a>
|
|
57
|
+
</div>
|
|
58
|
+
|
|
59
|
+
A data acquisition and extraction tool designed to collect, archive, and structure information from multiple sources.
|
|
60
|
+
|
|
61
|
+
## Description
|
|
62
|
+
|
|
63
|
+
The project aims to provide a reusable and extensible framework for retrieving data from different content providers and media types. The initial focus is on collecting radio programme records from the [INA Catalogue](https://catalogue.ina.fr/).
|
|
64
|
+
|
|
65
|
+
## Objectives
|
|
66
|
+
|
|
67
|
+
- Discover and index available records from external sources.
|
|
68
|
+
- Download and archive raw source documents and extract relevant information.
|
|
69
|
+
- Provide structured data that can be exported and consumed by other applications.
|
|
70
|
+
- Support multiple data sources through dedicated source integrations.
|
|
71
|
+
- Preserve source references and data provenance.
|
|
72
|
+
|
|
73
|
+
## Flow Logic
|
|
74
|
+
|
|
75
|
+
Harvest works as follow:
|
|
76
|
+
|
|
77
|
+
1. **Selection**: select a data source, a media type, a media name, and a title to search for.
|
|
78
|
+
2. **Discovery**: query the source catalogue to discover available records and their notice identifier.
|
|
79
|
+
3. **Process**: retrieve notices individually and archive their original content as HTML files.
|
|
80
|
+
4. **Extraction**: extract relevant information from the archived documents as JSON files.
|
|
81
|
+
5. **Export**: produce structured records that can be consumed by other applications.
|
|
82
|
+
|
|
83
|
+
## Project Structure
|
|
84
|
+
|
|
85
|
+
The project contains several files and directories, which are the following:
|
|
86
|
+
|
|
87
|
+
| Files | Description |
|
|
88
|
+
| :---- | :---------- |
|
|
89
|
+
| [`src/`](src/) | The package source code directory. |
|
|
90
|
+
| [`tests/`](tests/) | The package tests directory. |
|
|
91
|
+
| [`CHANGELOG.md`](CHANGELOG.md) | The markdown file listing the changes history of the tool. |
|
|
92
|
+
| [`LICENSE`](LICENSE) | The text file defining the license of the tool. |
|
|
93
|
+
| [`README.md`](README.md) | The markdown file introducting the tool. |
|
|
94
|
+
| [`pyproject.toml`](pyproject.toml) | The packaging configuration file. |
|
|
95
|
+
|
|
96
|
+
## Output Format
|
|
97
|
+
|
|
98
|
+
```
|
|
99
|
+
data/
|
|
100
|
+
└── <TITLE>/
|
|
101
|
+
├── discovery.json
|
|
102
|
+
└── notices/
|
|
103
|
+
├── raw/
|
|
104
|
+
│ └── <ID>.html
|
|
105
|
+
└── extracted/
|
|
106
|
+
└── <ID>.json
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
## Sources
|
|
110
|
+
|
|
111
|
+
The acquisition process is designed to support multiple sources.
|
|
112
|
+
|
|
113
|
+
**Available Sources**:
|
|
114
|
+
|
|
115
|
+
- [INA Catalogue](https://catalogue.ina.fr)
|
|
116
|
+
|
|
117
|
+
Additional sources may be supported as the project evolves.
|
|
118
|
+
|
|
119
|
+
## Data Acquisition
|
|
120
|
+
|
|
121
|
+
The acquisition process is divided into two distinct stages:
|
|
122
|
+
|
|
123
|
+
1. **Discover**: search external sources and build a detailed inventory of available records with their identifiers.
|
|
124
|
+
2. **Process**: retrieve individual records, archive their original content as HTML files and extract structured information as JSON files.
|
|
125
|
+
|
|
126
|
+
Raw documents are preserved independently from extracted data, allowing extraction rules to evolve without repeatedly querying external sources. All acquired data is stored locally in a `data/` directory.
|
|
127
|
+
|
|
128
|
+
## Installation
|
|
129
|
+
|
|
130
|
+
It is recommended to create a virtual environment before installing Harvest:
|
|
131
|
+
|
|
132
|
+
```bash
|
|
133
|
+
$ python3 -m venv venv
|
|
134
|
+
$ source venv/bin/activate
|
|
135
|
+
$ pip install tool-harvest
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
## Usage
|
|
139
|
+
|
|
140
|
+
Harvest can be run using the following commands:
|
|
141
|
+
|
|
142
|
+
### Discover
|
|
143
|
+
|
|
144
|
+
```bash
|
|
145
|
+
$ harvest discover <source> <query> [<options>] # Run Harvest to discover available records for a specified external source.
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
### Process
|
|
149
|
+
|
|
150
|
+
```bash
|
|
151
|
+
$ harvest process <source> <query> [<limit>] # Run Harvest to process each record by downloading it and extracting relevant information.
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
### Help
|
|
155
|
+
|
|
156
|
+
```bash
|
|
157
|
+
$ harvest --help # Show help with description for available commands.
|
|
158
|
+
$ harvest <command> --help # Show help with arguments/options description for the specified command.
|
|
159
|
+
```
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
# Harvest
|
|
2
|
+
|
|
3
|
+
<div align="center">
|
|
4
|
+
<a href="https://pypi.org/project/tool-harvest">
|
|
5
|
+
<img src="https://img.shields.io/pypi/v/tool-harvest?color=blue">
|
|
6
|
+
</a>
|
|
7
|
+
</div>
|
|
8
|
+
|
|
9
|
+
A data acquisition and extraction tool designed to collect, archive, and structure information from multiple sources.
|
|
10
|
+
|
|
11
|
+
## Description
|
|
12
|
+
|
|
13
|
+
The project aims to provide a reusable and extensible framework for retrieving data from different content providers and media types. The initial focus is on collecting radio programme records from the [INA Catalogue](https://catalogue.ina.fr/).
|
|
14
|
+
|
|
15
|
+
## Objectives
|
|
16
|
+
|
|
17
|
+
- Discover and index available records from external sources.
|
|
18
|
+
- Download and archive raw source documents and extract relevant information.
|
|
19
|
+
- Provide structured data that can be exported and consumed by other applications.
|
|
20
|
+
- Support multiple data sources through dedicated source integrations.
|
|
21
|
+
- Preserve source references and data provenance.
|
|
22
|
+
|
|
23
|
+
## Flow Logic
|
|
24
|
+
|
|
25
|
+
Harvest works as follow:
|
|
26
|
+
|
|
27
|
+
1. **Selection**: select a data source, a media type, a media name, and a title to search for.
|
|
28
|
+
2. **Discovery**: query the source catalogue to discover available records and their notice identifier.
|
|
29
|
+
3. **Process**: retrieve notices individually and archive their original content as HTML files.
|
|
30
|
+
4. **Extraction**: extract relevant information from the archived documents as JSON files.
|
|
31
|
+
5. **Export**: produce structured records that can be consumed by other applications.
|
|
32
|
+
|
|
33
|
+
## Project Structure
|
|
34
|
+
|
|
35
|
+
The project contains several files and directories, which are the following:
|
|
36
|
+
|
|
37
|
+
| Files | Description |
|
|
38
|
+
| :---- | :---------- |
|
|
39
|
+
| [`src/`](src/) | The package source code directory. |
|
|
40
|
+
| [`tests/`](tests/) | The package tests directory. |
|
|
41
|
+
| [`CHANGELOG.md`](CHANGELOG.md) | The markdown file listing the changes history of the tool. |
|
|
42
|
+
| [`LICENSE`](LICENSE) | The text file defining the license of the tool. |
|
|
43
|
+
| [`README.md`](README.md) | The markdown file introducting the tool. |
|
|
44
|
+
| [`pyproject.toml`](pyproject.toml) | The packaging configuration file. |
|
|
45
|
+
|
|
46
|
+
## Output Format
|
|
47
|
+
|
|
48
|
+
```
|
|
49
|
+
data/
|
|
50
|
+
└── <TITLE>/
|
|
51
|
+
├── discovery.json
|
|
52
|
+
└── notices/
|
|
53
|
+
├── raw/
|
|
54
|
+
│ └── <ID>.html
|
|
55
|
+
└── extracted/
|
|
56
|
+
└── <ID>.json
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
## Sources
|
|
60
|
+
|
|
61
|
+
The acquisition process is designed to support multiple sources.
|
|
62
|
+
|
|
63
|
+
**Available Sources**:
|
|
64
|
+
|
|
65
|
+
- [INA Catalogue](https://catalogue.ina.fr)
|
|
66
|
+
|
|
67
|
+
Additional sources may be supported as the project evolves.
|
|
68
|
+
|
|
69
|
+
## Data Acquisition
|
|
70
|
+
|
|
71
|
+
The acquisition process is divided into two distinct stages:
|
|
72
|
+
|
|
73
|
+
1. **Discover**: search external sources and build a detailed inventory of available records with their identifiers.
|
|
74
|
+
2. **Process**: retrieve individual records, archive their original content as HTML files and extract structured information as JSON files.
|
|
75
|
+
|
|
76
|
+
Raw documents are preserved independently from extracted data, allowing extraction rules to evolve without repeatedly querying external sources. All acquired data is stored locally in a `data/` directory.
|
|
77
|
+
|
|
78
|
+
## Installation
|
|
79
|
+
|
|
80
|
+
It is recommended to create a virtual environment before installing Harvest:
|
|
81
|
+
|
|
82
|
+
```bash
|
|
83
|
+
$ python3 -m venv venv
|
|
84
|
+
$ source venv/bin/activate
|
|
85
|
+
$ pip install tool-harvest
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
## Usage
|
|
89
|
+
|
|
90
|
+
Harvest can be run using the following commands:
|
|
91
|
+
|
|
92
|
+
### Discover
|
|
93
|
+
|
|
94
|
+
```bash
|
|
95
|
+
$ harvest discover <source> <query> [<options>] # Run Harvest to discover available records for a specified external source.
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
### Process
|
|
99
|
+
|
|
100
|
+
```bash
|
|
101
|
+
$ harvest process <source> <query> [<limit>] # Run Harvest to process each record by downloading it and extracting relevant information.
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
### Help
|
|
105
|
+
|
|
106
|
+
```bash
|
|
107
|
+
$ harvest --help # Show help with description for available commands.
|
|
108
|
+
$ harvest <command> --help # Show help with arguments/options description for the specified command.
|
|
109
|
+
```
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=69", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "tool-harvest"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
authors = [
|
|
9
|
+
{ name = "Gwendal Minguy-Pèlerin", email = "gwendalminguy@outlook.fr" }
|
|
10
|
+
]
|
|
11
|
+
description = "Data acquisition and extraction tool."
|
|
12
|
+
readme = "README.md"
|
|
13
|
+
requires-python = ">=3.10"
|
|
14
|
+
classifiers = [
|
|
15
|
+
"Programming Language :: Python :: 3",
|
|
16
|
+
"Programming Language :: Python :: 3.10",
|
|
17
|
+
"License :: OSI Approved :: MIT License",
|
|
18
|
+
"Operating System :: OS Independent"
|
|
19
|
+
]
|
|
20
|
+
license = { file = "LICENSE" }
|
|
21
|
+
maintainers = [
|
|
22
|
+
{ name = "Gwendal Minguy-Pèlerin", email = "gwendalminguy@outlook.fr" }
|
|
23
|
+
]
|
|
24
|
+
dependencies = [
|
|
25
|
+
"beautifulsoup4>=4.15.0,<4.16.0",
|
|
26
|
+
"httpx>=0.28.0,<0.29.0",
|
|
27
|
+
"typer>=0.29.0,<0.30.0",
|
|
28
|
+
]
|
|
29
|
+
keywords = ["cli", "devtools", "acquisition", "extraction", "productivity"]
|
|
30
|
+
|
|
31
|
+
[project.scripts]
|
|
32
|
+
harvest = "harvest.cli:app"
|
|
33
|
+
|
|
34
|
+
[project.urls]
|
|
35
|
+
Homepage = "https://github.com/gwendalminguy/tool-harvest"
|
|
36
|
+
Repository = "https://github.com/gwendalminguy/tool-harvest"
|
|
37
|
+
Changelog = "https://github.com/gwendalminguy/tool-harvest/blob/main/CHANGELOG.md"
|
|
38
|
+
|
|
39
|
+
[project.optional-dependencies]
|
|
40
|
+
dev = [
|
|
41
|
+
"pytest>=9.2.0,<9.3.0",
|
|
42
|
+
"pytest-mock>=3.17.0,<3.18.0",
|
|
43
|
+
"pytest-asyncio>=1.5.0,<1.6.0",
|
|
44
|
+
"respx>=0.23.0,<0.24.0",
|
|
45
|
+
"ruff>=0.17.0,<0.18.0",
|
|
46
|
+
]
|
|
47
|
+
|
|
48
|
+
[tool.pytest.ini_options]
|
|
49
|
+
testpaths = ["tests"]
|
|
50
|
+
pythonpath = ["src"]
|
|
51
|
+
addopts = "-ra"
|
|
52
|
+
|
|
53
|
+
[tool.setuptools.packages.find]
|
|
54
|
+
where = ["src"]
|
|
File without changes
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"""
|
|
2
|
+
harvest/cli.py
|
|
3
|
+
Module containing command-line interface functions.
|
|
4
|
+
"""
|
|
5
|
+
from harvest.sources.registry import get_source_fn
|
|
6
|
+
from harvest.utils import parse_options
|
|
7
|
+
|
|
8
|
+
import asyncio
|
|
9
|
+
import typer
|
|
10
|
+
|
|
11
|
+
app = typer.Typer()
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
@app.command()
|
|
15
|
+
def discover(
|
|
16
|
+
source: str = typer.Argument(help="Source to search a title on."),
|
|
17
|
+
query: str = typer.Argument(help="Title to search for."),
|
|
18
|
+
options: list[str] = typer.Option([], "--option", "-o"),
|
|
19
|
+
) -> None:
|
|
20
|
+
"""
|
|
21
|
+
Discover all available notices for a query from a source.
|
|
22
|
+
"""
|
|
23
|
+
handler = get_source_fn(
|
|
24
|
+
source=source,
|
|
25
|
+
fn="discover",
|
|
26
|
+
)
|
|
27
|
+
|
|
28
|
+
options = parse_options(options)
|
|
29
|
+
|
|
30
|
+
try:
|
|
31
|
+
asyncio.run(handler(
|
|
32
|
+
query=query,
|
|
33
|
+
**options,
|
|
34
|
+
))
|
|
35
|
+
except ValueError as error:
|
|
36
|
+
raise typer.BadParameter(str(error))
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
@app.command()
|
|
40
|
+
def process(
|
|
41
|
+
source: str = typer.Argument(help="Source to retrieve notices from."),
|
|
42
|
+
query: str = typer.Argument(help="Title to process notices."),
|
|
43
|
+
limit: int = typer.Option(None, "--limit", "-l", help="Number of notices to process."),
|
|
44
|
+
) -> None:
|
|
45
|
+
"""
|
|
46
|
+
Fetch and save all notices for a query from a source.
|
|
47
|
+
"""
|
|
48
|
+
handler = get_source_fn(
|
|
49
|
+
source=source,
|
|
50
|
+
fn="process",
|
|
51
|
+
)
|
|
52
|
+
|
|
53
|
+
asyncio.run(handler(
|
|
54
|
+
query=query,
|
|
55
|
+
limit=limit,
|
|
56
|
+
))
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
from . import discover, process
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"""
|
|
2
|
+
harvest/sources/ina/client.py
|
|
3
|
+
Module containing INA client.
|
|
4
|
+
"""
|
|
5
|
+
import httpx
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class INAClient:
|
|
9
|
+
"""
|
|
10
|
+
Simple INA Client.
|
|
11
|
+
"""
|
|
12
|
+
BASE_URL = "https://catalogue.ina.fr/docListe/TV-RADIO"
|
|
13
|
+
USER_AGENT = "Harvest/0.1.0"
|
|
14
|
+
|
|
15
|
+
def __init__(self):
|
|
16
|
+
self.client = httpx.AsyncClient(
|
|
17
|
+
headers={"User-Agent": self.USER_AGENT},
|
|
18
|
+
timeout=10,
|
|
19
|
+
)
|
|
20
|
+
|
|
21
|
+
async def _request(
|
|
22
|
+
self,
|
|
23
|
+
url: str,
|
|
24
|
+
*,
|
|
25
|
+
params: dict | None = None,
|
|
26
|
+
) -> str:
|
|
27
|
+
"""
|
|
28
|
+
Execute an HTTP GET request and handle potential errors.
|
|
29
|
+
"""
|
|
30
|
+
try:
|
|
31
|
+
response = await self.client.get(url, params=params)
|
|
32
|
+
response.raise_for_status()
|
|
33
|
+
except httpx.HTTPStatusError as e:
|
|
34
|
+
raise RuntimeError(f"INA returned HTTP {e.response.status_code}: {url}") from e
|
|
35
|
+
except httpx.RequestError as e:
|
|
36
|
+
raise RuntimeError(f"Failed to reach INA: {url}") from e
|
|
37
|
+
|
|
38
|
+
return response.text
|
|
39
|
+
|
|
40
|
+
async def close(self):
|
|
41
|
+
await self.client.aclose()
|
|
42
|
+
|
|
43
|
+
async def search(
|
|
44
|
+
self,
|
|
45
|
+
*,
|
|
46
|
+
base_label: str,
|
|
47
|
+
emission_title: str,
|
|
48
|
+
media_name: str,
|
|
49
|
+
page: int = 1,
|
|
50
|
+
) -> str:
|
|
51
|
+
"""
|
|
52
|
+
Search for INA notices.
|
|
53
|
+
"""
|
|
54
|
+
params = {
|
|
55
|
+
"base_label": base_label,
|
|
56
|
+
"itousti_exact": emission_title,
|
|
57
|
+
"sujets_filter": "Sujet",
|
|
58
|
+
"ch": media_name,
|
|
59
|
+
"bool_operator": "AND",
|
|
60
|
+
"tri": "datdif0",
|
|
61
|
+
"nbLignes": "500",
|
|
62
|
+
"page": page,
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
return await self._request(self.BASE_URL, params=params)
|
|
66
|
+
|
|
67
|
+
async def fetch(self, url: str) -> str:
|
|
68
|
+
"""
|
|
69
|
+
Fetch an INA notice page.
|
|
70
|
+
"""
|
|
71
|
+
return await self._request(url)
|
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
"""
|
|
2
|
+
harvest/sources/ina/discover.py
|
|
3
|
+
Module containing INA discovery functions.
|
|
4
|
+
"""
|
|
5
|
+
from harvest.sources.ina.client import INAClient
|
|
6
|
+
from harvest.sources.ina.validation import validate_media_type, validate_media_name
|
|
7
|
+
from harvest.utils import slugify
|
|
8
|
+
|
|
9
|
+
from bs4 import BeautifulSoup
|
|
10
|
+
from datetime import datetime
|
|
11
|
+
from pathlib import Path
|
|
12
|
+
from urllib.parse import urlparse
|
|
13
|
+
|
|
14
|
+
import asyncio
|
|
15
|
+
import json
|
|
16
|
+
import re
|
|
17
|
+
|
|
18
|
+
DATA_DIR = Path("data")
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
async def search_source(
|
|
22
|
+
emission_title: str,
|
|
23
|
+
client: INAClient,
|
|
24
|
+
media_type: str,
|
|
25
|
+
media_name: str,
|
|
26
|
+
) -> list[dict]:
|
|
27
|
+
"""
|
|
28
|
+
Search the INA catalogue and return discovered notices.
|
|
29
|
+
"""
|
|
30
|
+
page = 1
|
|
31
|
+
notices = {}
|
|
32
|
+
|
|
33
|
+
while True:
|
|
34
|
+
html = await client.search(
|
|
35
|
+
base_label=media_type,
|
|
36
|
+
emission_title=emission_title,
|
|
37
|
+
media_name=media_name,
|
|
38
|
+
page=page,
|
|
39
|
+
)
|
|
40
|
+
|
|
41
|
+
page_notices = extract_notices(html)
|
|
42
|
+
|
|
43
|
+
if not page_notices:
|
|
44
|
+
break
|
|
45
|
+
|
|
46
|
+
for notice in page_notices:
|
|
47
|
+
notices[notice["id"]] = notice
|
|
48
|
+
|
|
49
|
+
page += 1
|
|
50
|
+
|
|
51
|
+
await asyncio.sleep(0.5)
|
|
52
|
+
|
|
53
|
+
return list(notices.values())
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def extract_notices(html: str) -> list[dict]:
|
|
57
|
+
"""
|
|
58
|
+
Extract notice information from INA search results.
|
|
59
|
+
"""
|
|
60
|
+
soup = BeautifulSoup(html, "html.parser")
|
|
61
|
+
|
|
62
|
+
rows = soup.select(
|
|
63
|
+
"#search-content-full-100-ss-titre "
|
|
64
|
+
".search-resultset tr:has(a[href*='/doc/TV-RADIO/'])"
|
|
65
|
+
)
|
|
66
|
+
|
|
67
|
+
notices = []
|
|
68
|
+
|
|
69
|
+
for row in rows:
|
|
70
|
+
cells = row.find_all("td", recursive=False)
|
|
71
|
+
|
|
72
|
+
if len(cells) < 9:
|
|
73
|
+
continue
|
|
74
|
+
|
|
75
|
+
link = cells[5].find("a", href=True)
|
|
76
|
+
|
|
77
|
+
if link is None:
|
|
78
|
+
continue
|
|
79
|
+
|
|
80
|
+
url = link["href"]
|
|
81
|
+
notice_id = _extract_notice_id(url)
|
|
82
|
+
|
|
83
|
+
if notice_id is None:
|
|
84
|
+
continue
|
|
85
|
+
|
|
86
|
+
try:
|
|
87
|
+
broadcast_date = datetime.strptime(
|
|
88
|
+
cells[2].get_text(strip=True),
|
|
89
|
+
"%d/%m/%Y",
|
|
90
|
+
).date().isoformat()
|
|
91
|
+
except ValueError:
|
|
92
|
+
broadcast_date = None
|
|
93
|
+
|
|
94
|
+
notices.append({
|
|
95
|
+
"id": notice_id,
|
|
96
|
+
"url": url,
|
|
97
|
+
"metadata": {
|
|
98
|
+
"rank": int(cells[0].get_text(strip=True)),
|
|
99
|
+
"media_name": cells[1].get_text(strip=True),
|
|
100
|
+
"broadcast_date": broadcast_date,
|
|
101
|
+
"broadcast_time": cells[3].get_text(strip=True),
|
|
102
|
+
"emission_title": cells[6].get_text(strip=True),
|
|
103
|
+
"program_title": link.get_text(strip=True),
|
|
104
|
+
"duration": cells[4].get_text(strip=True),
|
|
105
|
+
},
|
|
106
|
+
})
|
|
107
|
+
|
|
108
|
+
return notices
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
def _extract_notice_id(url: str) -> str | None:
|
|
112
|
+
"""
|
|
113
|
+
Extract an INA notice identifier from its URL.
|
|
114
|
+
"""
|
|
115
|
+
path = urlparse(url).path
|
|
116
|
+
match = re.search(r"/doc/TV-RADIO/([^/]+)", path)
|
|
117
|
+
|
|
118
|
+
return match.group(1) if match else None
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
def save_discovery(
|
|
122
|
+
emission_title: str,
|
|
123
|
+
notices: list[dict],
|
|
124
|
+
media_type: str,
|
|
125
|
+
media_name: str,
|
|
126
|
+
data_dir: Path = DATA_DIR,
|
|
127
|
+
) -> Path:
|
|
128
|
+
"""
|
|
129
|
+
Save discovered notices to a JSON file.
|
|
130
|
+
"""
|
|
131
|
+
output_dir = data_dir / slugify(emission_title)
|
|
132
|
+
output_file = output_dir / "discovery.json"
|
|
133
|
+
|
|
134
|
+
output_dir.mkdir(parents=True, exist_ok=True)
|
|
135
|
+
|
|
136
|
+
if output_file.exists():
|
|
137
|
+
with output_file.open("r", encoding="utf-8") as file:
|
|
138
|
+
discovery = json.load(file)
|
|
139
|
+
|
|
140
|
+
if not isinstance(discovery, dict):
|
|
141
|
+
raise ValueError(f"Invalid discovery structure: {output_file}")
|
|
142
|
+
|
|
143
|
+
if not isinstance(discovery.get("notices"), list):
|
|
144
|
+
raise ValueError(f"Invalid notices list: {output_file}")
|
|
145
|
+
|
|
146
|
+
else:
|
|
147
|
+
discovery = {
|
|
148
|
+
"source": "ina",
|
|
149
|
+
"media_type": media_type,
|
|
150
|
+
"media_name": media_name,
|
|
151
|
+
"emission_title": emission_title,
|
|
152
|
+
"notices": [],
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
# Index existing notices by ID.
|
|
156
|
+
existing_notices = {
|
|
157
|
+
notice["id"]: notice
|
|
158
|
+
for notice in discovery["notices"]
|
|
159
|
+
if isinstance(notice, dict) and notice.get("id")
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
# Merge new discoveries.
|
|
163
|
+
for notice in notices:
|
|
164
|
+
existing_notices[notice["id"]] = notice
|
|
165
|
+
|
|
166
|
+
discovery.update({
|
|
167
|
+
"source": "ina",
|
|
168
|
+
"media_type": media_type,
|
|
169
|
+
"media_name": media_name,
|
|
170
|
+
"emission_title": emission_title,
|
|
171
|
+
"notices": list(existing_notices.values()),
|
|
172
|
+
})
|
|
173
|
+
|
|
174
|
+
with output_file.open("w", encoding="utf-8") as file:
|
|
175
|
+
json.dump(
|
|
176
|
+
discovery,
|
|
177
|
+
file,
|
|
178
|
+
ensure_ascii=False,
|
|
179
|
+
indent=4,
|
|
180
|
+
)
|
|
181
|
+
|
|
182
|
+
file.write("\n")
|
|
183
|
+
|
|
184
|
+
return output_file
|
|
185
|
+
|
|
186
|
+
|
|
187
|
+
async def discover(
|
|
188
|
+
query: str,
|
|
189
|
+
media_type: str | None = None,
|
|
190
|
+
media_name: str | None = None,
|
|
191
|
+
) -> None:
|
|
192
|
+
if media_type is None:
|
|
193
|
+
raise ValueError('Missing required INA source option: media_type (use: -o "media-type=VALUE")')
|
|
194
|
+
|
|
195
|
+
if media_name is None:
|
|
196
|
+
raise ValueError('Missing required INA source option: media_name (use: -o "media-name=VALUE")')
|
|
197
|
+
|
|
198
|
+
validate_media_type(media_type)
|
|
199
|
+
validate_media_name(media_name)
|
|
200
|
+
|
|
201
|
+
emission_title = query
|
|
202
|
+
|
|
203
|
+
client = INAClient()
|
|
204
|
+
|
|
205
|
+
try:
|
|
206
|
+
notices = await search_source(
|
|
207
|
+
emission_title=emission_title,
|
|
208
|
+
client=client,
|
|
209
|
+
media_type=media_type,
|
|
210
|
+
media_name=media_name,
|
|
211
|
+
)
|
|
212
|
+
finally:
|
|
213
|
+
await client.close()
|
|
214
|
+
|
|
215
|
+
output_file = save_discovery(
|
|
216
|
+
emission_title=emission_title,
|
|
217
|
+
notices=notices,
|
|
218
|
+
media_type=media_type,
|
|
219
|
+
media_name=media_name,
|
|
220
|
+
)
|
|
221
|
+
|
|
222
|
+
print(f"[INFO] Discovered: {len(notices)} notices")
|
|
223
|
+
print(f"[INFO] Saved to: {output_file}")
|
|
224
|
+
|
|
225
|
+
|
|
226
|
+
if __name__ == "__main__":
|
|
227
|
+
asyncio.run(discover(
|
|
228
|
+
emission_title="le masque et la plume",
|
|
229
|
+
media_type="RADIO",
|
|
230
|
+
media_name="France Inter",
|
|
231
|
+
))
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"""
|
|
2
|
+
harvest/sources/ina/parser.py
|
|
3
|
+
Module containing INA parser.
|
|
4
|
+
"""
|
|
5
|
+
from bs4 import BeautifulSoup
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class INAParser:
|
|
9
|
+
"""
|
|
10
|
+
Parse HTML pages from the INA catalogue.
|
|
11
|
+
"""
|
|
12
|
+
FIELD_MAPPING = {
|
|
13
|
+
"NO": "id",
|
|
14
|
+
"TI": "title",
|
|
15
|
+
"TICOL": "collection",
|
|
16
|
+
"CH": "channel",
|
|
17
|
+
"DATDIF": "broadcast_date",
|
|
18
|
+
"JOUR": "broadcast_day",
|
|
19
|
+
"DATENG": "recording_date",
|
|
20
|
+
"STADIF": "broadcast_type",
|
|
21
|
+
"HEURE": "start_time",
|
|
22
|
+
"HEUREFIN": "end_time",
|
|
23
|
+
"DUREE": "duration",
|
|
24
|
+
"THEMAT": "category",
|
|
25
|
+
"GENRE": "genres",
|
|
26
|
+
"TYPDESCR": "document_type",
|
|
27
|
+
"GEN": "credits",
|
|
28
|
+
"RES": "description",
|
|
29
|
+
"SP": "organization",
|
|
30
|
+
"NATPRO": "production_nature",
|
|
31
|
+
"PROD": "production",
|
|
32
|
+
"GEO": "geographic_scope",
|
|
33
|
+
"BASE": "archive_collection",
|
|
34
|
+
"FONDS": "archive_fund",
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
def parse(self, html: str) -> dict:
|
|
38
|
+
"""
|
|
39
|
+
Extract structured data from an INA notice page.
|
|
40
|
+
"""
|
|
41
|
+
soup = BeautifulSoup(html, "html.parser")
|
|
42
|
+
|
|
43
|
+
metadata = {}
|
|
44
|
+
|
|
45
|
+
for cell in soup.select("td[id]"):
|
|
46
|
+
field = self.FIELD_MAPPING.get(cell["id"])
|
|
47
|
+
|
|
48
|
+
if field:
|
|
49
|
+
metadata[field] = cell.get_text(
|
|
50
|
+
separator="\n",
|
|
51
|
+
strip=True,
|
|
52
|
+
)
|
|
53
|
+
|
|
54
|
+
return metadata
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
"""
|
|
2
|
+
harvest/sources/ina/process.py
|
|
3
|
+
Module containing INA process functions.
|
|
4
|
+
"""
|
|
5
|
+
from harvest.sources.ina.client import INAClient
|
|
6
|
+
from harvest.sources.ina.discover import slugify
|
|
7
|
+
from harvest.sources.ina.parser import INAParser
|
|
8
|
+
from harvest.utils import slugify
|
|
9
|
+
|
|
10
|
+
from pathlib import Path
|
|
11
|
+
|
|
12
|
+
import asyncio
|
|
13
|
+
import json
|
|
14
|
+
|
|
15
|
+
DATA_DIR = Path("data")
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def get_pending_items(
|
|
19
|
+
emission_title: str,
|
|
20
|
+
data_dir: Path = DATA_DIR,
|
|
21
|
+
limit: int | None = None,
|
|
22
|
+
) -> list[dict]:
|
|
23
|
+
"""
|
|
24
|
+
Find discovered notices that still require processing,
|
|
25
|
+
by comparing discovery list with existing HTML and JSON files.
|
|
26
|
+
"""
|
|
27
|
+
if limit is not None and limit < 0:
|
|
28
|
+
raise ValueError(f"Invalid limit: {limit}")
|
|
29
|
+
|
|
30
|
+
input_dir = data_dir / slugify(emission_title)
|
|
31
|
+
input_file = input_dir / "discovery.json"
|
|
32
|
+
|
|
33
|
+
if input_file.exists():
|
|
34
|
+
with input_file.open("r", encoding="utf-8") as file:
|
|
35
|
+
discovery = json.load(file)
|
|
36
|
+
|
|
37
|
+
if not isinstance(discovery, dict):
|
|
38
|
+
raise ValueError(f"Invalid discovery structure: {input_file}")
|
|
39
|
+
|
|
40
|
+
if not isinstance(discovery.get("notices"), list):
|
|
41
|
+
raise ValueError(f"Invalid notices list: {input_file}")
|
|
42
|
+
|
|
43
|
+
else:
|
|
44
|
+
raise FileNotFoundError(f"Discovery file not found: {input_file}")
|
|
45
|
+
|
|
46
|
+
# Determine the processing status of each discovered notice.
|
|
47
|
+
discovered_notices = [
|
|
48
|
+
{
|
|
49
|
+
"rank": notice["metadata"]["rank"],
|
|
50
|
+
"id": notice["id"],
|
|
51
|
+
"url": notice["url"],
|
|
52
|
+
"fetched": (input_dir / "notices" / "raw" / f"{notice['id']}.html").is_file(),
|
|
53
|
+
"extracted": (input_dir / "notices" / "extracted" / f"{notice['id']}.json").is_file(),
|
|
54
|
+
}
|
|
55
|
+
for notice in discovery["notices"]
|
|
56
|
+
if isinstance(notice, dict) and notice.get("id")
|
|
57
|
+
]
|
|
58
|
+
|
|
59
|
+
# Keep notices that still require at least one processing step.
|
|
60
|
+
pending = [
|
|
61
|
+
notice
|
|
62
|
+
for notice in discovered_notices
|
|
63
|
+
if not notice["fetched"] or not notice["extracted"]
|
|
64
|
+
]
|
|
65
|
+
|
|
66
|
+
# Apply the limit after filtering already processed notices.
|
|
67
|
+
if limit is not None:
|
|
68
|
+
pending = pending[:limit]
|
|
69
|
+
|
|
70
|
+
return pending
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
async def fetch_item(
|
|
74
|
+
client: INAClient,
|
|
75
|
+
url: str,
|
|
76
|
+
) -> str:
|
|
77
|
+
"""
|
|
78
|
+
Fetch an INA notice page and return its raw HTML.
|
|
79
|
+
"""
|
|
80
|
+
html = await client.fetch(url=url)
|
|
81
|
+
|
|
82
|
+
return html
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
def save_raw(
|
|
86
|
+
emission_title: str,
|
|
87
|
+
item_id: str,
|
|
88
|
+
html: str,
|
|
89
|
+
data_dir: Path = DATA_DIR,
|
|
90
|
+
) -> Path:
|
|
91
|
+
"""
|
|
92
|
+
Save raw HTML content to the emission's raw directory.
|
|
93
|
+
"""
|
|
94
|
+
output_dir = data_dir / slugify(emission_title) / "notices" / "raw"
|
|
95
|
+
output_dir.mkdir(parents=True, exist_ok=True)
|
|
96
|
+
|
|
97
|
+
output_file = output_dir / f"{item_id}.html"
|
|
98
|
+
output_file.write_text(html, encoding="utf-8")
|
|
99
|
+
|
|
100
|
+
return output_file
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
def extract_item(
|
|
104
|
+
emission_title: str,
|
|
105
|
+
item_id: str,
|
|
106
|
+
html: str,
|
|
107
|
+
data_dir: Path = DATA_DIR,
|
|
108
|
+
) -> Path:
|
|
109
|
+
"""
|
|
110
|
+
Extract structured data from an INA notice and save it as JSON.
|
|
111
|
+
"""
|
|
112
|
+
parser = INAParser()
|
|
113
|
+
data = parser.parse(html)
|
|
114
|
+
|
|
115
|
+
output_dir = data_dir / slugify(emission_title) / "notices" / "extracted"
|
|
116
|
+
output_dir.mkdir(parents=True, exist_ok=True)
|
|
117
|
+
|
|
118
|
+
output_file = output_dir / f"{item_id}.json"
|
|
119
|
+
|
|
120
|
+
with output_file.open("w", encoding="utf-8") as file:
|
|
121
|
+
json.dump(data, file, ensure_ascii=False, indent=4)
|
|
122
|
+
|
|
123
|
+
return output_file
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
async def process(
|
|
127
|
+
query: str,
|
|
128
|
+
limit: int | None = None,
|
|
129
|
+
) -> None:
|
|
130
|
+
emission_title = query
|
|
131
|
+
|
|
132
|
+
items = get_pending_items(
|
|
133
|
+
emission_title=emission_title,
|
|
134
|
+
limit=limit,
|
|
135
|
+
)
|
|
136
|
+
|
|
137
|
+
client = INAClient()
|
|
138
|
+
|
|
139
|
+
try:
|
|
140
|
+
for item in items:
|
|
141
|
+
html = await fetch_item(
|
|
142
|
+
client=client,
|
|
143
|
+
url=item["url"],
|
|
144
|
+
)
|
|
145
|
+
|
|
146
|
+
save_raw(
|
|
147
|
+
emission_title=emission_title,
|
|
148
|
+
item_id=item["id"],
|
|
149
|
+
html=html,
|
|
150
|
+
)
|
|
151
|
+
|
|
152
|
+
extract_item(
|
|
153
|
+
emission_title=emission_title,
|
|
154
|
+
item_id=item["id"],
|
|
155
|
+
html=html,
|
|
156
|
+
)
|
|
157
|
+
|
|
158
|
+
print(f"[INFO] Fetched and saved: {item['id']}")
|
|
159
|
+
|
|
160
|
+
await asyncio.sleep(0.5)
|
|
161
|
+
finally:
|
|
162
|
+
await client.close()
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
if __name__ == "__main__":
|
|
166
|
+
asyncio.run(process(
|
|
167
|
+
emission_title="le masque et la plume",
|
|
168
|
+
limit=10,
|
|
169
|
+
))
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"""
|
|
2
|
+
harvest/sources/ina/validation.py
|
|
3
|
+
Module containing INA validation functions.
|
|
4
|
+
"""
|
|
5
|
+
from pathlib import Path
|
|
6
|
+
|
|
7
|
+
import json
|
|
8
|
+
|
|
9
|
+
RESOURCES_DIR = Path(__file__).parent / "resources"
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def load_json(filename: str) -> list[str]:
|
|
13
|
+
path = RESOURCES_DIR / filename
|
|
14
|
+
|
|
15
|
+
with path.open(encoding="utf-8") as file:
|
|
16
|
+
return json.load(file)
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
MEDIA_TYPES = load_json("media_types.json")
|
|
20
|
+
MEDIA_NAMES = load_json("media_names.json")
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def validate_media_type(media_type: str) -> None:
|
|
24
|
+
if media_type not in MEDIA_TYPES:
|
|
25
|
+
raise ValueError(f"Unsupported media type: {media_type}")
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def validate_media_name(media_name: str) -> None:
|
|
29
|
+
if media_name not in MEDIA_NAMES:
|
|
30
|
+
raise ValueError(f"Unsupported media name: {media_name}")
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"""
|
|
2
|
+
harvest/sources/registry.py
|
|
3
|
+
Module containing sources registry.
|
|
4
|
+
"""
|
|
5
|
+
from harvest.sources import ina
|
|
6
|
+
|
|
7
|
+
from typing import Callable
|
|
8
|
+
|
|
9
|
+
SOURCES = {
|
|
10
|
+
"ina": {
|
|
11
|
+
"discover": ina.discover.discover,
|
|
12
|
+
"process": ina.process.process,
|
|
13
|
+
},
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def get_source_fn(source: str, fn: str) -> Callable:
|
|
18
|
+
"""
|
|
19
|
+
Get a function from a given source.
|
|
20
|
+
"""
|
|
21
|
+
try:
|
|
22
|
+
return SOURCES[source].get(fn)
|
|
23
|
+
except KeyError:
|
|
24
|
+
raise ValueError(f"Unknown source: {source}")
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"""
|
|
2
|
+
harvest/utils.py
|
|
3
|
+
Module containing utility functions.
|
|
4
|
+
"""
|
|
5
|
+
import re
|
|
6
|
+
import typer
|
|
7
|
+
import unicodedata
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def slugify(value: str) -> str:
|
|
11
|
+
"""
|
|
12
|
+
Convert a string into a filesystem-friendly directory name.
|
|
13
|
+
"""
|
|
14
|
+
value = unicodedata.normalize("NFKD", value)
|
|
15
|
+
value = value.encode("ascii", "ignore").decode("ascii")
|
|
16
|
+
value = value.lower()
|
|
17
|
+
value = re.sub(r"[^a-z0-9]+", "-", value)
|
|
18
|
+
|
|
19
|
+
return value.strip("-")
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def parse_options(options: list[str]) -> dict[str, str]:
|
|
23
|
+
"""
|
|
24
|
+
Parse a list of options.
|
|
25
|
+
"""
|
|
26
|
+
parsed = {}
|
|
27
|
+
|
|
28
|
+
for option in options:
|
|
29
|
+
key, separator, value = option.partition("=")
|
|
30
|
+
|
|
31
|
+
if not separator or not key:
|
|
32
|
+
raise typer.BadParameter(
|
|
33
|
+
f'Invalid option "{option}". Expected: "KEY=VALUE"'
|
|
34
|
+
)
|
|
35
|
+
|
|
36
|
+
parsed[key.replace("-", "_")] = value
|
|
37
|
+
|
|
38
|
+
return parsed
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: tool-harvest
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Data acquisition and extraction tool.
|
|
5
|
+
Author-email: Gwendal Minguy-Pèlerin <gwendalminguy@outlook.fr>
|
|
6
|
+
Maintainer-email: Gwendal Minguy-Pèlerin <gwendalminguy@outlook.fr>
|
|
7
|
+
License: MIT License
|
|
8
|
+
|
|
9
|
+
Copyright (c) 2026 Gwendal Minguy-Pèlerin
|
|
10
|
+
|
|
11
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
12
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
13
|
+
in the Software without restriction, including without limitation the rights
|
|
14
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
15
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
16
|
+
furnished to do so, subject to the following conditions:
|
|
17
|
+
|
|
18
|
+
The above copyright notice and this permission notice shall be included in all
|
|
19
|
+
copies or substantial portions of the Software.
|
|
20
|
+
|
|
21
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
22
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
23
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
24
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
25
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
26
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
27
|
+
SOFTWARE.
|
|
28
|
+
|
|
29
|
+
Project-URL: Homepage, https://github.com/gwendalminguy/tool-harvest
|
|
30
|
+
Project-URL: Repository, https://github.com/gwendalminguy/tool-harvest
|
|
31
|
+
Project-URL: Changelog, https://github.com/gwendalminguy/tool-harvest/blob/main/CHANGELOG.md
|
|
32
|
+
Keywords: cli,devtools,acquisition,extraction,productivity
|
|
33
|
+
Classifier: Programming Language :: Python :: 3
|
|
34
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
35
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
36
|
+
Classifier: Operating System :: OS Independent
|
|
37
|
+
Requires-Python: >=3.10
|
|
38
|
+
Description-Content-Type: text/markdown
|
|
39
|
+
License-File: LICENSE
|
|
40
|
+
Requires-Dist: beautifulsoup4<4.16.0,>=4.15.0
|
|
41
|
+
Requires-Dist: httpx<0.29.0,>=0.28.0
|
|
42
|
+
Requires-Dist: typer<0.30.0,>=0.29.0
|
|
43
|
+
Provides-Extra: dev
|
|
44
|
+
Requires-Dist: pytest<9.3.0,>=9.2.0; extra == "dev"
|
|
45
|
+
Requires-Dist: pytest-mock<3.18.0,>=3.17.0; extra == "dev"
|
|
46
|
+
Requires-Dist: pytest-asyncio<1.6.0,>=1.5.0; extra == "dev"
|
|
47
|
+
Requires-Dist: respx<0.24.0,>=0.23.0; extra == "dev"
|
|
48
|
+
Requires-Dist: ruff<0.18.0,>=0.17.0; extra == "dev"
|
|
49
|
+
Dynamic: license-file
|
|
50
|
+
|
|
51
|
+
# Harvest
|
|
52
|
+
|
|
53
|
+
<div align="center">
|
|
54
|
+
<a href="https://pypi.org/project/tool-harvest">
|
|
55
|
+
<img src="https://img.shields.io/pypi/v/tool-harvest?color=blue">
|
|
56
|
+
</a>
|
|
57
|
+
</div>
|
|
58
|
+
|
|
59
|
+
A data acquisition and extraction tool designed to collect, archive, and structure information from multiple sources.
|
|
60
|
+
|
|
61
|
+
## Description
|
|
62
|
+
|
|
63
|
+
The project aims to provide a reusable and extensible framework for retrieving data from different content providers and media types. The initial focus is on collecting radio programme records from the [INA Catalogue](https://catalogue.ina.fr/).
|
|
64
|
+
|
|
65
|
+
## Objectives
|
|
66
|
+
|
|
67
|
+
- Discover and index available records from external sources.
|
|
68
|
+
- Download and archive raw source documents and extract relevant information.
|
|
69
|
+
- Provide structured data that can be exported and consumed by other applications.
|
|
70
|
+
- Support multiple data sources through dedicated source integrations.
|
|
71
|
+
- Preserve source references and data provenance.
|
|
72
|
+
|
|
73
|
+
## Flow Logic
|
|
74
|
+
|
|
75
|
+
Harvest works as follow:
|
|
76
|
+
|
|
77
|
+
1. **Selection**: select a data source, a media type, a media name, and a title to search for.
|
|
78
|
+
2. **Discovery**: query the source catalogue to discover available records and their notice identifier.
|
|
79
|
+
3. **Process**: retrieve notices individually and archive their original content as HTML files.
|
|
80
|
+
4. **Extraction**: extract relevant information from the archived documents as JSON files.
|
|
81
|
+
5. **Export**: produce structured records that can be consumed by other applications.
|
|
82
|
+
|
|
83
|
+
## Project Structure
|
|
84
|
+
|
|
85
|
+
The project contains several files and directories, which are the following:
|
|
86
|
+
|
|
87
|
+
| Files | Description |
|
|
88
|
+
| :---- | :---------- |
|
|
89
|
+
| [`src/`](src/) | The package source code directory. |
|
|
90
|
+
| [`tests/`](tests/) | The package tests directory. |
|
|
91
|
+
| [`CHANGELOG.md`](CHANGELOG.md) | The markdown file listing the changes history of the tool. |
|
|
92
|
+
| [`LICENSE`](LICENSE) | The text file defining the license of the tool. |
|
|
93
|
+
| [`README.md`](README.md) | The markdown file introducting the tool. |
|
|
94
|
+
| [`pyproject.toml`](pyproject.toml) | The packaging configuration file. |
|
|
95
|
+
|
|
96
|
+
## Output Format
|
|
97
|
+
|
|
98
|
+
```
|
|
99
|
+
data/
|
|
100
|
+
└── <TITLE>/
|
|
101
|
+
├── discovery.json
|
|
102
|
+
└── notices/
|
|
103
|
+
├── raw/
|
|
104
|
+
│ └── <ID>.html
|
|
105
|
+
└── extracted/
|
|
106
|
+
└── <ID>.json
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
## Sources
|
|
110
|
+
|
|
111
|
+
The acquisition process is designed to support multiple sources.
|
|
112
|
+
|
|
113
|
+
**Available Sources**:
|
|
114
|
+
|
|
115
|
+
- [INA Catalogue](https://catalogue.ina.fr)
|
|
116
|
+
|
|
117
|
+
Additional sources may be supported as the project evolves.
|
|
118
|
+
|
|
119
|
+
## Data Acquisition
|
|
120
|
+
|
|
121
|
+
The acquisition process is divided into two distinct stages:
|
|
122
|
+
|
|
123
|
+
1. **Discover**: search external sources and build a detailed inventory of available records with their identifiers.
|
|
124
|
+
2. **Process**: retrieve individual records, archive their original content as HTML files and extract structured information as JSON files.
|
|
125
|
+
|
|
126
|
+
Raw documents are preserved independently from extracted data, allowing extraction rules to evolve without repeatedly querying external sources. All acquired data is stored locally in a `data/` directory.
|
|
127
|
+
|
|
128
|
+
## Installation
|
|
129
|
+
|
|
130
|
+
It is recommended to create a virtual environment before installing Harvest:
|
|
131
|
+
|
|
132
|
+
```bash
|
|
133
|
+
$ python3 -m venv venv
|
|
134
|
+
$ source venv/bin/activate
|
|
135
|
+
$ pip install tool-harvest
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
## Usage
|
|
139
|
+
|
|
140
|
+
Harvest can be run using the following commands:
|
|
141
|
+
|
|
142
|
+
### Discover
|
|
143
|
+
|
|
144
|
+
```bash
|
|
145
|
+
$ harvest discover <source> <query> [<options>] # Run Harvest to discover available records for a specified external source.
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
### Process
|
|
149
|
+
|
|
150
|
+
```bash
|
|
151
|
+
$ harvest process <source> <query> [<limit>] # Run Harvest to process each record by downloading it and extracting relevant information.
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
### Help
|
|
155
|
+
|
|
156
|
+
```bash
|
|
157
|
+
$ harvest --help # Show help with description for available commands.
|
|
158
|
+
$ harvest <command> --help # Show help with arguments/options description for the specified command.
|
|
159
|
+
```
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
README.md
|
|
3
|
+
pyproject.toml
|
|
4
|
+
src/harvest/__init__.py
|
|
5
|
+
src/harvest/cli.py
|
|
6
|
+
src/harvest/utils.py
|
|
7
|
+
src/harvest/sources/__init__.py
|
|
8
|
+
src/harvest/sources/registry.py
|
|
9
|
+
src/harvest/sources/ina/__init__.py
|
|
10
|
+
src/harvest/sources/ina/client.py
|
|
11
|
+
src/harvest/sources/ina/discover.py
|
|
12
|
+
src/harvest/sources/ina/parser.py
|
|
13
|
+
src/harvest/sources/ina/process.py
|
|
14
|
+
src/harvest/sources/ina/validation.py
|
|
15
|
+
src/tool_harvest.egg-info/PKG-INFO
|
|
16
|
+
src/tool_harvest.egg-info/SOURCES.txt
|
|
17
|
+
src/tool_harvest.egg-info/dependency_links.txt
|
|
18
|
+
src/tool_harvest.egg-info/entry_points.txt
|
|
19
|
+
src/tool_harvest.egg-info/requires.txt
|
|
20
|
+
src/tool_harvest.egg-info/top_level.txt
|
|
21
|
+
tests/test_utils.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
harvest
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"""
|
|
2
|
+
tests/test_utils.py
|
|
3
|
+
Utils module tests.
|
|
4
|
+
"""
|
|
5
|
+
from harvest.utils import slugify, parse_options
|
|
6
|
+
|
|
7
|
+
import pytest
|
|
8
|
+
import typer
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class TestSlugify:
|
|
12
|
+
"""
|
|
13
|
+
Tests for slugify.
|
|
14
|
+
"""
|
|
15
|
+
@pytest.mark.parametrize(
|
|
16
|
+
("value, result"),
|
|
17
|
+
[
|
|
18
|
+
("Le Masque et la Plume", "le-masque-et-la-plume"),
|
|
19
|
+
("La Terre au carré", "la-terre-au-carre"),
|
|
20
|
+
("Les Pieds sur terre", "les-pieds-sur-terre"),
|
|
21
|
+
("L'été indien", "l-ete-indien"),
|
|
22
|
+
("France Culture - Les matins", "france-culture-les-matins"),
|
|
23
|
+
("Already-normalized", "already-normalized"),
|
|
24
|
+
],
|
|
25
|
+
ids=[
|
|
26
|
+
"standard-title",
|
|
27
|
+
"title-with-accent",
|
|
28
|
+
"title-with-spaces",
|
|
29
|
+
"title-with-apostrophe",
|
|
30
|
+
"title-with-special-characters",
|
|
31
|
+
"title-already-normalized",
|
|
32
|
+
],
|
|
33
|
+
)
|
|
34
|
+
def test_slugify(self, value, result):
|
|
35
|
+
assert slugify(value) == result
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
class TestParseOptions:
|
|
39
|
+
"""
|
|
40
|
+
Tests for parse_options.
|
|
41
|
+
"""
|
|
42
|
+
@pytest.mark.parametrize(
|
|
43
|
+
("options", "result"),
|
|
44
|
+
[
|
|
45
|
+
(
|
|
46
|
+
["media-type=VALUE"],
|
|
47
|
+
{"media_type": "VALUE"},
|
|
48
|
+
),
|
|
49
|
+
(
|
|
50
|
+
["media-type=VALUE", "media-name=Value"],
|
|
51
|
+
{"media_type": "VALUE", "media_name": "Value"},
|
|
52
|
+
),
|
|
53
|
+
(
|
|
54
|
+
["media-type="],
|
|
55
|
+
{"media_type": ""},
|
|
56
|
+
),
|
|
57
|
+
],
|
|
58
|
+
ids=[
|
|
59
|
+
"option-single",
|
|
60
|
+
"option-multiple",
|
|
61
|
+
"option-missing-value",
|
|
62
|
+
],
|
|
63
|
+
)
|
|
64
|
+
def test_parse_options(self, options, result):
|
|
65
|
+
assert parse_options(options) == result
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
@pytest.mark.parametrize(
|
|
69
|
+
"options",
|
|
70
|
+
[
|
|
71
|
+
["media-type"],
|
|
72
|
+
["=VALUE"],
|
|
73
|
+
],
|
|
74
|
+
ids=[
|
|
75
|
+
"option-key-only",
|
|
76
|
+
"option-missing-key",
|
|
77
|
+
],
|
|
78
|
+
)
|
|
79
|
+
def test_parse_options_invalid(self, options):
|
|
80
|
+
with pytest.raises(typer.BadParameter):
|
|
81
|
+
parse_options(options)
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
def test_parse_options_emty(self):
|
|
85
|
+
assert parse_options([]) == {}
|