rara-tools 0.0.8__tar.gz → 0.0.10__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.

Potentially problematic release.


This version of rara-tools might be problematic. Click here for more details.

Files changed (30) hide show
  1. {rara_tools-0.0.8/rara_tools.egg-info → rara_tools-0.0.10}/PKG-INFO +33 -18
  2. {rara_tools-0.0.8 → rara_tools-0.0.10}/README.md +31 -17
  3. rara_tools-0.0.10/VERSION +1 -0
  4. rara_tools-0.0.10/rara_tools/converters.py +41 -0
  5. {rara_tools-0.0.8 → rara_tools-0.0.10}/rara_tools/decorators.py +3 -3
  6. rara_tools-0.0.10/rara_tools/digar_schema_converter.py +409 -0
  7. {rara_tools-0.0.8 → rara_tools-0.0.10}/rara_tools/elastic.py +1 -1
  8. {rara_tools-0.0.8 → rara_tools-0.0.10}/rara_tools/exceptions.py +3 -0
  9. {rara_tools-0.0.8 → rara_tools-0.0.10}/rara_tools/s3.py +3 -2
  10. rara_tools-0.0.10/rara_tools/utils.py +104 -0
  11. {rara_tools-0.0.8 → rara_tools-0.0.10/rara_tools.egg-info}/PKG-INFO +33 -18
  12. {rara_tools-0.0.8 → rara_tools-0.0.10}/rara_tools.egg-info/SOURCES.txt +5 -0
  13. {rara_tools-0.0.8 → rara_tools-0.0.10}/rara_tools.egg-info/requires.txt +1 -0
  14. {rara_tools-0.0.8 → rara_tools-0.0.10}/requirements.txt +1 -0
  15. rara_tools-0.0.10/tests/test_converters.py +105 -0
  16. rara_tools-0.0.10/tests/test_digar_schema_converter.py +133 -0
  17. {rara_tools-0.0.8 → rara_tools-0.0.10}/tests/test_elastic.py +0 -1
  18. {rara_tools-0.0.8 → rara_tools-0.0.10}/tests/test_s3_exceptions.py +4 -3
  19. {rara_tools-0.0.8 → rara_tools-0.0.10}/tests/test_task_reporter.py +1 -0
  20. rara_tools-0.0.8/VERSION +0 -1
  21. {rara_tools-0.0.8 → rara_tools-0.0.10}/LICENSE.md +0 -0
  22. {rara_tools-0.0.8 → rara_tools-0.0.10}/pyproject.toml +0 -0
  23. {rara_tools-0.0.8 → rara_tools-0.0.10}/rara_tools/constants/__init__.py +0 -0
  24. {rara_tools-0.0.8 → rara_tools-0.0.10}/rara_tools/constants/digitizer.py +0 -0
  25. {rara_tools-0.0.8 → rara_tools-0.0.10}/rara_tools/constants/general.py +0 -0
  26. {rara_tools-0.0.8 → rara_tools-0.0.10}/rara_tools/task_reporter.py +0 -0
  27. {rara_tools-0.0.8 → rara_tools-0.0.10}/rara_tools.egg-info/dependency_links.txt +0 -0
  28. {rara_tools-0.0.8 → rara_tools-0.0.10}/rara_tools.egg-info/top_level.txt +0 -0
  29. {rara_tools-0.0.8 → rara_tools-0.0.10}/setup.cfg +0 -0
  30. {rara_tools-0.0.8 → rara_tools-0.0.10}/tests/test_s3_file_operations.py +1 -1
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: rara-tools
3
- Version: 0.0.8
3
+ Version: 0.0.10
4
4
  Summary: Tools to support Kata's work.
5
5
  Classifier: Programming Language :: Python :: 3
6
6
  Classifier: Programming Language :: Python :: 3.10
@@ -14,6 +14,7 @@ Requires-Dist: elasticsearch==8.*
14
14
  Requires-Dist: elasticsearch_dsl==8.*
15
15
  Requires-Dist: minio==7.*
16
16
  Requires-Dist: requests
17
+ Requires-Dist: iso639-lang
17
18
  Provides-Extra: testing
