Skip to content

Instantly share code, notes, and snippets.

@danielatdattrixdotcom danielatdattrixdotcom/j4u.py Secret

Last active Oct 29, 2019
Embed
What would you like to do?
J4U
import requests
import time
import datetime
import json
def add_all(username, password):
# STORE ID REQUIRED. Just use dev tools in browser to find it.
STORE_ID = 0000
START_PAGE = u'https://auth.safeway.com/opensso/UI/Login?&goto=http%3A%2F%2Fwww.safeway.com%2FIFL%2FGrocery%2FHome'
LOGIN = u'https://auth.safeway.com/opensso/UI/Login'
CLIP = u'https://nimbus.safeway.com/Clipping1/services/clip/items?storeId=%s' % STORE_ID
#Fire up session
AGENT = u'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36'
s = requests.session()
s.headers.update({'User-Agent': AGENT})
#Pretend we're real and go to the login page
s.get(START_PAGE)
login = {
'goto':'',
'SunQueryParamsString':'',
'encoded':'true',
'arg':'newsession',
'IDToken1': username,
'fakePassword':'8-12 characters',
'IDToken2': password,
}
#Login
s.post(LOGIN, data=login)
referers = {'YCS': 'http://www.safeway.com/ShopStores/Justforu-YourClubSpecials.page',
'CD': 'http://www.safeway.com/ShopStores/Justforu-Coupons.page',
'CC': 'http://www.safeway.com/ShopStores/Justforu-Coupons.page', }
def headers(feed):
return {'Content-type': 'application/json',
'X-SWY_VERSION': '1.0',
'X-SWY_BANNER': 'safeway',
'X-SWY_API_KEY': 'emjou',
'X-SWY_ISREMEMBERED': 'false',
'Origin': 'http://www.safeway.com',
'X-Requested-With': 'XMLHttpRequest',
'DNT': '1',
'Referer': referers[feed],
'User-Agent': AGENT,
'X-swyConsumerDirectoryPro': s.cookies['swyConsumerDirectoryPro'],
'X-swyConsumerlbcookie': s.cookies['swyConsumerlbcookie'],
}
#Process feeds
for FEED, code in [(u'https://nimbus.safeway.com/J4UProgram1/services/program/%s/offer/allocations' % (pgm), pgm) for pgm in ['YCS', 'CD', 'CC']]:
get_params = {'_dc': int(time.mktime(datetime.datetime.now().timetuple()))*100, 'hierarchies': 'y', 'storeId': STORE_ID, 'topAllocations': 'y'}
s.options(FEED, params=get_params)
feed = s.get(FEED, params=get_params, headers=headers(code))
response = json.loads(feed.text)
for o in response['offers']:
if o['clipStatus'] not in ['C', 'S']:
clips = [{'clipType': 'C', 'itemId':o['offerId'], 'itemType':o['offerPgm'], }, {'clipType': 'L', 'itemId':o['offerId'], 'itemType':o['offerPgm'],} ]
s.options(CLIP)
clip = s.post(CLIP, data=json.dumps({'items': clips}), headers=headers(code))
if clip.status_code != 200:
print 'Error Clipping %s (Code %s) [%s]' % (o['offerId'], clip.status_code, clip.text)
return True
#add_all('username_email', 'password')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.