#! /usr/bin/python
# -*- encoding:utf-8 -*-

import re
import my_utils
from base_parse import BaseParse
from lxml import etree
from items import Item


class Ifeng1(BaseParse):
    def _parse(self, raw_html):
        root = etree.HTML(raw_html)
        lines = root.xpath("//ul[contains(@id,'list01')]/li")
        for li in lines:
            item = Item()
            item.set('url', "".join(li.xpath("./h3/a/@href")))
            item.set('status', 1)
            item.set('title', "".join(li.xpath("./h3/a/text()")))
            nid_match = re.match(r".*/(\d+)/(\d+)_(\d+)\.shtml$", item.url)
            if nid_match:
                item.set('nid', nid_match.group(1)+nid_match.group(2)+nid_match.group(3))
            times = "".join(li.xpath(".//div[contains(@class,'date')]/text()"))
            item.set('timestamp', my_utils.get_timestamp(times))
            self._add_to_data(item)
