#!/usr/bin/python
import sys, urllib, re
class BaseSpecial:
def getSpecial(self):
childMustImplement()
class BuyDotComPriceMistake (BaseSpecial):
def __init__(self):
self.url = "http://www.us.buy.com/default.asp"
def getSpecial(self):
fp = urllib.urlopen(self.url)
line = ""
while 1:
chunk = fp.readline()
if not chunk: break
m = re.search("mistake", chunk)
if m != None: line = chunk
return line
class CompgeeksDailySpecials (BaseSpecial):
def __init__(self):
self.url = "http://www.compgeeks.com"
def getSpecial(self):
fp = urllib.urlopen(self.url)
lines = fp.readlines()
inTable = 0
tables = []
table = []
depth = 3
ret = ""
for chunk in lines:
if inTable < depth+1:
table = []
m = re.search("
0:
if inTable > depth:
table.append(chunk)
m = re.search("
", chunk)
if m != None:
inTable = inTable - 1
if inTable == depth:
self.splitTable(table, tables)
tab = 0
for t in tables:
tab = tab + 1
if self.tableHasAffiliate(t) == 1:
continue
for l in t:
m = re.search("SPECIALS", l)
if m != None:
for ll in t:
ll = re.sub("
]*>", "", ll)
ll = re.sub("", l)
if m != None: pairs.append( (starts.pop(), lineNo) )
lineNo = lineNo + 1
if len(pairs) > 2:
for p in pairs:
newTable = t[p[0]:p[1]]
if p[1] - p[0] > 10:
tables.append(newTable)
else:
tables.append(t)
class Stack:
def __init__(self):
self.stack = []
def push(self, obj):
self.stack.append(obj)
def pop(self):
ret, self.stack = self.stack[-1], self.stack[:-1]
return ret
print ""
bdc = BuyDotComPriceMistake()
print "%s" % bdc.getSpecial()
cg = CompgeeksDailySpecials()
print "%s" % cg.getSpecial()
print ""