#!/usr/bin/env python2
# vim:fileencoding=utf-8
from __future__ import unicode_literals, division, absolute_import

from calibre.web.feeds.news import BasicNewsRecipe

class Pro_Git_ZH(BasicNewsRecipe):

    language = 'zh'
    title = '阿信-新浪博客'
    description = '阿信-新浪博客'
    cover_url = 'http://iissnan.com/progit/assets/img/pro-git-cover.jpeg'

    uid = '1686302192' ;
    url_prefix = 'http://blog.sina.com.cn/s/articlelist_' + uid + '_0_1.html'
    no_stylesheets = False
    # 仅保留文章的post中的内容，其中为自己分析得到的正文范围
    keep_only_tags = [{ 'class': 'articalContent' }]

    def parse_index(self):
        soup = self.index_to_soup(self.url_prefix)

        #itprint soup.html.head.contents[10];
        str1 = soup.html.head.contents[10]
        index_start = str1.find('<div class="articleList">')
        index_end = str1.find('<div class="SG_page">')
        div = BeautifulSoup(str1[index_start:index_end]).contents[0].findAll('div', {'class': 'articleCell SG_j_linedot1'})

        print len(div)


        articles = []
        for d in div:
            for link in d.findAll('a'):

                til = link.contents[0].strip()
                url = link['href']
                a = { 'title': til, 'url': url }
                print a
                articles.append(a)
#        return
        ans = [('阿信-新浪博客', articles)]

        return ans
