Jake.codes

Redemption, for Redeeming Promo Codes

Sunday, December 22, 2013

import re
import urllib

def redeemCode(query):
    websites = [
        ('comix','https://www.comixology.com/my-account/egift-cards?code='),
        ('comixology','https://www.comixology.com/my-account/egift-cards?code='),
        ('itunes','https://buy.itunes.apple.com/WebObjects/MZFinance.woa/wa/redeemLandingPage?code='),
        ('mac','macappstores://buy.itunes.apple.com/WebObjects/MZFinance.woa/wa/redeemLandingPage?code='),
        ('amazon','https://www.amazon.com/gp/css/gc/payment/view-gc-balance?code='),
        ('audible','http://www.audible.com/mt/giftmembership?emailClaimCode='),
        ('xbox','https://account.xbox.com/en-US/PaymentAndBilling/RedeemCode?doRedeem=1&token='),
        # Steam Wallet only, unfortunately
        ('steam','https://store.steampowered.com/account/redeemwalletcode/?code='),
        # Sony has a bad system
        ('ps','https://account.sonyentertainmentnetwork.com/liquid/cam/account/giftcard/redeem-gift-card-flow.action'),
        
        # Wishlist:
        # ('marvel','https://marvel.com/redeem/'),
    ]

    for name, url in websites:
        website = '%s ' % name
        
        if not query.lower().startswith(website):
            continue
            
        # For Sony must be difficult
        if (name is "ps") or (name is "psn") or (name is "playstation"):
            sections = re.findall("\d{4}",query[len(website):])
            if len(sections) is 3:
                query = "?voucherCode1=" + sections[0] + "&voucherCode2=" + sections[1] + "&voucherCode3=" + sections[2]
                return url + query
            break
            
        return url + query[len(website):]
        break

print redeemCode("iTunes WKHUEA1P15GWM9D")