#!/usr/bin/env python
# -*- coding:utf-8 -*-

import os
import sys
import abc
import zcommand
import itertools
from search_engine_spider import SearchEngineManager


class SearchEngineSpider(zcommand.RunCommand):
    def __init__(self):
        super(SearchEngineSpider, self).__init__("help")
        self.mgr = SearchEngineManager()
        self.command.add('list', self.mgr.print_search_engine, 0, 0,
                         "list", "列出当前搜索引擎")
        self.command.add('product-urls', self.mgr.product_urls, 2, 100,
                         "product-urls engine_name url_file1 [url_file2]...",
                         "产生该搜索引擎要搜索的url")
        self.command.add('extract-html', self.mgr.print_extract_html, 2, 3,
                         "extract-html engine_name html_path [max_num]", "提取html内容")
        self.command.add('extract-json', self.mgr.print_extract_json, 2, 3,
                         "extract-json engine_name json_path [max_num]",
                         "提取json内容, 是一个json文件，有url，content字段")
        self.command.add('recovery', self.mgr.recovery_rate, 2, 3,
                         "recovery local_site_file json_result_path [max_num]",
                         "根据本地已经有的站点和extrct-json的结果计算本地覆盖率")

if __name__=="__main__":
    spider = SearchEngineSpider()
    spider.run(sys.argv[1:])
