10000 🐛 Bugfix · Correia-jpv/github-follow-bot@d077894 · GitHub
[go: up one dir, main page]

Skip to content

Commit d077894

Browse files
committed
🐛 Bugfix
- Update retrieving GitHub users paging algorithm ( fix #3 )
1 parent fd327b8 commit d077894

File tree

1 file changed

+7
-16
lines changed

1 file changed

+7
-16
lines changed

GithubAPIBot.py

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -172,23 +172,9 @@ def getUsers(self, url="", maxAction=None, following=False):
1721 10708 72
except requests.exceptions.RequestException as e:
173173
raise SystemExit(e)
174174

175-
if 'Link' not in res.headers:
176-
return []
177-
178-
# Get pages of users
179-
pagesURLs = requests.utils.parse_header_links(res.headers["Link"])
180-
lastPageURL = pagesURLs[1]["url"]
181-
lastPage = parse_qs(urlparse(lastPageURL).query)["page"][0]
182-
183175
# Get usernames from each page
184-
pages = tqdm(
185-
range(int(lastPage), 0, -1),
186-
dynamic_ncols=True,
187-
smoothing=True,
188-
bar_format="[PROGRESS] {l_bar}{bar}|",
189-
leave=False,
190-
)
191-
for page in pages:
176+
page = 1
177+
while True:
192178
try:
193179
res = self.session.get(url + "?page=" + str(page)).json()
194180
except requests.exceptions.RequestException as e:
@@ -214,6 +200,11 @@ def getUsers(self, url="", maxAction=None, following=False):
214200
if len(users) >= int(maxAction):
215201
break
216202

203+
if res == []:
204+
break
205+
else:
206+
page += 1
207+
217208
return users
218209

219210
def getFollowers(self, username=None, following=None):

0 commit comments

Comments
 (0)
0