def treat_serie(serie_name, site_name = 'en', main_page_name = None, num = None):
    """ main """

    if not main_page_name:
        main_page_name = serie_name
    

    site = pywikibot.Site(site_name, "wikipedia")
    output(u"======> Serie : {}, Page: {}".format(serie_name, main_page_name) )    
    serie_item = wd_lib.item_by_title(site, main_page_name)
    
    title_pattern = u"{}_(season_{})"

    has_previous = True
    current = 1
    items = {}

    if not num:
        num = 1000

    try:
        while has_previous and current <= num:
            title = title_pattern.format(serie_name, current)
            page = pywikibot.Page(site, title)
            output(title)
            if page.exists():
                datapage = pywikibot.ItemPage.fromPage(page)
                if datapage.exists():
                    datapage.get()
                    items[current] = datapage
                else:
                    raise NoPage("page do not exists")
                
                current += 1
            else:
                has_previous = False
    except NoPage:
        pass # doing nothing, TODO: mark and log

    num_season = current - 1

    output(u"=>Number of seasons : {}".format(num_season))
    
    for i in range(1, len(items) + 1):
        output("===> Saison {}\n".format(i))
        
        output(u"season {}, item: {}". format(i, items[i]))
        set_season_labels(serie_item, items[i], serie_name, i)
        if i > 1:
            wd_lib.set_previous(items[i], items[i-1])
        if i < num_season:
            wd_lib.set_next(items[i], items[i+1])
        # part of (P361): this item is a part of that item 
        wd_lib.maybe_set_claim(items[i], 361, serie_item)
        wd_lib.instance_of(items[i], wd_lib.item_by_title("fr", u"Saison (télévision)"))
        
        output("===> End of aison {} processing\n".format(i))
    
    output("======> End of serie (maybe) processing\n")
def treat_serie(serie_name, site_name = 'en', \
        main_page_name = None, num = None, start_year = None, title_pattern = "{}_{}"):
    """ main """

    if not main_page_name:
        main_page_name = serie_name
    

    site = pywikibot.getSite(site_name)
    print("Serie : {}, Page: {}".format(serie_name, main_page_name) )    
    serie_item = wd_lib.item_by_title(site, main_page_name)
    
    # Patterns of the titles of the series
    
    has_previous = True
    current = 1
    items = {}

    if not num:
        num = 1000
    
    year = start_year

    while has_previous and current < num:
        title = title_pattern.format(serie_name, year)
        pywikibot.output("searching article : {}".format(title))
        
        page = pywikibot.Page(site, title)
        
        print(title)
        
        if page.exists():
            datapage = pywikibot.DataPage(page)
            if datapage.exists():
                datapage.get()
                items[current] = datapage
            else:
                raise Exception()
            current += 1
            year = year + 1
        else:
            has_previous = False

    num_season = current - 1

    print("Number of seasons : {}".format(num_season))

    year = start_year
    for i in range(1, len(items) + 1):
        print("season {}, item: {}". format(i, items[i]))
        set_season_labels(items[i], serie_name, i, year)
        
        year = year + 1
                
        # part of (P361): this item is a part of that item 
        items[i] = wd_lib.reloaditempage(items[i])
        wd_lib.maybe_set_claim(items[i], 361, serie_item)
        # wd_lib.instance_of(items[i], wd_lib.item_by_title("fr", u"Saison (télévision)"))
    type_item = wd_lib.item_by_title("fr", u"Saison (télévision)")
    print(type_item)
    wd_lib.make_sequence(items.itervalues(), type_item)