Skip to content

Commit

Permalink
Reorganized stuff and added GIthubAPI thing
Browse files Browse the repository at this point in the history
  • Loading branch information
kings177 committed Nov 21, 2023
1 parent f994937 commit b104dc3
Show file tree
Hide file tree
Showing 19 changed files with 50 additions and 34 deletions.
1 change: 1 addition & 0 deletions .github/workflows/discordmessage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ jobs:

CI_LINK="<https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}>"

# secrets.DISCORD_WEBHOOK_URL="https://discord.com/api/webhooks/1138292630699118733/-9QfspX7aBxiVYRKgyf70eBNBpCG6EhLWNHnEmdFsUmkx24RgTj3i-TkfR4ttiocUomh"

if [ ! -z "$DISCORD_ID" ]; then
MESSAGE="The CI from <@$DISCORD_ID>'s commit has failed, please check: $CI_LINK"
Expand Down
49 changes: 49 additions & 0 deletions GithubAPI/fetch_top_repos.py
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.
34 changes: 0 additions & 34 deletions scripts/actions/cargo.yml

This file was deleted.

0 comments on commit b104dc3

Please sign in to comment.