Skip to content

Instantly share code, notes, and snippets.

@spookyahell
Last active December 25, 2018 10:09
Show Gist options
  • Select an option

  • Save spookyahell/94ed53a6cadb10cb9e347557449ef246 to your computer and use it in GitHub Desktop.

Select an option

Save spookyahell/94ed53a6cadb10cb9e347557449ef246 to your computer and use it in GitHub Desktop.
python iTunes tool (batch claim) | Use at own risk | Modify the sections that obviously require editing
import requests
import configparser
s = requests.session()
from sys import exit
import argparse
parser = argparse.ArgumentParser(prog='piTunes',formatter_class=argparse.RawTextHelpFormatter, description='This python script is the work of @spookyahell.\n'+
'Unlawful distribution or even usage is strictly prohibited.\nPremission is required.\n'+
'DISCLAIMER: We are not responsible for any damage caused by this script.\n'+
'Keep all pets away and don\'t let them near you while you\'re working with this script.\n'+
'You have been warned! Nothing is impossible when Donald Trump is president.\n(Well besides a reasonable president of course and a reasonable government and etc. etc.))')
parser.add_argument('claimcodes',
help='codes to claim on iTunes', metavar='CLAIMCODE', nargs='+')
args = parser.parse_args()
head_parse = configparser.ConfigParser(interpolation = None)
head_parse.optionxform=str
head_parse.read('iTunes.ini')
headers = dict(head_parse['headers'])
headers['Content-Type'] = 'application/x-apple-plist'
for claimcode in args.claimcodes:
data_string = DATA_STRING_FROM_FIDDLER (modified to accept claimcode)
#~ print(data_string)
r = requests.post('https://p44-buy.itunes.apple.com/WebObjects/MZFinance.woa/wa/redeemCodeSrv', headers = headers, data = data_string.encode('utf-8'))
if r.ok:
o = r.json()
if 'userPresentableErrorMessage' in o:
print(o['userPresentableErrorMessage'])
exit(1)
else:
totalCredit = o['totalCredit']
redeemedCredit = o['redeemedCredit']
print('Congratulations on redeeming', redeemedCredit['money'], 'leading you to a new total of', totalCredit['totalCredit'])
else:
print(r.status_code, r.reason)
print(r.headers)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment