noidea
2010-11-25 16:43:32
*Linux only*
Requires espeak installed.
This will monitor the items on newegg you put in the array and check every X seconds.
forgot to update :S
Thats an example. time_between is the amount in seconds to wait before checking the webpage again.
It logs the price changed in newegg.txt (which it will create).
It will espeak when the prices change or it cannot detect a price. All the pages I've tried so far have worked, but I ran into an issue earlier with one and fixed it.
Tell me if you find one that doesnt work.
Update: Fixed url exceptions, threading, etc.
yet to add: getting the items name. Should be piss easy.
Requires espeak installed.
This will monitor the items on newegg you put in the array and check every X seconds.
forgot to update :S
# To change this template, choose Tools | Templates
# and open the template in the editor.
__author__="lucas"
__date__ ="$Nov 24, 2010 11:52:39 PM$"
import os
import urllib2
import threading
import time
import math
class NeweggCheck(threading.Thread):
def __init__(self, url, timecheck=30):
threading.Thread.__init__(self)
self.url, self.timecheck = url, timecheck
self.exit = False
def stop(self):
self.exit = True
def run(self):
print 'thread started', self.url
price = 0
while self.exit == False:
try:
request = urllib2.build_opener()
request.addheaders = [('User-agent', 'Mozilla/5.0')]
line = request.open(self.url).read()
except IOError, e:
print 'There was an exception'
print e
continue
line_catch = 'Biz.Product.DetailPage.switchCrossSellItem(this,\''
# check for the price
if line.find(line_catch, 0, len(line)-1) != -1: # Searches for the phrase from within the line
line_catch_posA = line.find(line_catch)+len(line_catch)+1
# Gets the price of the item from the line
price_string = line[line_catch_posA:line[line.find(line_catch)+len(line_catch)+1:len(line)-1].find('\',\'')+ line_catch_posA]
price_float = float(price_string)
print '$' + price_string, self.url
if price != price_float:
os.popen("espeak --stdout 'the. prices. have. updated. . . It. is. now."+price_string+"' | aplay")
# os.popen("espeak 'the. prices. have. updated. . . It. is. now. "+ price_string+"'")
print 'Price of', self.url, 'has changed'
price = price_float
with open('newegg.txt', 'a') as f:
f.write(price_string+' '+self.url+'\n')
else:
print 'POSSIBLE PRICE CHANGE, CANNOT FIND PRICE', self.url
os.popen("espeak --stdout 'possible price. change' | aplay") #("espeak 'possible price. change'")
wait = self.timecheck if self.timecheck < 1 else 0.5
for t in range(int(math.ceil(self.timecheck))*2):
time.sleep(wait)
if self.exit: break
if __name__ == "__main__":
urls = ['http://www.newegg.com/Product/Product.aspx?Item=N82E16856119018', #case, mobo, psu
'http://www.newegg.com/Product/Product.aspx?Item=N82E16814121397', #gpu
'http://www.newegg.com/Product/Product.aspx?Item=20-144-259', #ram
'http://www.newegg.com/Product/Product.aspx?Item=N82E16820148235', #ram
'http://www.newegg.com/Product/Product.aspx?Item=N82E16819116264', #cpu
'http://www.newegg.com/Product/Product.aspx?Item=N82E16827136181'] #bluraty burner
time_between = 30 # amount in seconds to wait before checking the site again.
thread_list = []
for url in urls:
thread_list.append(NeweggCheck(url, timecheck=time_between))
thread_list[len(thread_list)-1].start()
try:
while True:
time.sleep(0.5)
except KeyboardInterrupt:
print 'Interrupt called'
for single_thread in thread_list:
single_thread.stop()Thats an example. time_between is the amount in seconds to wait before checking the webpage again.
It logs the price changed in newegg.txt (which it will create).
It will espeak when the prices change or it cannot detect a price. All the pages I've tried so far have worked, but I ran into an issue earlier with one and fixed it.
Tell me if you find one that doesnt work.
Update: Fixed url exceptions, threading, etc.
yet to add: getting the items name. Should be piss easy.