Skip to content

Instantly share code, notes, and snippets.

@btel
Created June 19, 2015 16:32
Show Gist options
  • Save btel/9b3c40ac71af528174ee to your computer and use it in GitHub Desktop.
Save btel/9b3c40ac71af528174ee to your computer and use it in GitHub Desktop.
price tracker
import urllib
import urllib2
import string
import sys
from bs4 import BeautifulSoup
import sys
import argparse
import datetime
import re
parser = argparse.ArgumentParser(description='Process some integers.')
parser.add_argument('product', metavar='product', type=str, nargs=1,
help='URL of product')
parser.add_argument('target', metavar='target',type=float , nargs=1,
help='target price')
args = parser.parse_args()
product = args.product[0]
target = args.target[0]
csvfile = r'c:\users\owner\documents\python\amazon.csv'
user_agent = 'Mozilla/5.0 (Windows NT 6.1; rv:13.0) Gecko/20100101 Firefox/13.0'
headers = { 'User-Agent' : user_agent }
request=urllib2.Request(product,None ,headers)
response = urllib2.urlopen(request)
the_page = response.read()
soup= BeautifulSoup(the_page)
title = soup.find("span",{"id":"priceblock_ourprice"})
s = title.contents[0]
price = ''.join(s.split()[1:]).replace(',','.')
date = datetime.datetime.now().strftime('%d/%m/%y')
m = re.search('dp/([A-Z0-9]+)/', product)
asin = m.groups()[0]
with file('/home/bartosz/ownCloud/price_{}.csv'.format(asin), 'a') as fid:
fid.write(date + ';' + price + '\n')
@btel
Copy link
Author

btel commented Jun 19, 2015

crontab rule:

3 13 * * * python /home/bartosz/Downloads/amazon.py "http://www.amazon.fr/Seagate-Expansion-Desktop-Disque-externe/dp/B0084LZJ1M/" 100

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