pyritrix3 0.0.1__py3-none-any.whl

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.
pyritrix3/__init__.py ADDED
@@ -0,0 +1 @@
1
+ from .pyritrix import pyritrix
pyritrix3/jobs.py ADDED
@@ -0,0 +1,164 @@
1
+ from typing import TYPE_CHECKING, IO
2
+
3
+ if TYPE_CHECKING:
4
+ from .pyritrix import pyritrix
5
+
6
+
7
+ class JobsEndpoint:
8
+ def __init__(self, client: pyritrix):
9
+ self._client = client
10
+
11
+ def create(self, createpath: str, profile=None) -> dict:
12
+ """
13
+ Creates a new crawl job from the selected profile.
14
+ If no profile is supplied, Defaults (XML) is used.
15
+ Built-in profiles include Defaults (XML) and Defaults (Groovy).
16
+ Existing job profiles may also be selected by passing the profile job’s short name.
17
+ Arguments:
18
+ createpath: the name of the new job
19
+ profile: optional profile name. Existing profiles use their job short names.
20
+ """
21
+ data = {
22
+ "action": "create",
23
+ "createpath": createpath,
24
+ "profile": profile # It's fine, requests will omit this if profile=None
25
+ }
26
+ response = self._client.post("/engine", data=data)
27
+ assert response.status_code == 200
28
+ return response.json()
29
+
30
+ def add(self, addpath: str) -> dict:
31
+ """
32
+ Adds a new job directory to the Heritrix configuration.
33
+ The directory must contain a cxml configuration file.
34
+ Arguments:
35
+ action: must be add
36
+ addpath: the job directory to add
37
+ """
38
+ data = {
39
+ "action": "add",
40
+ "addpath": addpath
41
+ }
42
+ response = self._client.post("/engine", data=data)
43
+ return response.json()
44
+
45
+ def get(self, jobname: str) -> dict:
46
+ """
47
+ Returns status information and statistics about the chosen job.
48
+ """
49
+ return self._client.get(f"/engine/job/{jobname}").json()
50
+
51
+ def build(self, jobname: str) -> dict:
52
+ """
53
+ Builds the job configuration for the chosen job. It reads an XML descriptor file and uses
54
+ Spring to build the Java objects that are necessary for running the crawl.
55
+ Before a crawl can be run it must be built.
56
+ """
57
+ data = {"action": "build"}
58
+ response = self._client.post(f"/engine/job/{jobname}", data=data)
59
+ return response.json()
60
+
61
+ def launch(self, jobname: str, checkpoint: str) -> dict:
62
+ """
63
+ Launches a crawl job. The job can be launched in the “paused” state or the “unpaused” state.
64
+ If launched in the “unpaused” state the job will immediately begin crawling.
65
+ Arguments:
66
+ checkpoint: optional field. If supplied, Heritrix will attempt to launch from a checkpoint.
67
+ Should be the name of a checkpoint (e.g. cp00001-20180102121229) or (since version 3.3)
68
+ the special value latest, which will automatically select the most recent checkpoint.
69
+ If no checkpoint is specified (or if the latest checkpoint is requested and there
70
+ are no valid checkpoints) a new crawl will be launched.
71
+ """
72
+ data = {
73
+ "action": "launch",
74
+ "checkpoint": checkpoint
75
+ }
76
+ response = self._client.post(f"/engine/job/{jobname}", data=data)
77
+ return response.json()
78
+
79
+ def rescan(self) -> dict:
80
+ """
81
+ Rescans the main job directory and returns an HTML page containing all the job names.
82
+ It also returns information about the jobs, such as the location of the job
83
+ configuration file and the number of job launches.
84
+ """
85
+
86
+ return self._client.post("/engine", data={"action": "rescan"}).json()
87
+
88
+ def pause(self, jobname: str) -> dict:
89
+ """
90
+ Pauses an unpaused job. No crawling will occur while a job is paused.
91
+ """
92
+ return self._client.post(f"/engine/job/{jobname}", data={"action": "pause"}).json()
93
+
94
+ def unpause(self, jobname: str) -> dict:
95
+ """
96
+ This API unpauses a paused job. Crawling will resume (or begin, in the case of
97
+ a job launched in the paused state) if possible.
98
+ """
99
+ return self._client.post(f"/engine/job/{jobname}", data={"action": "unpause"}).json()
100
+
101
+ def terminate(self, jobname: str) -> dict:
102
+ """
103
+ Terminates a runnig job.
104
+ """
105
+ return self._client.post(f"/engine/job/{jobname}", data={"action": "terminate"}).json()
106
+
107
+ def teardown(self, jobname: str) -> dict:
108
+ """
109
+ Removes the Spring code that is used to run the job. Once a job is torn down it must be rebuilt in order to run.
110
+ """
111
+ return self._client.post(f"/engine/job/{jobname}", data={"action": "teardown"}).json()
112
+
113
+ def copy(self, jobname: str, copyTo: str, asProfile: bool) -> dict:
114
+ """
115
+ Copies an existing job configuration to a new job configuration. If the asProfile option is submitted with value on,
116
+ then the copy is a non-runnable profile. Profiles are listed as options when creating new jobs,
117
+ and profiles with built-in names override the built-ins.
118
+ Arguments:
119
+ copyTo: the name of the new job or profile configuration
120
+ asProfile: whether to copy the job as a runnable configuration or as a non-runnable profile.
121
+ True means the job will be copied as a profile.
122
+ """
123
+ data = {
124
+ "copyTo": copyTo,
125
+ }
126
+ if asProfile:
127
+ data["asProfile"] = "on"
128
+ return self._client.post(f"/engine/job/{jobname}", data=data).json()
129
+
130
+ def delete(self, jobname: str) -> dict:
131
+ """
132
+ Deletes an existing job. It will remove everything related to the job (configuration, statistics, logs and results)
133
+ including the whole job folder. Everything to keep has to be copied outside of the job folder.
134
+
135
+ Deleting a job is only possible if no active application context for the job exists which is
136
+ the case for new or unbuilt jobs. If a job has been built, it must first be torn down to allow deletion.
137
+ """
138
+ return self._client.post(f"/engine/job/{jobname}", data={"action": "delete"}).json()
139
+
140
+ def checkpoint(self, jobname: str) -> dict:
141
+ """
142
+ This API checkpoints the chosen job. Checkpointing writes the current state of a crawl
143
+ to the file system so that the crawl can be recovered if it fails.
144
+ """
145
+ return self._client.post(f"/engine/job/{jobname}", data={"action": "checkpoint"}).json()
146
+
147
+ def execute_script(self, jobname: str, engine: str, script: str) -> dict:
148
+ """
149
+ Executes a script. The script can be written as Beanshell, ECMAScript, Groovy, or AppleScript.
150
+ Arguments:
151
+ engine: the script engine to use. One of beanshell, js, groovy or AppleScriptEngine.
152
+ script: the script code to execute
153
+ """
154
+ assert script in ["beanshell", "js", "groovy", "AppleScriptEngine"]
155
+ data = {
156
+ "engine": engine,
157
+ "script": script
158
+ }
159
+ return self._client.post(f"/engine/job/{jobname}/script", data=data).json()
160
+
161
+ def submit_config_file(self, jobname: str, file: IO):
162
+ response = self._client.put(
163
+ f"/engine/job/{jobname}/crawler-beans.cxml", data=file)
164
+ assert response.status_code == 200
pyritrix3/pyritrix.py ADDED
@@ -0,0 +1,34 @@
1
+ import requests
2
+ from requests.auth import HTTPDigestAuth
3
+ from urllib.parse import urljoin
4
+ from .jobs import JobsEndpoint
5
+
6
+ common_headers = {
7
+ "Accept": "application/json"
8
+ }
9
+
10
+
11
+ class pyritrix():
12
+ def __init__(self, hostname: str, username: str, password: str, port=8443, verify_certs=True):
13
+ self.session = requests.Session()
14
+ self.session.auth = HTTPDigestAuth(username, password)
15
+ self.verify_certs = verify_certs
16
+ self.base_url = f"https://{hostname}:{port}/"
17
+ self.jobs = JobsEndpoint(self)
18
+
19
+ def get(self, path: str, **kwargs) -> requests.Response:
20
+ return self.session.get(
21
+ urljoin(self.base_url, path), headers=common_headers, verify=self.verify_certs, **kwargs)
22
+
23
+ def post(self, path: str, **kwargs) -> requests.Response:
24
+ return self.session.post(
25
+ urljoin(self.base_url, path), headers=common_headers, verify=self.verify_certs, **kwargs)
26
+
27
+ def post(self, path: str, **kwargs) -> requests.Response:
28
+ return self.session.put(urljoin(self.base_url, path), headers=common_headers, verify=self.verify_certs, **kwargs)
29
+
30
+ def status(self) -> dict:
31
+ """
32
+ Returns information about this instance of Heritrix such as version number, memory usage and the list of crawl jobs.
33
+ """
34
+ return self.get("/engine").json()
@@ -0,0 +1,16 @@
1
+ Metadata-Version: 2.5
2
+ Name: pyritrix3
3
+ Version: 0.0.1
4
+ Summary: A simple wrapper around Heritrix3' REST API
5
+ Project-URL: Homepage, https://github.com/obrotowy/pyritrix3
6
+ Project-URL: Issues, https://github.com/obrotowy/pyritrix3/issues
7
+ Author-email: Emilian Zawrotny <emilian@zawrotny.pl>
8
+ License-Expression: MIT
9
+ License-File: LICENSE
10
+ Classifier: Operating System :: OS Independent
11
+ Classifier: Programming Language :: Python :: 3
12
+ Requires-Python: >=3.9
13
+ Requires-Dist: requests>=2.34.2
14
+ Description-Content-Type: text/markdown
15
+
16
+ Simple wrapper around [Hetririx3](https://github.com/internetarchive/heritrix3) REST API
@@ -0,0 +1,7 @@
1
+ pyritrix3/__init__.py,sha256=ubnW3mcQpam0POjMaqogyufmWZ55erToYYf-X-9arkQ,31
2
+ pyritrix3/jobs.py,sha256=P6z2bmWwI2DuE3ua0_7wtY7sXwUVSUBg1DTIEJViDhg,7175
3
+ pyritrix3/pyritrix.py,sha256=skKdKqVuRCno-zsdbLulxznMwEbLIMlRRNmOt0Zg9K8,1337
4
+ pyritrix3-0.0.1.dist-info/METADATA,sha256=b1SIU2XeC38lzKhsDevI7n-tBwLQ6OceMHXU_skxak8,611
5
+ pyritrix3-0.0.1.dist-info/WHEEL,sha256=zOwg4jB6zX2kU910N-cMawjivD6tO8NEWvE12je1bVk,87
6
+ pyritrix3-0.0.1.dist-info/licenses/LICENSE,sha256=-IXAMVx1mBWkca9gf9l-eKGpEUsYvH3DpFjjbu7BwVs,1073
7
+ pyritrix3-0.0.1.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: hatchling 1.32.0
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Emilian Zawrotny
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.