Skip to content

Instantly share code, notes, and snippets.

@kwgotrik
Created January 12, 2014 22:11
Show Gist options
  • Save kwgotrik/8391334 to your computer and use it in GitHub Desktop.
Save kwgotrik/8391334 to your computer and use it in GitHub Desktop.
# Scraping the Safeway Ice Cream deals for store 676, adjust with storefinder for yours
# Notification via Pushover, can run with a cron job on server
# url: 'http://m.safeway.com/WeeklySpecials/Index?filterType=ByCategory&selectedCategory=none&storeId=676'
# use this to find the other categories
# thanks ccc for the input!
import bs4, requests, console
console.clear()
def writePushNotification(message):
pushover_url = 'https://api.pushover.net/1/messages.json'
payload = { 'token' : 'your_token',
'user' : 'your_userID',
'message' : message }
return requests.post(pushover_url, data=payload).text
items_url = 'http://m.safeway.com/WeeklySpecials/GetCategoryItems'
payload = {'storeID' : '676', 'filter' : 'ByCategory', 'categoryName' : 'Frozen Foods'}
items = requests.post(items_url, data=payload)
soup = bs4.BeautifulSoup(items.text)
products = soup.findAll('div', {'class' : 'one-item-div'})
pushme =[]
for product in products:
title = product.find('h3', {'class' : 'sw-heading'}).text
price = product.find('div', {'class' : 'red bold'}).text.strip()
if 'Ice Cream' in title:
string = title.replace('Ice Cream', '- ') + price
if not string in pushme:
pushme.append(string)
if pushme:
s = '\n'.join(pushme)
print(s)
# writePushNotification(s)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment