Created
December 10, 2024 22:46
-
-
Save muvaf/c5bbd59b92312e7e1ccc2184466579c1 to your computer and use it in GitHub Desktop.
Script to calculate how much of Homebrew users are on linux from live data
This file contains hidden or 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
import json | |
import requests | |
# Download JSON data from URL | |
url = "https://formulae.brew.sh/api/analytics/os-version/365d.json" | |
response = requests.get(url) | |
data = response.json() | |
# Helper function to convert count strings to integers | |
def parse_count(count_str): | |
return int(count_str.replace(",", "")) | |
# Initialize totals | |
macos_total = 0 | |
linux_total = 0 | |
# Process data | |
for item in data["items"]: | |
os_version = item["os_version"].lower() | |
count = parse_count(item["count"]) | |
if "macos" in os_version: | |
macos_total += count | |
else: | |
linux_total += count | |
# Calculate percentages | |
grand_total = macos_total + linux_total | |
macos_percentage = (macos_total / grand_total) * 100 | |
linux_percentage = (linux_total / grand_total) * 100 | |
# Output results | |
print(f"macOS: {macos_percentage:.2f}%") | |
print(f"Linux: {linux_percentage:.2f}%") | |
# As of December 11, 2024 | |
# macOS: 85.43% | |
# Linux: 14.57% |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment