-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsearch-github-repos.py
More file actions
59 lines (42 loc) · 1.32 KB
/
search-github-repos.py
File metadata and controls
59 lines (42 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import os
import requests
from dotenv import load_dotenv
load_dotenv()
GITHUB_TOKEN = os.getenv("GITHUB_TOKEN")
if not GITHUB_TOKEN:
raise RuntimeError("GITHUB_TOKEN is not set in the .env file.")
QUERY = "language:lua micro"
PER_PAGE = 100
MAX_PAGES = 10
def search_github_repositories(query, token, max_pages=10, per_page=100):
url = "https://api.github.com/search/repositories"
headers = {
"Authorization": f"token {token}",
"Accept": "application/vnd.github+json",
"User-Agent": "python-script",
}
all_items = []
for page in range(1, max_pages + 1):
params = {
"q": query,
"per_page": per_page,
"page": page,
}
response = requests.get(url, headers=headers, params=params)
if response.status_code != 200:
print(f"Error: {response.status_code} {response.text}")
break
data = response.json()
items = data.get("items", [])
if not items:
break
all_items.extend(items)
if len(all_items) >= data.get("total_count", 0):
break
return all_items
def main():
repos = search_github_repositories(QUERY, GITHUB_TOKEN, MAX_PAGES, PER_PAGE)
for repo in repos:
print(repo["html_url"])
if __name__ == "__main__":
main()