18
19
  Requires-Dist: pytest>=8.0; extra == "testing"
19
20
  Requires-Dist: pytest-order; extra == "testing"
@@ -28,25 +29,28 @@ Requires-Dist: pytest-order; extra == "testing"
28
29
 
29
30
  ---
30
31
 
31
- ## ✨ Features
32
+ ## ✨ Features
32
33
 
33
34
  - Elasticsearch index & document operations
34
35
  - S3 file management operations
35
36
  - Task reporting to Core API
37
+ - Converting SIERRA API responses to Pymarc compatible JSON
38
+
36
39
  ---
37
40
 
38
- ## ⚡ Quick Start
41
+ ## ⚡ Quick Start
39
42
 
40
43
  Get started with `rara-tools` in just a few steps:
41
44
 
42
45
  1. **Install the Package**
43
- Ensure you're using Python 3.10 or above, then run:
46
+ Ensure you're using Python 3.10 or above, then run:
47
+
44
48
  ```bash
45
49
  pip install rara-tools
46
50
  ```
47
51
 
48
52
  2. **Import and Use**
49
- Example usage to download a folder from S3:
53
+ Example usage to download a folder from S3:
50
54
 
51
55
  ```python
52
56
  from rara_tools.s3 import S3Files
@@ -77,22 +81,25 @@ Follow the steps below to install the `rara-tools` package, either via `pip` or
77
81
  Create or activate a Python environment using Python **3.10** or above.
78
82
 
79
83
  2. **Install the Package**
80
- Run the following command:
84
+ Run the following command:
85
+
81
86
  ```bash
82
87
  pip install rara-tools
83
88
  ```
84
- </details>
89
+
90
+ </details>
85
91
 
86
92
  ---
87
93
 
88
94
  ### Local Installation
89
95
 
90
- Follow these steps to install the `rara-tools` package locally:
96
+ Follow these steps to install the `rara-tools` package locally:
91
97
 
92
98
  <details><summary>Click to expand</summary>
93
99
 
94
100
  1. **Clone the Repository**
95
- Clone the repository and navigate into it:
101
+ Clone the repository and navigate into it:
102
+
96
103
  ```bash
97
104
  git clone <repository-url>
98
105
  cd <repository-directory>
@@ -100,25 +107,29 @@ Follow these steps to install the `rara-tools` package locally:
100
107
 
101
108
  2. **Set Up Python Environment**
102
109
  Create or activate a Python environment using Python 3.10 or above. E.g:
110
+
103
111
  ```bash
104
112
  conda create -n py310 python==3.10
105
113
  conda activate py310
106
114
  ```
107
115
 
108
116
  3. **Install Build Package**
109
- Install the `build` package to enable local builds:
117
+ Install the `build` package to enable local builds:
118
+
110
119
  ```bash
111
120
  pip install build
112
121
  ```
113
122
 
114
123
  4. **Build the Package**
115
- Run the following command inside the repository:
124
+ Run the following command inside the repository:
125
+
116
126
  ```bash
117
127
  python -m build
118
128
  ```
119
129
 
120
130
  5. **Install the Package**
121
- Install the built package locally:
131
+ Install the built package locally:
132
+
122
133
  ```bash
123
134
  pip install .
124
135
  ```
@@ -131,13 +142,13 @@ Follow these steps to install the `rara-tools` package locally:
131
142
 
132
143
  Follow these steps to test the `rara-tools` package.
133
144
 
134
-
135
145
  ### How to Test
136
146
 
137
147
  <details><summary>Click to expand</summary>
138
148
 
139
149
  1. **Clone the Repository**
140
- Clone the repository and navigate into it:
150
+ Clone the repository and navigate into it:
151
+
141
152
  ```bash
142
153
  git clone <repository-url>
143
154
  cd <repository-directory>
@@ -147,25 +158,29 @@ Follow these steps to test the `rara-tools` package.
147
158
  Create or activate a Python environment using Python 3.10 or above.
148
159
 
149
160
  3. **Install Build Package**
150
- Install the `build` package:
161
+ Install the `build` package:
162
+
151
163
  ```bash
152
164
  pip install build
