@@ -29,6 +29,42 @@ def __init__(self, crawler_id, session=requests.Session(), config="apify_config.
29
29
self ._base_url = 'https://api.apify.com/v1/' + \
30
30
self .get_user_id () + '/crawlers/' + self .get_crawler_id ()
31
31
32
+ def get_crawler_id (self ):
33
+ """Returns: crawler_id (str): crawler ID"""
34
+ return self ._crawler_id
35
+
36
+ def get_settings (self , ** kwargs ):
37
+ """Gets full crawler details and settings
38
+ https://www.apify.com/docs/api/v1#/reference/crawlers/crawler-settings/get-crawler-settings
39
+
40
+ Args:
41
+ kwargs:
42
+ noSecrets (int): If 1, response will not contain sensitive data like auth tokens (default: 0)
43
+ executionId (str): execution ID for which to return the settings (default: current settings)
44
+
45
+ Returns:
46
+ settings (JSON object): crawler settings
47
+ """
48
+ return super ()._get () # TODO ADD **KWARGS
49
+
50
+ def update_settings (self , settings = {}):
51
+ """Updates crawler settings
52
+ https://www.apify.com/docs/api/v1#/reference/crawlers/crawler-settings/update-crawler-settings
53
+
54
+ Args:
55
+ settings (JSON object): settings to be updated
56
+
57
+ Returns:
58
+ settings (JSON object): new crawler settings
59
+ """
60
+ return super ()._put (data = settings )
61
+
62
+ def delete (self ):
63
+ """Deletes the crawler
64
+ https://www.apify.com/docs/api/v1#/reference/crawlers/crawler-settings/delete-crawler
65
+ """
66
+ return super ()._delete ()
67
+
32
68
def start (self , settings = {}, ** kwargs ):
33
69
"""Executes crawler
34
70
https://www.apify.com/docs/api/v1#/reference/executions/start-execution/start-execution
@@ -62,6 +98,23 @@ def start(self, settings={}, **kwargs):
62
98
r .raise_for_status ()
63
99
return r .json ()
64
100
101
+ def get_list_of_executions (self , ** kwargs ):
102
+ """Gets the crawler's list of executions
103
+ https://www.apify.com/docs/api/v1#/reference/executions/list-of-executions/get-list-of-executions
104
+
105
+ Args:
106
+ kwargs:
107
+ status (str): Filter for the execution status (default: no filter)
108
+ offset (int): Rank of first execution to return (default: 0)
109
+ limit (int): Maximum number of executions to return (default: 1000)
110
+ desc (int): If 1, executions are sorted from newest to oldest (default: None)
111
+
112
+ Returns:
113
+ execution_list (JSON object): list of executions and their metadata
114
+ """
115
+ url = self ._base_url + "/execs"
116
+ return super ()._get (url , None , ** kwargs )
117
+
65
118
def get_last_execution (self , ** kwargs ):
66
119
"""Gets information about the crawler's last execution
67
120
https://www.apify.com/docs/api/v1#/reference/executions/last-execution/get-last-execution
@@ -109,55 +162,6 @@ def get_last_execution_results(self, status=None, combine=False, **kwargs):
109
162
110
163
return execution .get_results (combine = combine , ** kwargs )
111
164
112
- def delete (self ):
113
- """Deletes the crawler
114
- https://www.apify.com/docs/api/v1#/reference/crawlers/crawler-settings/delete-crawler
115
- """
116
- return super ()._delete ()
117
-
118
- def get_settings (self , ** kwargs ):
119
- """Gets full details and settings of a specific crawler
120
- https://www.apify.com/docs/api/v1#/reference/crawlers/crawler-settings/get-crawler-settings
121
-
122
- Args:
123
- kwargs:
124
- noSecrets (int): If 1, response will not contain sensitive data like auth tokens (default: 0)
125
- executionId (str): execution ID for which to return the settings (default: current settings)
126
-
127
- Returns:
128
- settings (JSON object): crawler settings
129
- """
130
- return super ()._get ()
131
-
132
- def update_settings (self , settings = {}):
133
- """Updates a specific crawler's settings
134
- https://www.apify.com/docs/api/v1#/reference/crawlers/crawler-settings/update-crawler-settings
135
-
136
- Args:
137
- settings (JSON object): settings to be updated
138
-
139
- Returns:
140
- settings (JSON object): new crawler settings
141
- """
142
- return super ()._put (data = settings )
143
-
144
- def get_list_of_executions (self , ** kwargs ):
145
- """Gets the crawler's list of executions
146
- https://www.apify.com/docs/api/v1#/reference/executions/list-of-executions/get-list-of-executions
147
-
148
- Args:
149
- kwargs:
150
- status (str): Filter for the execution status (default: no filter)
151
- offset (int): Rank of first execution to return (default: 0)
152
- limit (int): Maximum number of executions to return (default: 1000)
153
- desc (int): If 1, executions are sorted from newest to oldest (default: None)
154
-
155
- Returns:
156
- execution_list (JSON object): list of executions and their metadata
157
- """
158
- url = self ._base_url + "/execs"
159
- return super ()._get (url , None , ** kwargs )
160
-
161
165
def stop_last_execution (self ):
162
166
"""Stops the last crawler execution
163
167
https://www.apify.com/docs/api/v1#/reference/executions/stop-execution
@@ -169,10 +173,6 @@ def stop_last_execution(self):
169
173
execution = Execution (execution_id , session = self .get_session (), config = self ._config )
170
174
return execution .stop ()
171
175
172
- def get_crawler_id (self ):
173
- """Returns: crawler_id (str): crawler ID"""
174
- return self ._crawler_id
175
-
176
176
177
177
class Execution (CrawlerABC ):
178
178
def __init__ (self , execution_id , session = requests .Session (), config = "apify_config.json" ):
@@ -188,6 +188,29 @@ def __init__(self, execution_id, session=requests.Session(), config="apify_confi
188
188
self ._execution_id = execution_id
189
189
self ._base_url = "https://api.apify.com/v1/execs/" + self .get_execution_id ()
190
190
191
+ def get_execution_id (self ):
192
+ """Returns: execution_id (str): crawler ID"""
193
+ return self ._execution_id
194
+
195
+ def stop (self ):
196
+ """Stops the execution
197
+ https://www.apify.com/docs/api/v1#/reference/executions/stop-execution/
198
+
199
+ Returns:
200
+ execution_details (JSON object): execution details
201
+ """
202
+ url = self ._base_url + "/stop"
203
+ return super ()._post (url )
204
+
205
+ def get_details (self ):
206
+ """Gets execution details
207
+ https://www.apify.com/docs/api/v1#/reference/executions/execution-details/get-execution-details
208
+
209
+ Returns:
210
+ execution_details (JSON object): execution details
211
+ """
212
+ return super ()._get ()
213
+
191
214
def get_results (self , combine = False , ** kwargs ):
192
215
""" Gets execution results
193
216
https://www.apify.com/docs/api/v1#/reference/executions
@@ -246,26 +269,3 @@ def get_results(self, combine=False, **kwargs):
246
269
else :
247
270
result = r .text
248
271
return result
249
-
250
- def stop (self ):
251
- """Stops the execution
252
- https://www.apify.com/docs/api/v1#/reference/executions/stop-execution/stop-execution
253
-
254
- Returns:
255
- execution_details (JSON object): execution details
256
- """
257
- url = self ._base_url + "/stop"
258
- return super ()._post (url )
259
-
260
- def get_details (self ):
261
- """Gets execution details
262
- https://www.apify.com/docs/api/v1#/reference/executions/execution-details/get-execution-details
263
-
264
- Returns:
265
- execution_details (JSON object): execution details
266
- """
267
- return super ()._get ()
268
-
269
- def get_execution_id (self ):
270
- """Returns: execution_id (str): crawler ID"""
271
- return self ._execution_id
0 commit comments