-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reorganized stuff and added GIthubAPI thing
- Loading branch information
Showing
19 changed files
with
50 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import requests | ||
import time | ||
import json | ||
|
||
def fetch_repos(language, api_token, max_repos=1000): | ||
"""Fetch top repos for a given language from the GitHub API.""" | ||
repos = [] | ||
page = 1 | ||
headers = {'Authorization': f'token {api_token}'} | ||
|
||
while len(repos) < max_repos: | ||
url = f'https://api.github.com/search/repositories?q=language:{language}&sort=stars&order=desc&page={page}&per_page=100' | ||
response = requests.get(url, headers=headers) | ||
|
||
if response.status_code != 200: | ||
print(f"Failed to fetch page {page} of repos for {language} with status code {response.status_code}") | ||
break | ||
|
||
data = response.json()['items'] | ||
repos.extend(data) | ||
|
||
if len(data) < 100: | ||
break | ||
|
||
page += 1 | ||
time.sleep(0.5) # So we don't get rate limited | ||
|
||
if len(repos) >= max_repos: | ||
print(f"Fetched {len(repos)} repos for {language}") | ||
repos = repos[:max_repos] | ||
|
||
return repos | ||
|
||
def save_repos_to_file(repos, language): | ||
"""Save the repos to a file.""" | ||
with open(f'{language}_repos.json', 'w') as file: | ||
json.dump(repos, file, indent=4) | ||
|
||
api_token= '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' | ||
languages = ['Python', 'Rust', 'C', 'JavaScript'] | ||
|
||
for language in languages: | ||
print(f"Fetching top repos for {language}") | ||
top_repos = fetch_repos(language, api_token) | ||
print(f"Fetched {len(top_repos)} repos for {language}") | ||
|
||
print(f"Saving repos to file for {language}") | ||
save_repos_to_file(top_repos, language) | ||
|
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file was deleted.
Oops, something went wrong.