Skip to content

Instantly share code, notes, and snippets.

@DJStompZone
Created December 15, 2023 04:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DJStompZone/a2b68bff7c4caaed76ac5bd62d37cc63 to your computer and use it in GitHub Desktop.
Save DJStompZone/a2b68bff7c4caaed76ac5bd62d37cc63 to your computer and use it in GitHub Desktop.
#!/bin/bash
PYTHON_PATH=$(which python3)
if [ -z "$PYTHON_PATH" ]; then
PYTHON_PATH=$(which python)
fi
if [ -z "$PYTHON_PATH" ]; then
echo "Python is not installed or not found in PATH."
exit 1
fi
"$PYTHON_PATH" pickrates.py "$@"
[
{
"rank": "#1",
"legend_name": "Conduit",
"win_rate": "67.8%",
"pick_rate": "18.3%",
"total_games": "137,542"
},
{
"rank": "#2",
"legend_name": "Horizon",
"win_rate": "63.3%",
"pick_rate": "15.4%",
"total_games": "116,336"
},
{
"rank": "#3",
"legend_name": "Revenant",
"win_rate": "70.1%",
"pick_rate": "15.3%",
"total_games": "115,270"
},
{
"rank": "#4",
"legend_name": "Pathfinder",
"win_rate": "70.1%",
"pick_rate": "11.7%",
"total_games": "88,076"
},
{
"rank": "#5",
"legend_name": "Bangalore",
"win_rate": "64.2%",
"pick_rate": "11.2%",
"total_games": "84,579"
},
{
"rank": "#6",
"legend_name": "Loba",
"win_rate": "82.2%",
"pick_rate": "7%",
"total_games": "52,712"
},
{
"rank": "#7",
"legend_name": "Bloodhound",
"win_rate": "62.9%",
"pick_rate": "3.5%",
"total_games": "26,326"
},
{
"rank": "#8",
"legend_name": "Lifeline",
"win_rate": "88.7%",
"pick_rate": "3.3%",
"total_games": "24,578"
},
{
"rank": "#9",
"legend_name": "Crypto",
"win_rate": "89.1%",
"pick_rate": "2.2%",
"total_games": "16,246"
},
{
"rank": "#10",
"legend_name": "Wraith",
"win_rate": "65.2%",
"pick_rate": "2%",
"total_games": "15,131"
},
{
"rank": "#11",
"legend_name": "Catalyst",
"win_rate": "64.6%",
"pick_rate": "2%",
"total_games": "14,791"
},
{
"rank": "#12",
"legend_name": "Valkyrie",
"win_rate": "85.4%",
"pick_rate": "1.2%",
"total_games": "9,103"
},
{
"rank": "#13",
"legend_name": "Octane",
"win_rate": "64.3%",
"pick_rate": "1.2%",
"total_games": "8,943"
},
{
"rank": "#14",
"legend_name": "Newcastle",
"win_rate": "69.9%",
"pick_rate": "0.9%",
"total_games": "6,910"
},
{
"rank": "#15",
"legend_name": "Mad Maggie",
"win_rate": "65.6%",
"pick_rate": "0.8%",
"total_games": "5,865"
},
{
"rank": "#16",
"legend_name": "Rampart",
"win_rate": "71%",
"pick_rate": "0.7%",
"total_games": "5,572"
},
{
"rank": "#17",
"legend_name": "Wattson",
"win_rate": "65.8%",
"pick_rate": "0.7%",
"total_games": "5,307"
},
{
"rank": "#18",
"legend_name": "Gibraltar",
"win_rate": "66.1%",
"pick_rate": "0.5%",
"total_games": "4,119"
},
{
"rank": "#19",
"legend_name": "Vantage",
"win_rate": "69.1%",
"pick_rate": "0.5%",
"total_games": "3,572"
},
{
"rank": "#20",
"legend_name": "Ash",
"win_rate": "74.1%",
"pick_rate": "0.5%",
"total_games": "3,547"
},
{
"rank": "#21",
"legend_name": "Fuse",
"win_rate": "64%",
"pick_rate": "0.4%",
"total_games": "2,927"
},
{
"rank": "#22",
"legend_name": "Caustic",
"win_rate": "69.2%",
"pick_rate": "0.3%",
"total_games": "2,193"
},
{
"rank": "#23",
"legend_name": "Mirage",
"win_rate": "68.4%",
"pick_rate": "0.3%",
"total_games": "1,947"
},
{
"rank": "#24",
"legend_name": "Ballistic",
"win_rate": "64.5%",
"pick_rate": "0.1%",
"total_games": "1,102"
},
{
"rank": "#25",
"legend_name": "Seer",
"win_rate": "66.7%",
"pick_rate": "0.1%",
"total_games": "696"
}
]
#!/usr/bin/env python3
import argparse
from bs4 import BeautifulSoup as BS
from httpx import get
from json import dumps
import os
def get_picks(as_dict=False):
[rank, legend, win_rate, pick_rate, total] = [(lambda url: [ea.strip() for ea in BS(get(url, timeout=None).content, features="html.parser").select("#br_winrate")[0].text.split('\n') if ea])("https://apexlegendsstatus.com/meta")[i+4::5] for i in range(5)]
_data = [{"rank": rank[i], "legend_name": legend[i], "win_rate": win_rate[i], "pick_rate": pick_rate[i], "total_games": total[i]} for i in range(len(rank))]
return _data if as_dict else dumps(_data, indent=4)
def save_json(picks, filename="pickrates", filepath=".", force=False):
file_path = os.path.join(filepath, f"{filename}.json")
if os.path.exists(file_path) and not force:
print(f"Warning: File '{file_path}' already exists. Use --force to overwrite.")
return
with open(file_path, "w") as fp:
fp.write(picks)
def main():
parser = argparse.ArgumentParser(description="Get and/or save Apex Legends pick rate statistics.")
parser.add_argument("--no-save", action="store_true", help="Do not save the output to a file.")
parser.add_argument("--save-dir", type=str, help="Directory to save the output file.", default=".")
parser.add_argument("--quiet", action="store_true", help="Do not print the output.")
parser.add_argument("--force", action="store_true", help="Overwrite the output file if it already exists.")
args = parser.parse_args()
picks = get_picks()
if not args.quiet:
print(picks)
if not args.no_save:
save_json(picks, filepath=args.save_dir, force=args.force)
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment