#!/usr/bin/python
# dell_warranty.py v0.1
# Written by Frode Egeland <egeland[at]gmail.com> - Copyright 2009
# Released under the terms of the GNU GPL v3 - see http://www.gnu.org/licenses/gpl-3.0.html
#
# Version History
# 0.1 - 2009-10-12 - Frode Egeland - Initial version. Tested with a simple csv list of service tags only.
#
import urllib2, csv, re
from BeautifulSoup import BeautifulSoup
url="http://support.dell.com/support/topics/global.aspx/support/my_systems_info/details?c=us&l=en&s=gen&ServiceTag=%s"
stlist = []
# generate a list of servicetags from a csv
csvfile = csv.reader(open('taglist.csv'))
for line in csvfile:
for entry in line:
stlist.append(entry)
fixdate = re.compile("(\d{1,2})\/(\d{1,2})\/(\d{4})")
print "Service Tag, Warranty Type, Provider, Start Date, End Date, Days Remaining"
for currtag in stlist:
page = urllib2.urlopen(url % (currtag,))
for line in page.readlines():
if "Parts only Warranty" in line:
soup = BeautifulSoup(line)
break
table = soup.find('table',{'class':"contract_table"})
rows = table.findAll('tr')
rows = rows[1:]
for row in rows:
output = "%s" % (currtag,)
cells = row.findAll('td')
for cell in cells:
if cell.a: # link / formatted text
txt = cell.a.string
elif cell.b: # bold text
txt = cell.b.string
elif cell.i: # italic
txt = cell.i.string
else: #normal text
txt = cell.string
match = fixdate.search(txt)
if match:
txt = "%d-%d-%d" % (int(match.group(3)),int(match.group(1)),int(match.group(2)))
output = "%s,%s" % (output,txt)
output = output.strip()
print output