153
165
  ```
154
166
 
155
167
  4. **Build the Package**
156
- Build the package inside the repository:
168
+ Build the package inside the repository:
169
+
157
170
  ```bash
158
171
  python -m build
159
172
  ```
160
173
 
161
174
  5. **Install with Testing Dependencies**
162
- Install the package along with its testing dependencies:
175
+ Install the package along with its testing dependencies:
176
+
163
177
  ```bash
164
178
  pip install .[testing]
165
179
  ```
166
180
 
167
181
  6. **Run Tests**
168
- Run the test suite from the repository root:
182
+ Run the test suite from the repository root:
183
+
169
184
  ```bash
170
185
  python -m pytest -v tests
171
186
  ```
@@ -8,25 +8,28 @@
8
8
 
9
9
  ---
10
10
 
11
- ## ✨ Features
11
+ ## ✨ Features
12
12
 
13
13
  - Elasticsearch index & document operations
14
14
  - S3 file management operations
15
15
  - Task reporting to Core API
16
+ - Converting SIERRA API responses to Pymarc compatible JSON
17
+
16
18
  ---
17
19
 
18
- ## ⚡ Quick Start
20
+ ## ⚡ Quick Start
19
21
 
20
22
  Get started with `rara-tools` in just a few steps:
21
23
 
22
24
  1. **Install the Package**
23
- Ensure you're using Python 3.10 or above, then run:
25
+ Ensure you're using Python 3.10 or above, then run:
26
+
24
27
  ```bash
25
28
  pip install rara-tools
26
29
  ```
27
30
 
28
31
  2. **Import and Use**
29
- Example usage to download a folder from S3:
32
+ Example usage to download a folder from S3:
30
33
 
31
34
  ```python
32
35
  from rara_tools.s3 import S3Files
@@ -57,22 +60,25 @@ Follow the steps below to install the `rara-tools` package, either via `pip` or
57
60
  Create or activate a Python environment using Python **3.10** or above.
58
61
 
59
62
  2. **Install the Package**
60
- Run the following command:
63
+ Run the following command:
64
+
61
65
  ```bash
62
66
  pip install rara-tools
63
67
  ```
64
- </details>
68
+
69
+ </details>
65
70
 
66
71
  ---
67
72
 
68
73
  ### Local Installation
69
74
 
70
- Follow these steps to install the `rara-tools` package locally:
75
+ Follow these steps to install the `rara-tools` package locally:
71
76
 
72
77
  <details><summary>Click to expand</summary>
73
78
 
74
79
  1. **Clone the Repository**
75
- Clone the repository and navigate into it:
80
+ Clone the repository and navigate into it:
81
+
76
82
  ```bash
77
83
  git clone <repository-url>
78
84
  cd <repository-directory>
@@ -80,25 +86,29 @@ Follow these steps to install the `rara-tools` package locally:
80
86
 
81
87
  2. **Set Up Python Environment**
82
88
  Create or activate a Python environment using Python 3.10 or above. E.g:
89
+
83
90
  ```bash
84
91
  conda create -n py310 python==3.10
85
92
  conda activate py310
86
93
  ```
87
94
 
88
95
  3. **Install Build Package**
89
- Install the `build` package to enable local builds:
96
+ Install the `build` package to enable local builds:
97
+
90
98
  ```bash
91
99
  pip install build
92
100
  ```
93
101
 
94
102
  4. **Build the Package**
95
- Run the following command inside the repository:
103
+ Run the following command inside the repository:
104
+
96
105
  ```bash
97
106
  python -m build
98
107
  ```
99
108
 
100
109
  5. **Install the Package**
101
- Install the built package locally:
110
+ Install the built package locally:
111
+
102
112
  ```bash
103
113
  pip install .
104
114
  ```
@@ -111,13 +121,13 @@ Follow these steps to install the `rara-tools` package locally:
111
121
 
112
122
  Follow these steps to test the `rara-tools` package.
113
123
 
114
-
115
124
  ### How to Test
116
125
 
117
126
  <details><summary>Click to expand</summary>
118
127
 
119
128
  1. **Clone the Repository**
120
- Clone the repository and navigate into it:
129
+ Clone the repository and navigate into it:
130
+
121
131
  ```bash
