Created
December 25, 2021 22:07
-
-
Save user-grinch/02befd4c5360d2f38a616c83c5b58434 to your computer and use it in GitHub Desktop.
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
""" | |
OP.GG Scrapper v1.0 | |
Author: Grinch_ | |
Last Update: 25-12-2021 | |
TODO: | |
- Make the scrapper less prone to op.gg update breakages | |
- Add support for multiple runesets | |
- Add support for multiple runesets | |
""" | |
from bs4 import BeautifulSoup | |
import urllib.request | |
from bs4.element import ResultSet | |
import enum | |
""" | |
League of Legends constants | |
Ruenes & fragments | |
""" | |
class Runes(enum.Enum): | |
# Precision tree | |
PRECISION = 0 | |
PRESS_THE_ATTACK = 1 | |
LETHAL_TEMPO = 2 | |
FLEET_FOOTWORK = 3 | |
CONQUEROR = 4 | |
OVERHEAL = 5 | |
TRUIMPH = 6 | |
PRESENCE_OF_MIND = 7 | |
LEGEND_ALACRITY = 8 | |
LEGEND_BLOODLINE = 9 | |
COUP_DE_GRACE = 10 | |
CUT_DOWN = 11 | |
LAST_STAND = 12 | |
# Domination tree | |
DOMINATION = 13 | |
ELECTROCUTE = 14 | |
PREDATOR = 15 | |
DARK_HARVEST = 16 | |
HAIL_OF_BLADES = 17 | |
CHEAP_SHOT = 18 | |
TASTE_OF_BLOOD = 19 | |
SUDDEN_IMPACT = 20 | |
ZOMBIE_WARD = 21 | |
GHOST_PORO = 22 | |
EYEBALL_COLLECTION = 23 | |
RAVENOUS_HUNTER = 24 | |
INGENIOUS_HUNTER = 25 | |
RELENTLESS_HUNTER = 26 | |
ULTIMATE_HUNTER = 27 | |
# Sorcery tree | |
SORCERY = 28 | |
SUMMON_AERY = 29 | |
ARCANE_COMET = 30 | |
PHASE_RUSH = 31 | |
NULLIFYING_ORB = 32 | |
MANAFLOW_BAND = 33 | |
NIMBUS_CLOAK = 34 | |
TRANSCENDENCE = 35 | |
CELERITY = 36 | |
ABSOLUTE_FOCUS = 37 | |
SCORCH = 38 | |
WATERWALKING = 39 | |
GATHERING_STORM = 40 | |
# Resolve tree | |
RESOLVE = 41 | |
GRASP_OF_THE_UNDYING = 42 | |
AFTERSHOCK = 43 | |
GUARDIAN = 44 | |
DEMOLISH = 45 | |
FONT_OF_LIFE = 46 | |
SHIELD_BASH = 47 | |
CONDITIONING = 48 | |
SECOND_WIND = 49 | |
BONE_PLATING = 50 | |
OVERGROWTH = 51 | |
REVITALIZE = 52 | |
UNFLINCHING = 53 | |
# Inspiration tree | |
INSPIRATION = 54 | |
GLACIAL_AUGMENT = 55 | |
UNSEALED_SPELLBOOK = 56 | |
FIRST_STRIKE = 57 | |
HEXTECH_FLASHTRAPTION = 58 | |
MAGICAL_FOOTWEAR = 59 | |
PERFECT_TIMING = 60 | |
FUTURES_MARKET = 61 | |
MINION_DEMATERIALIZER = 62 | |
BISCUIT_DELIVERY = 63 | |
COSMIC_INSIGHT = 64 | |
APPROACH_VELOCITY = 65 | |
TIME_WARP_TONIC = 66 | |
class Fragments(enum.Enum): | |
ADAPTIVE_FORCE = 67 | |
ATTACK_SPEED = 68 | |
ABILITY_HASTE = 69 | |
ARMOR = 70 | |
MAGIC_RESIST = 71 | |
DEFENCE = 72 | |
UNKNOWN = 73 | |
class OP_GG_Scrapper: | |
__url: str = "" | |
__content: str = "" | |
__soup: BeautifulSoup = None | |
def __init__(self, champion_name: str) -> None: | |
""" | |
Parses the OP.GG website for the recent runes with higest winrates for the champion | |
@params: | |
champion_name: The name of the champion | |
""" | |
self.__url = "https://na.op.gg/champion/" + champion_name.lower() + "/" | |
self.__content = urllib.request.urlopen(self.__url).read() | |
self.__soup = BeautifulSoup(self.__content, 'lxml') | |
def getRuneData(self) -> 'list[str]': | |
""" | |
Returns a list of names of all available runes for the champion | |
""" | |
rtn_list: list[str] = [] | |
perk_wrap: ResultSet = self.__soup.find('div', class_='perk-page-wrap') | |
for rune_data in perk_wrap.find_all('div', class_='perk-page__item--active'): | |
rtn_list.append(rune_data.find('img')['alt']) | |
return rtn_list | |
def getFragmentData(self) -> 'list[Fragments]': | |
""" | |
Returns a list of names of all available fragments for the champion | |
""" | |
rtn_list: list[Fragments] = [] | |
frag_detail: ResultSet = self.__soup.find( | |
'div', class_='fragment__detail') | |
row: int = 1 | |
for frag_row in frag_detail.find_all('div', class_='fragment__row'): | |
col: int = 1 | |
for frags in frag_row.find_all('div', class_='fragment'): | |
class_str: str = frags.find('img')['class'][0] | |
if (class_str.find("active")): | |
col = col + 1 | |
continue | |
# Go through each row and column and find the fragments | |
if (row == 1): | |
if (col == 1): | |
rtn_list.append(Fragments.ADAPTIVE_FORCE) | |
elif (col == 2): | |
rtn_list.append(Fragments.ATTACK_SPEED) | |
else: | |
rtn_list.append(Fragments.ABILITY_HASTE) | |
elif (row == 2): | |
if (col == 1): | |
rtn_list.append(Fragments.ADAPTIVE_FORCE) | |
elif (col == 2): | |
rtn_list.append(Fragments.ARMOR) | |
else: | |
rtn_list.append(Fragments.MAGIC_RESIST) | |
else: | |
if (col == 1): | |
rtn_list.append(Fragments.DEFENCE) | |
elif (col == 2): | |
rtn_list.append(Fragments.ARMOR) | |
else: | |
rtn_list.append(Fragments.MAGIC_RESIST) | |
col = col + 1 | |
row = row + 1 | |
return rtn_list |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment