Created
June 19, 2015 16:32
-
-
Save btel/9b3c40ac71af528174ee to your computer and use it in GitHub Desktop.
price tracker
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
crontab rule: