Skip to content

Commit 93582c3

Browse files
committed
Add missing docstrings
1 parent ac2a052 commit 93582c3

File tree

5 files changed

+75
-4
lines changed

5 files changed

+75
-4
lines changed

scrapinghub/client/activity.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,13 @@ class Activity(_Proxy):
4444
>>> project.activity.add(events)
4545
4646
"""
47-
def __init__(self, *args, **kwargs):
48-
super(Activity, self).__init__(*args, **kwargs)
49-
5047
def iter(self, **params):
48+
"""Iterate over activity events.
49+
50+
:return: a generator object over a list of activity event dicts.
51+
:rtype: :class:`types.GeneratorType[dict]`
52+
"""
53+
# TODO describe allowable params
5154
params = self._modify_iter_params(params)
5255
return self._origin.list(**params)
5356

scrapinghub/client/collections.py

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,11 +181,29 @@ def delete(self, keys):
181181
self._origin.delete(keys)
182182

183183
def count(self, *args, **kwargs):
184+
"""Count collection items with a given filters.
185+
186+
:return: amount of elements in collection.
187+
:rtype: :class:`int`
188+
"""
189+
# TODO describe allowable params
184190
return self._origin._collections.count(
185191
self._origin.coltype, self._origin.colname, *args, **kwargs)
186192

187193
def iter(self, key=None, prefix=None, prefixcount=None, startts=None,
188194
endts=None, requests_params=None, **params):
195+
"""A method to iterate through collection items.
196+
197+
:param key: a string key or a list of keys to filter with.
198+
:param prefix: a string prefix to filter items.
199+
:param prefixcount: maximum number of values to return per prefix.
200+
:param startts: UNIX timestamp at which to begin results.
201+
:param endts: UNIX timestamp at which to end results.
202+
:param requests_params: (optional) a dict with optional requests params.
203+
:param \*\*params: (optional) additional query params for the request.
204+
:return: an iterator over items list.
205+
:rtype: :class:`collections.Iterable[dict]`
206+
"""
189207
update_kwargs(params, key=key, prefix=prefix, prefixcount=prefixcount,
190208
startts=startts, endts=endts,
191209
requests_params=requests_params)
@@ -195,6 +213,19 @@ def iter(self, key=None, prefix=None, prefixcount=None, startts=None,
195213

196214
def iter_raw_json(self, key=None, prefix=None, prefixcount=None,
197215
startts=None, endts=None, requests_params=None, **params):
216+
"""A method to iterate through json pack-ed items.
217+
Can be convenient if data is needed in the json format.
218+
219+
:param key: a string key or a list of keys to filter with.
220+
:param prefix: a string prefix to filter items.
221+
:param prefixcount: maximum number of values to return per prefix.
222+
:param startts: UNIX timestamp at which to begin results.
223+
:param endts: UNIX timestamp at which to end results.
224+
:param requests_params: (optional) a dict with optional requests params.
225+
:param \*\*params: (optional) additional query params for the request.
226+
:return: an iterator over items list packed with json.
227+
:rtype: :class:`collections.Iterable[str]`
228+
"""
198229
update_kwargs(params, key=key, prefix=prefix, prefixcount=prefixcount,
199230
startts=startts, endts=endts,
200231
requests_params=requests_params)
@@ -248,6 +279,18 @@ def list(self, key=None, prefix=None, prefixcount=None, startts=None,
248279
startts=startts, endts=endts)
249280
return list(self.iter(requests_params=requests_params, **params))
250281

251-
def create_writer(self, **kwargs):
282+
def create_writer(self, start=0, auth=None, size=1000, interval=15,
283+
qsize=None, content_encoding='identity',
284+
maxitemsize=1024 ** 2, callback=None):
285+
"""Create a new writer for a collection.
286+
287+
:return: a new writer object.
288+
:rtype: :class:`~scrapinghub.hubstorage.batchuploader._BatchWriter`
289+
"""
290+
# TODO describe allowable params
291+
kwargs = {}
292+
update_kwargs(start=start, auth=auth, size=size, interval=interval,
293+
qsize=qsize, content_encoding=content_encoding,
294+
maxitemsize=maxitemsize, callback=callback)
252295
return self._origin._collections.create_writer(
253296
self._origin.coltype, self._origin.colname, **kwargs)

scrapinghub/client/frontiers.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,11 @@ def newcount(self):
121121
return sum(self._origin.newcount.values())
122122

123123
def flush(self):
124+
"""Flush data in all frontiers writer threads."""
124125
self._origin.flush()
125126

126127
def close(self):
128+
"""Close frontier writer threads one-by-one."""
127129
self._origin.close()
128130

129131

scrapinghub/client/logs.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,22 +50,34 @@ class Logs(_ItemsResourceProxy, _DownloadableProxyMixin):
5050
}]
5151
"""
5252
def log(self, message, level=logging.INFO, ts=None, **other):
53+
"""Base method to write a log entry.
54+
55+
:param message: a string message.
56+
:param level: (optional) logging level, default to INFO.
57+
:param ts: (optional) unix timestamp in milliseconds.
58+
:param \*\*other: other optional kwargs.
59+
"""
5360
self._origin.log(message, level=level, ts=ts, **other)
5461

5562
def debug(self, message, **other):
63+
"""Log a message with DEBUG level."""
5664
self._origin.debug(message, **other)
5765

5866
def info(self, message, **other):
67+
"""Log a message with INFO level."""
5968
self._origin.info(message, **other)
6069

6170
def warn(self, message, **other):
71+
"""Log a message with WARN level."""
6272
self._origin.warn(message, **other)
6373
warning = warn
6474

6575
def error(self, message, **other):
76+
"""Log a message with ERROR level."""
6677
self._origin.error(message, **other)
6778

6879
def batch_write_start(self):
80+
"""Override to set a start parameter when commencing writing."""
6981
return self._origin.batch_write_start()
7082

7183
def _modify_iter_params(self, params):

scrapinghub/client/requests.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,16 @@ class Requests(_ItemsResourceProxy, _DownloadableProxyMixin):
4242
}]
4343
"""
4444
def add(self, url, status, method, rs, parent, duration, ts, fp=None):
45+
""" Add a new requests.
46+
47+
:param url: string url for the request.
48+
:param status: HTTP status of the request.
49+
:param method: stringified request method.
50+
:param rs: response body length.
51+
:param parent: parent request id or ``None``.
52+
:param duration: request duration in milliseconds.
53+
:param ts: unix timestamp in milliseconds.
54+
:param fp: (optional) string fingerprint for the request.
55+
"""
4556
return self._origin.add(
4657
url, status, method, rs, parent, duration, ts, fp=None)

0 commit comments

Comments
 (0)