Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python2
- import os
- import re
- import urllib
- # Aggiungi i codici che trovi in nell'indirizzo della pagina dell'oggetto
- # come elementi della variabile %codes
- # (es: http://www.amazon.it/Call-Duty-Modern-Warfare-3/dp/B005DEZRA6/
- # codice=B005DEZRA6)
- codes = [
- 'B0002UYA8Q', # Summit [Edizione: Germania]
- 'B000268AZE', # Reunion Cumbre [Edizione: Germania]
- 'B000BYAD20', # Complete Studio Recordings [Edizione: Francia]
- 'B00004TY56', # Bossa Antigua [Edizione: Francia]
- 'B0012BMMZC', # Getz Meets Mulligan In Hi-Fi [Edizione: Francia]
- 'B0000365G8', # Sweet & Lowdown [Colonna sonora]
- ]
- # Cambia il nome del file come preferisci, ora come ora salva sulla home un
- # file di "nome AmazonPriceHistory.log"
- logFilename = os.path.join(os.getenv('HOME'),'AmazonPriceHistory.log')
- if not os.path.exists(logFilename):
- with open(logFilename,'w') as fp: fp.write('')
- def Elaborate(code):
- p = re.compile(' *<.*(EUR )([^<]*)</b.*')
- d = re.compile(' *<[^>]*>([^<]*)<span.*>')
- address = 'http://www.amazon.it/gp/product/%s/' % ( code )
- content = urllib.urlopen(address)
- content = content.read().splitlines()
- for line in content:
- if line.count('EUR') and line.count('priceLarge'):
- largePrice = eval(p.match(line).group(2).replace(',','.'))
- if line.count("btAsinTitle"):
- itemName = d.match(line).group(1)
- with open(logFilename) as fp:
- fileCont = fp.read().splitlines()
- for idx in range(len(fileCont)):
- items = fileCont[idx].split('\t')
- if items[0] == itemName:
- items[1] += ',%s' % largePrice
- fileCont[idx] = '\t'.join(items)
- break
- if idx == len(fileCont)-1:
- fileCont.append('%s\t%s' % (itemName, largePrice))
- with open(logFilename, 'w') as fp:
- fp.write('\n'.join(fileCont)+'\n')
- print '%s done: %s > %.2f' % (code, itemName, largePrice)
- if __name__ == '__main__':
- for ind in codes:
- Elaborate(ind)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement