Skip to content

Instantly share code, notes, and snippets.

@Aikufurr
Last active August 8, 2022 15:38
Show Gist options
  • Save Aikufurr/ad4a828b59796ad78d7537369f793489 to your computer and use it in GitHub Desktop.
Save Aikufurr/ad4a828b59796ad78d7537369f793489 to your computer and use it in GitHub Desktop.
Hold a series of Pokémon TCG QR Cards in front of your webcam and it'll automatically redeem them for you, perfect for when you have a batch of cards to redeem.
### USAGE ###
# 0. Install the requirements: python -m pip install opencv-python pyperclip selenium
# 1. Fill out the credentials below
USERNAME = "USERNAME"
PASSWORD = "PASSWORD"
AUTO_REDEEM = True
# If Auto Redeem (True):
# 2. Run program
# 3. Hold the Online TCG Cards in front of the webcam, once the card has been registered it's code will be printed to the console
# 4. Once all cards have been accounted for, press "q"
# 5. Wait until the page loads and you have been logged in, it'll automatically log you in and redirect to the redeem page
# 6. If prompted, complete the Google reCAPTCHA, then press [enter] on the console to continue the program
# 7. Wait until all codes have been entered and redeemed
# 8. Done!
# If Manual Redeem (False):
# 2. Run program
# 3. Hold the Online TCG Cards in front of the webcam, once the card has been registered it's code will be printed to the console
# 4. Once all cards have been accounted for, press "q"
# 5. Go to the redeem page yourself, the first code will be in your clipboard
# 6. After entering the first code, press [enter] on the console and it'll then copy the next code to your clipboard
# 7. Repeat until all codes accounted for
# 8. Done!
### Code ###
from selenium.webdriver.common.by import By
from selenium import webdriver
from time import sleep
import pyperclip
import cv2
cap = cv2.VideoCapture(0)
# Initialize the cv2 QRCode detector
detector = cv2.QRCodeDetector()
# List for storing the codes
codes = []
while True:
# Read camera
_, img = cap.read()
# Detect and decode
data, bbox, _ = detector.detectAndDecode(img)
# Check if there is a QRCode in the image
if data:
# Check if the code is already in the list
if data not in codes:
codes.append(data)
print(data)
sleep(0.2)
# Show window
cv2.imshow("QRCODEscanner", img)
# Wait for 'q'
if cv2.waitKey(1) == ord("q"):
break
# Close window
cap.release()
cv2.destroyAllWindows()
# Manual Redeem
if not AUTO_REDEEM:
for code in codes:
# Copy code to clipboard
pyperclip.copy(code)
print(code, "copied to clipboard, press [enter] for next")
input()
print("Done!")
exit()
driver = webdriver.Chrome()
driver.get("https://sso.pokemon.com/sso/login?locale=en-gb&service=https://www.pokemon.com/uk/pokemon-trainer-club/caslogin") # Login Page
# Log user in to their account
driver.find_element(By.ID, "username").send_keys(USERNAME)
sleep(0.2)
driver.find_element(By.ID, "password").send_keys(PASSWORD)
sleep(0.2)
driver.find_element(By.ID, "btnLogin").click()
# Redirect to code redeem page
driver.get("https://www.pokemon.com/uk/pokemon-trainer-club/enter-codes")
sleep(2)
try:
# Remove cookie popup
driver.find_element(By.ID, "onetrust-reject-all-handler").click()
except:
pass
# If Google reCAPTCHA found, wait for user to complete it
if len(driver.find_elements(By.CLASS_NAME, "g-recaptcha")) > 0:
print("Please solve Google's reCAPTCHA then press [enter]")
input()
def redeem_codes():
print("Redeeming All...")
driver.find_element(By.ID, "redemption-check-all").click() # Find the checkbox for selecting all codes, click it
sleep(0.1)
redeem_btn = driver.find_element(By.ID, "redeem-code") # Find the redeem button
if "disabled" in redeem_btn.get_attribute("class"): # If the redeem button is not clickable (i.e. all codes are invalid)
driver.find_element(By.ID, "clear-table").click() # Click the clear table button
sleep(1)
while len(driver.find_elements(By.ID, "verify-code")) == 0: # Wait until the check code button is available again
sleep(1)
entered = 0 # Codes entered into table
for code in codes:
if entered == 10:
print("-- 10 Codes Entered -- ")
redeem_codes()
print("Trying code:", code)
code_box = driver.find_element(By.NAME, "redemption_code") # Find the box for entering the code
code_box.clear() # Clear it from any prev attempts
code_box.send_keys(code) # Enter the code
try:
driver.find_element(By.ID, "verify-code").click() # Click the button to verify the code
except:
sleep(2) # If the program failed the validation wait check, this except may fire, a 2s delay will solve it
driver.find_element(By.ID, "verify-code").click()
while len(driver.find_elements(By.CLASS_NAME, "code_overlay")) > 0: # While the code is being validated, sleep
sleep(0.5)
entered += 1
redeem_codes()
print("Done!")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment