Skip to content

Commit 2ad3679

Browse files
committed
Additional helper classes for FrontierSlot
1 parent 23e6131 commit 2ad3679

File tree

1 file changed

+48
-11
lines changed

1 file changed

+48
-11
lines changed

scrapinghub/client.py

Lines changed: 48 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1179,28 +1179,23 @@ def __init__(self, client, frontier, slot):
11791179
self.key = slot
11801180
self._client = client
11811181
self._frontier = frontier
1182+
self.fingerprints = FrontierSlotFingerprints(self)
1183+
self.queue = FrontierSlotQueue(self)
1184+
# proxy iter & list methods to FrontierSlotQueue instance
1185+
self.iter = self.queue.iter
1186+
self.list = self.queue.list
11821187

11831188
def add(self, fps):
11841189
"""Add requests to slot."""
11851190
origin = self._frontier._frontiers._origin
11861191
return origin.add(self._frontier.key, self.key, fps)
11871192

1188-
def iter(self, **kwargs):
1189-
"""Iterate requests in slot."""
1190-
origin = self._frontier._frontiers._origin
1191-
path = (self._frontier.key, 's', self.key, 'q')
1192-
return origin.apiget(path, params=kwargs)
1193-
1194-
def list(self, **kwargs):
1195-
"""List requests in slot."""
1196-
return list(self.iter(**kwargs))
1197-
11981193
def delete(self, ids=None):
11991194
"""Delete slot or some specific requests."""
12001195
origin = self._frontier._frontiers._origin
12011196
if ids is None:
12021197
return origin.delete_slot(self._frontier.key, self.key)
1203-
return origin.delete(self._frontier.key, self.key, ids)
1198+
return self.queue.delete(ids)
12041199

12051200
def flush(self):
12061201
"""Flush data for the slot."""
@@ -1210,6 +1205,48 @@ def flush(self):
12101205
writer.flush()
12111206

12121207

1208+
class FrontierSlotFingerprints(object):
1209+
1210+
def __init__(self, slot):
1211+
self.key = slot.key
1212+
self._frontier = slot._frontier
1213+
self._slot = slot
1214+
1215+
def iter(self, **kwargs):
1216+
"""Iterate through fingerprints."""
1217+
origin = self._frontier._frontiers._origin
1218+
path = (self._frontier.key, 's', self.key, 'f')
1219+
for fp in origin.apiget(path, params=kwargs):
1220+
yield fp.get('fp')
1221+
1222+
def list(self, **kwargs):
1223+
"""List fingerprints in slot."""
1224+
return list(self.iter(**kwargs))
1225+
1226+
1227+
class FrontierSlotQueue(object):
1228+
1229+
def __init__(self, slot):
1230+
self.key = slot.key
1231+
self._frontier = slot._frontier
1232+
self._slot = slot
1233+
1234+
def iter(self, **kwargs):
1235+
"""Iterate through batches in queue."""
1236+
origin = self._frontier._frontiers._origin
1237+
path = (self._frontier.key, 's', self.key, 'q')
1238+
return origin.apiget(path, params=kwargs)
1239+
1240+
def list(self, **kwargs):
1241+
"""List request batches in slot."""
1242+
return list(self.iter(**kwargs))
1243+
1244+
def delete(self, ids):
1245+
"""Delete request batches from slot."""
1246+
origin = self._frontier._frontiers._origin
1247+
return origin.delete(self._frontier.key, self.key, ids)
1248+
1249+
12131250
class Collections(_Proxy):
12141251
"""Access to project collections.
12151252

0 commit comments

Comments
 (0)