Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import tkinter as tk
- import re
- import hashlib
- from itertools import count
- from selenium import webdriver
- from selenium.webdriver.common.keys import Keys
- from selenium.webdriver.common.by import By
- tournament = 'https://limitlesstcg.com/tournaments/481/decklists'
- lists = []
- limit = 5
- driver = webdriver.Firefox()
- driver.get(tournament)
- sr = tk.Tk()
- assert "Decklists" in driver.title
- toggles = driver.find_elements(By.CSS_SELECTOR, '.tournament-decklist .decklist-toggle')
- processed = 0
- for toggle in toggles:
- if processed == limit:
- break
- toggle.click()
- processed += 1
- copyButtons = driver.find_elements(By.CSS_SELECTOR, ".decklist-extras .export")
- processed = 0
- for copyButton in copyButtons:
- if processed == limit:
- break
- copyButton.click()
- lists.append(sr.clipboard_get())
- processed += 1
- driver.close()
- allPokemon = {}
- allTrainers = {}
- reSectionHeader = re.compile(r'(?:Pokémon|Trainer|Energy): +\d+\n', re.IGNORECASE)
- rePokemon = re.compile(r'^(\d+)\s+(\D+?)\s+(\d+)$', re.MULTILINE)
- reTrainers = re.compile(r'^(\d+)\s+(\D+?)\s+(\d+)$', re.MULTILINE)
- for list in lists:
- [pokemon, trainers, energy] = list.split("\n\n")
- pokemon = reSectionHeader.sub('', pokemon)
- trainers = reSectionHeader.sub('', trainers)
- pokemon = rePokemon.findall(pokemon)
- for p in pokemon:
- pHash = hashlib.md5(p[1].encode())
- # Add reference if card is new
- if pHash not in allPokemon:
- allPokemon[pHash] = {'name': p[1], 'count': int(p[0]), 'number': int(p[2])}
- # Maximize count
- if int(p[0]) > allPokemon[pHash]['count']:
- allPokemon[pHash]['count'] = int(p[0])
- # Minimize rarity
- if int(p[2]) < allPokemon[pHash]['number']:
- allPokemon[pHash]['number'] = int(p[2])
- trainers = reTrainers.findall(trainers)
- for t in trainers:
- pHash = hashlib.md5(t[1].encode())
- # Add reference if card is new
- if pHash not in allTrainers:
- allTrainers[pHash] = {'name': t[1], 'count': int(t[0]), 'number': int(t[2])}
- # Maximize count
- if int(t[0]) > allTrainers[pHash]['count']:
- allTrainers[pHash]['count'] = int(t[0])
- # Minimize rarity
- if int(t[2]) < allTrainers[pHash]['number']:
- allTrainers[pHash]['number'] = int(t[2])
- print(allPokemon)
- print(allTrainers)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement