Skip to content

Instantly share code, notes, and snippets.

@sonya75
Last active June 18, 2018 05:09
Show Gist options
  • Save sonya75/b6790bcf12ab0194623770289f1c5a3f to your computer and use it in GitHub Desktop.
Save sonya75/b6790bcf12ab0194623770289f1c5a3f to your computer and use it in GitHub Desktop.
Add address to a list of nike+ accounts
#Script to add address in a list of nike+ accounts
#Works for Nike US and Nike GB
#The account file should contain email:password in each line for each account
ACCOUNTFILENAME="nikeemails.txt"
COUNTRY="US"
FIRSTNAME="John"
LASTNAME="Doe"
ADDRESSLINE1="123 abcd street"
ADDRESSLINE2=""
CITY="New York"
PROVINCE="NY"
ZIPCODE="00000"
PHONE="0000000000"
#Don't change anything below this line
import requests
from threading import Thread
import Queue
import uuid
import re
APPVERSION="291"
EXPVERSION="253"
def getAppVersion():
global APPVERSION,EXPVERSION
sess=requests.session()
sess.headers.update({"User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.115 Safari/537.36"})
try:
d=sess.get("https://s3.nikecdn.com/unite/scripts/unite.min.js")
APPVERSION=re.search("\"app-version\"\]\|\|\"([0-9]*)\"",d.text).group(1)
EXPVERSION=re.search("\"experience-version\"\]\|\|\"([0-9]*)\"",d.text).group(1)
print "Successfully updated nike app version and experience version"
except:
print "Failed to update app version, using default ones"
APPVERSION="291"
EXPVERSION="253"
def addaddress(email,password):
sess=requests.session()
sess.headers.update({"User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.115 Safari/537.36"})
print "Logging in to {0}".format(email)
if COUNTRY=="US":
sess.cookies["CONSUMERCHOICE"]="us/en_us"
sess.cookies["NIKE_COMMERCE_COUNTRY"]="US"
sess.cookies["NIKE_COMMERCE_LANG_LOCALE"]="en_US"
sess.cookies["nike_locale"]="us/en_US"
e=sess.post("https://unite.nike.com/loginWithSetCookie?appVersion={0}&experienceVersion={1}&uxid=com.nike.commerce.snkrs.web&locale=en_US&backendEnvironment=identity&browser=Google%20Inc.&os=undefined&mobile=false&native=false".format(APPVERSION,EXPVERSION),json={"username":email,"password":password,"keepMeLoggedIn":True,"client_id":"PbCREuPr3iaFANEDjtiEzXooFl7mXGQ7","ux_id":"com.nike.commerce.snkrs.web","grant_type":"password"})
else:
sess.cookies["CONSUMERCHOICE"]="gb/en_gb"
sess.cookies["NIKE_COMMERCE_COUNTRY"]="GB"
sess.cookies["NIKE_COMMERCE_LANG_LOCALE"]="en_GB"
sess.cookies["nike_locale"]="gb/en_GB"
e=sess.post("https://unite.nike.com/loginWithSetCookie?appVersion={0}&experienceVersion={1}&uxid=com.nike.commerce.snkrs.web&locale=en_GB&backendEnvironment=identity&browser=Google%20Inc.&os=undefined&mobile=false&native=false".format(APPVERSION,EXPVERSION),json={"username":email,"password":password,"keepMeLoggedIn":True,"client_id":"PbCREuPr3iaFANEDjtiEzXooFl7mXGQ7","ux_id":"com.nike.commerce.snkrs.web","grant_type":"password"})
e.raise_for_status()
token=e.json()["access_token"]
e=sess.put("https://api.nike.com/user/commerce",json={"address":{"shipping":{"preferred":True,"type":"shipping","name":{"primary":{"given":FIRSTNAME,"family":LASTNAME}},"line1":ADDRESSLINE1,"line2":ADDRESSLINE2,"locality":CITY,"province":PROVINCE,"code":ZIPCODE,"country":COUNTRY,"phone":{"primary":PHONE},"label":"shipping_1","guid":str(uuid.uuid4())}}},headers={"Authorization":("Bearer "+token)})
try:
e.raise_for_status()
except Exception as ee:
print e.text
raise ee
getAppVersion()
alls=open(ACCOUNTFILENAME,'r').read().split('\n')
alls=[p.strip().split(":",1) for p in alls if p.strip()!=""]
alls1=Queue.Queue()
for p in alls:
alls1.put(p)
def f():
while True:
try:
emp=alls1.get_nowait()
except:
return
try:
addaddress(emp[0],emp[1])
print "Successfully added address for {0}".format(emp[0])
except Exception as e:
print e
print "Error adding address to {0}".format(emp[0])
for i in range(0,20):
Thread(target=f).start()
@privatekenny
Copy link

400 client error: bad requests for URL

@bwangDev
Copy link

Did you find out why you got 400?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment