Skip to content

Commit

Permalink
Merge pull request #11 from Correia-jpv/dev
Browse files Browse the repository at this point in the history
  • Loading branch information
Correia-jpv authored Sep 10, 2022
2 parents fd327b8 + d077894 commit 4a77099
Showing 1 changed file with 7 additions and 16 deletions.
23 changes: 7 additions & 16 deletions GithubAPIBot.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,23 +172,9 @@ def getUsers(self, url="", maxAction=None, following=False):
except requests.exceptions.RequestException as e:
raise SystemExit(e)

if 'Link' not in res.headers:
return []

# Get pages of users
pagesURLs = requests.utils.parse_header_links(res.headers["Link"])
lastPageURL = pagesURLs[1]["url"]
lastPage = parse_qs(urlparse(lastPageURL).query)["page"][0]

# Get usernames from each page
pages = tqdm(
range(int(lastPage), 0, -1),
dynamic_ncols=True,
smoothing=True,
bar_format="[PROGRESS] {l_bar}{bar}|",
leave=False,
)
for page in pages:
page = 1
while True:
try:
res = self.session.get(url + "?page=" + str(page)).json()
except requests.exceptions.RequestException as e:
Expand All @@ -214,6 +200,11 @@ def getUsers(self, url="", maxAction=None, following=False):
if len(users) >= int(maxAction):
break

if res == []:
break
else:
page += 1

return users

def getFollowers(self, username=None, following=None):
Expand Down

0 comments on commit 4a77099

Please sign in to comment.