122
132
  git clone <repository-url>
123
133
  cd <repository-directory>
@@ -127,25 +137,29 @@ Follow these steps to test the `rara-tools` package.
127
137
  Create or activate a Python environment using Python 3.10 or above.
128
138
 
129
139
  3. **Install Build Package**
130
- Install the `build` package:
140
+ Install the `build` package:
141
+
131
142
  ```bash
132
143
  pip install build
133
144
  ```
134
145
 
135
146
  4. **Build the Package**
136
- Build the package inside the repository:
147
+ Build the package inside the repository:
148
+
137
149
  ```bash
138
150
  python -m build
139
151
  ```
140
152
 
141
153
  5. **Install with Testing Dependencies**
142
- Install the package along with its testing dependencies:
154
+ Install the package along with its testing dependencies:
155
+
143
156
  ```bash
144
157
  pip install .[testing]
145
158
  ```
146
159
 
147
160
  6. **Run Tests**
148
- Run the test suite from the repository root:
161
+ Run the test suite from the repository root:
162
+
149
163
  ```bash
150
164
  python -m pytest -v tests
151
165
  ```
@@ -0,0 +1 @@
1
+ 0.0.10
@@ -0,0 +1,41 @@
1
+ from .exceptions import SierraResponseConverterException
2
+
3
+
4
+ class SierraResponseConverter:
5
+ """ Takes a JSON response from the Sierra API (https://tester.ester.ee/iii/sierra-api/swagger/index.html)
6
+ and converts it to MARC-in-JSON format.
7
+
8
+ """
9
+
10
+ def __init__(self, response: dict):
11
+ if not isinstance(response, dict):
12
+ raise SierraResponseConverterException("Please provide a valid JSON response.")
13
+ self.response = response
14
+
15
+ def _map_field_data(self, field):
16
+ tag = field.get("tag")
17
+ if not tag:
18
+ raise SierraResponseConverterException("Field is missing a valid 'tag'.")
19
+ data = field.get("data", {})
20
+ return {tag: data}
21
+
22
+ def _convert_response(self):
23
+ response = self.response
24
+
25
+ entries = response.get("entries")
26
+ if not entries:
27
+ raise SierraResponseConverterException("No entries found in the response.")
28
+
29
+ try:
30
+ fields = [self._map_field_data(f) for e in entries for f in e["marc"]["fields"]]
31
+ except KeyError as e:
32
+ raise SierraResponseConverterException(f"Missing expected MARC fields in the response: {e}")
33
+
34
+ return {"fields": fields}
35
+
36
+ def convert(self):
37
+ """Runner method, converts the response to MARC-in-JSON format with error handling."""
38
+ try:
39
+ return self._convert_response()
40
+ except Exception as e:
41
+ raise SierraResponseConverterException(f"An unexpected error occurred during conversion: {e}")
@@ -1,12 +1,12 @@
1
1
  import functools
2
+ from typing import Any, Callable
3
+
2
4
  from elasticsearch import AuthenticationException
3
5
  from elasticsearch import ConnectionError as ElasticsearchConnectionError
4
6
  from elasticsearch import ConnectionTimeout, NotFoundError, RequestError
5
- from typing import Any, Callable
6
7
 
7
8
  from .exceptions import ElasticsearchException
8
9
 
9
-
10
10
  ELASTIC_NOT_FOUND_MESSAGE = 'Could not find specified data from Elasticsearch!'
11
11
  ELASTIC_REQUEST_ERROR_MESSAGE = 'Error executing Elasticsearch query! Bad query?'
12
12
  ELASTIC_CONNECTION_TIMEOUT_MESSAGE = 'Connection to Elasticsearch took too long, please try again later!'
@@ -39,4 +39,4 @@ def _elastic_connection(func: Callable) -> Callable:
39
39
  raise ElasticsearchException(ELASTIC_CONNECTION_ERROR_MESSAGE) from exception
40
40
  except Exception as exception:
41
41
  raise ElasticsearchException(ELASTIC_UNKNOWN_ERROR_MESSAGE) from exception
42
- return wrapper
42
+ return wrapper