Skip to content

Commit 63db1ed

Browse files
authored
Update network.py (#61)
1 parent 6673b5b commit 63db1ed

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

piazza_api/network.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from collections import namedtuple
2-
2+
import time
33
from .rpc import PiazzaRPC
44

55

@@ -82,7 +82,7 @@ def get_post(self, cid):
8282
"""
8383
return self._rpc.content_get(cid=cid)
8484

85-
def iter_all_posts(self, limit=None):
85+
def iter_all_posts(self, limit=None, sleep=0):
8686
"""Get all posts visible to the current user
8787
8888
This grabs you current feed and ids of all posts from it; each post
@@ -91,6 +91,8 @@ def iter_all_posts(self, limit=None):
9191
caution to the user when using this.
9292
9393
:type limit: int|None
94+
sleep:int -- If given, will allow to actually iterate through all of
95+
Piazza channel's posts without getting kicked or banned by Piazza.
9496
:param limit: If given, will limit the number of posts to fetch
9597
before the generator is exhausted and raises StopIteration.
9698
No special consideration is given to `0`; provide `None` to
@@ -102,6 +104,7 @@ def iter_all_posts(self, limit=None):
102104
feed = self.get_feed(limit=999999, offset=0)
103105
cids = [post['id'] for post in feed["feed"]]
104106
if limit is not None:
107+
time.sleep(sleep)
105108
cids = cids[:limit]
106109
for cid in cids:
107110
yield self.get_post(cid)

0 commit comments

Comments
 (0)