# Path: uamobile/scrapers/base.py
# class Scraper(object):
#     # subclass must override this property
#     url = None
# 
#     def scrape(self):
#         stream = self.get_stream()
#         doc = self.get_document(stream)
#         return self.do_scrape(doc)
# 
#     def get_document(self, stream):
#         doc = etree.parse(stream, etree.HTMLParser(remove_comments=True))
#         return doc
# 
#     def get_stream(self):
#         return urllib2.urlopen(self.url)
# 
#     def do_scrape(self, doc):
#         raise NotImplementedError()


from uamobile.scrapers.base import Scraper
class EZWebScraper(Scraper):
    url = 'http://www.au.kddi.com/ezfactory/tec/spec/ezsava_ip.html'

    def do_scrape(self, doc):
        res = []
        rows = doc.xpath("""//table[@cellspacing="1"]/tr[@bgcolor="#ffffff"]""")
        for row in rows:
            cols = row.xpath('./td/div[@class="TableText"]/text()')
            if len(cols) == 4:
                # deprecated
                continue
            res.append(str('%s%s' % (cols[1], cols[2])))
        return res


class SoftBankScraper(Scraper):
    url = 'http://creation.mb.softbank.jp/web/web_ip.html'

    def do_scrape(self, doc):
        return [str(x.text.strip()) for x in doc.xpath("//div[@class='contents']/table/tr[7]/td/table/tr/td/table/tr/td")]


class WILLCOMScraper(Scraper):
    url = 'http://www.willcom-inc.com/ja/service/contents_service/create/center_info/index.html'

    def do_scrape(self, doc):
        res = []
        sep = 0
        for td in doc.xpath("//table[@width='100%' and @cellspacing='1' and @cellpadding='3']/tr/td"):
            if td.attrib.get('colspan') == "4":

# Path: uamobile/scrapers/base.py
# class Scraper(object):
#     # subclass must override this property
#     url = None
# 
#     def scrape(self):
#         stream = self.get_stream()
#         doc = self.get_document(stream)
#         return self.do_scrape(doc)
# 
#     def get_document(self, stream):
#         doc = etree.parse(stream, etree.HTMLParser(remove_comments=True))
#         return doc
# 
#     def get_stream(self):
#         return urllib2.urlopen(self.url)
# 
#     def do_scrape(self, doc):
#         raise NotImplementedError()


# Path: uamobile/scrapers/cidr.py
from uamobile.scrapers.base import Scraper

class EZWebScraper(Scraper):
    url = 'http://www.au.kddi.com/ezfactory/tec/spec/ezsava_ip.html'

    def do_scrape(self, doc):
        res = []
        rows = doc.xpath("""//table[@cellspacing="1"]/tr[@bgcolor="#ffffff"]""")
        for row in rows:
            cols = row.xpath('./td/div[@class="TableText"]/text()')
            if len(cols) == 4:
                # deprecated
                continue
            res.append(str('%s%s' % (cols[1], cols[2])))
        return res


class SoftBankScraper(Scraper):
    url = 'http://creation.mb.softbank.jp/web/web_ip.html'

    def do_scrape(self, doc):
        return [str(x.text.strip()) for x in doc.xpath("//div[@class='contents']/table/tr[7]/td/table/tr/td/table/tr/td")]


class WILLCOMScraper(Scraper):
    url = 'http://www.willcom-inc.com/ja/service/contents_service/create/center_info/index.html'

    def do_scrape(self, doc):
        res = []
        sep = 0
        for td in doc.xpath("//table[@width='100%' and @cellspacing='1' and @cellpadding='3']/tr/td"):
            if td.attrib.get('colspan') == "4":

                sep += 1