Advertisement
Guest User

Untitled

a guest
Apr 9th, 2025
31
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.40 KB | None | 0 0
  1. import tkinter as tk
  2. import re
  3. import hashlib
  4. from itertools import count
  5.  
  6. from selenium import webdriver
  7. from selenium.webdriver.common.keys import Keys
  8. from selenium.webdriver.common.by import By
  9.  
  10. tournament = 'https://limitlesstcg.com/tournaments/481/decklists'
  11. lists = []
  12. limit = 5
  13.  
  14. driver = webdriver.Firefox()
  15. driver.get(tournament)
  16.  
  17. sr = tk.Tk()
  18.  
  19. assert "Decklists" in driver.title
  20.  
  21. toggles = driver.find_elements(By.CSS_SELECTOR, '.tournament-decklist .decklist-toggle')
  22. processed = 0
  23. for toggle in toggles:
  24.     if processed == limit:
  25.         break
  26.     toggle.click()
  27.     processed += 1
  28.  
  29. copyButtons = driver.find_elements(By.CSS_SELECTOR, ".decklist-extras .export")
  30. processed = 0
  31. for copyButton in copyButtons:
  32.     if processed == limit:
  33.         break
  34.  
  35.     copyButton.click()
  36.     lists.append(sr.clipboard_get())
  37.     processed += 1
  38.  
  39. driver.close()
  40. allPokemon = {}
  41. allTrainers = {}
  42.  
  43. reSectionHeader = re.compile(r'(?:Pokémon|Trainer|Energy): +\d+\n', re.IGNORECASE)
  44. rePokemon = re.compile(r'^(\d+)\s+(\D+?)\s+(\d+)$', re.MULTILINE)
  45. reTrainers = re.compile(r'^(\d+)\s+(\D+?)\s+(\d+)$', re.MULTILINE)
  46. for list in lists:
  47.     [pokemon, trainers, energy] = list.split("\n\n")
  48.  
  49.     pokemon = reSectionHeader.sub('', pokemon)
  50.     trainers = reSectionHeader.sub('', trainers)
  51.  
  52.     pokemon = rePokemon.findall(pokemon)
  53.     for p in pokemon:
  54.         pHash = hashlib.md5(p[1].encode())
  55.         # Add reference if card is new
  56.         if pHash not in allPokemon:
  57.             allPokemon[pHash] = {'name': p[1], 'count': int(p[0]), 'number': int(p[2])}
  58.  
  59.         # Maximize count
  60.         if int(p[0]) > allPokemon[pHash]['count']:
  61.             allPokemon[pHash]['count'] = int(p[0])
  62.         # Minimize rarity
  63.         if int(p[2]) < allPokemon[pHash]['number']:
  64.             allPokemon[pHash]['number'] = int(p[2])
  65.  
  66.     trainers = reTrainers.findall(trainers)
  67.     for t in trainers:
  68.         pHash = hashlib.md5(t[1].encode())
  69.         # Add reference if card is new
  70.         if pHash not in allTrainers:
  71.             allTrainers[pHash] = {'name': t[1], 'count': int(t[0]), 'number': int(t[2])}
  72.  
  73.         # Maximize count
  74.         if int(t[0]) > allTrainers[pHash]['count']:
  75.             allTrainers[pHash]['count'] = int(t[0])
  76.         # Minimize rarity
  77.         if int(t[2]) < allTrainers[pHash]['number']:
  78.             allTrainers[pHash]['number'] = int(t[2])
  79.  
  80. print(allPokemon)
  81. print(allTrainers)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement