Skip to content

Commit 951fb44

Browse files
authored
Merge pull request #9 from zkoppert/rate-limit
Add rate limiting
2 parents 2a21ac4 + 1ab39b2 commit 951fb44

File tree

2 files changed

+17
-17
lines changed

2 files changed

+17
-17
lines changed

crawler.py

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
import github3
88
from dotenv import load_dotenv
9+
from ratelimiter import RateLimiter
910

1011
if __name__ == "__main__":
1112

@@ -18,27 +19,25 @@
1819

1920
# Get all repos from organization
2021
all_repos = gh.repositories()
21-
22+
rate_limiter = RateLimiter(max_calls=10, period=1)
2223
repo_list = []
2324
# Set the topic
2425
topic = os.getenv("TOPIC")
2526

26-
for repo in all_repos:
27-
if repo is not None:
28-
# Get the repo topics as type dict and print them nicely
29-
30-
# TODO: #6 handle rate limiting
31-
try:
32-
repo_topic = repo.topics()
33-
except Exception:
34-
print("skipping 404")
35-
else:
36-
if topic in repo_topic.names:
37-
# TODO: #7 For each resulting project add a key _InnerSourceMetadata
38-
print("{0}".format(repo))
39-
full_repository = repo.refresh()
40-
# Add stuff here about innersource.json data before appending to list
41-
repo_list.append(full_repository.as_dict())
27+
with rate_limiter:
28+
for repo in all_repos:
29+
if repo is not None:
30+
try:
31+
repo_topic = repo.topics()
32+
except Exception:
33+
print("skipping 404")
34+
else:
35+
if topic in repo_topic.names:
36+
print("{0}".format(repo))
37+
full_repository = repo.refresh()
38+
# TODO: #7 For each resulting project add a key _InnerSourceMetadata
39+
# Add stuff here about innersource.json data before appending to list
40+
repo_list.append(full_repository.as_dict())
4241

4342
# Write each repository to a repos.json file
4443
with open("repos.json", "w") as f:

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
python-dotenv==0.15.0
2+
ratelimiter==1.2.0.post0

0 commit comments

Comments
 (0)