Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .github/workflows/deploy-pages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Fetch github stats
run: python3 scripts/fetch-stats.py
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Build static API
run: |
Expand Down
4 changes: 4 additions & 0 deletions public_html/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ <h1 class="text-5xl font-bold text-[#c4b5fd] mb-4">RusherHack Addons</h1>
</div>
<div class="flex gap-4">
<select id="sortSelect" class="px-4 py-3 rounded-xl text-sm cursor-pointer min-w-[160px]">
<option value="stars">Most Stars</option>
<option value="downloads">Most Downloads</option>
<option value="newest">Newest First</option>
<option value="oldest">Oldest First</option>
<option value="az">Name A-Z</option>
Expand Down Expand Up @@ -96,6 +98,8 @@ <h1 class="text-5xl font-bold text-[#c4b5fd] mb-4">RusherHack Addons</h1>
})

filtered.sort((a, b) => {
if (sortBy === 'stars') return (b.stars || 0) - (a.stars || 0);
if (sortBy === 'downloads') return (b.downloads || 0) - (a.downloads || 0);
if (sortBy === 'az') return a.name.localeCompare(b.name)
if (sortBy === 'za') return b.name.localeCompare(a.name)

Expand Down
51 changes: 51 additions & 0 deletions scripts/fetch-stats.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import json
import os
import requests
import time

JSON_PATH = "generated/json/plugins-and-themes.json"
TOKEN = os.getenv("GITHUB_TOKEN")

def get_github_stats(repo):
headers = {"Authorization": f"token {TOKEN}"} if TOKEN else {}
stats = {"stars": 0, "downloads": 0}
try:
#Stars
req = requests.get(f"https://api.github.com/repos/{repo}", headers=headers, timeout=10)
if (req.status_code) == 200:#its so cool
stats["stars"] = req.json().get("stargazers_count", 0)

#Downloads
req = requests.get(f"https://api.github.com/repos/{repo}/releases", headers=headers, timeout=10)
if (req.status_code) == 200:
releases = req.json()
stats["downloads"] = sum(asset.get("download_count", 0) for release in releases for asset in release.get("assets", []))
except Exception as e:
print(f"Error fetching stats for {repo}: {e}")

return stats

def main():
if (not os.path.exists(JSON_PATH)):
print(f"JSON file not found at {JSON_PATH}")
return

with open(JSON_PATH, "r", encoding="utf-8") as f:
data = json.load(f)

print("Fetching GitHub stats...")
for category in ["plugins", "themes"]:
for item in data.get(category, []):
repo = item.get("repo", "")
if (repo and "/" in repo):
res = get_github_stats(repo)
item["stars"] = res["stars"]
item["downloads"] = res["downloads"]
time.sleep(0.05)#github delay

with open(JSON_PATH, "w", encoding="utf-8") as f:
json.dump(data, f, indent=4)
print("Stats updated successfully.")

if __name__ == "__main__":
main()
Loading