Skip to content

Commit e6b03b8

Browse files
authored
Update network.py (#62)
* Update network.py I put the time.sleep in the wrong place. * Update network.py
1 parent 63db1ed commit e6b03b8

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

piazza_api/network.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,8 @@ def iter_all_posts(self, limit=None, sleep=0):
9393
:type limit: int|None
9494
sleep:int -- If given, will allow to actually iterate through all of
9595
Piazza channel's posts without getting kicked or banned by Piazza.
96+
Around 1 second works in practice if you're iterating through
97+
a lot of posts.
9698
:param limit: If given, will limit the number of posts to fetch
9799
before the generator is exhausted and raises StopIteration.
98100
No special consideration is given to `0`; provide `None` to
@@ -104,9 +106,9 @@ def iter_all_posts(self, limit=None, sleep=0):
104106
feed = self.get_feed(limit=999999, offset=0)
105107
cids = [post['id'] for post in feed["feed"]]
106108
if limit is not None:
107-
time.sleep(sleep)
108109
cids = cids[:limit]
109110
for cid in cids:
111+
time.sleep(sleep)
110112
yield self.get_post(cid)
111113

112114
def create_post(self, post_type, post_folders, post_subject, post_content, is_announcement=0, bypass_email=0, anonymous=False):

0 commit comments

Comments
 (0)