예제 #1
0
def run(conf={}):
    """
    @param {Dict} conf
    @param conf.date 抓取日期
    @param {'min'|'detail'|'info'} [conf.download] 数据更新内容.day为日线数据,detail为详细数据,info为股票代码,对应的公司名等数据
    @param {'detail'|'all'|'day'} [conf.mode] 当数据抓取模式为'day'时,'day'数据抓取模式。detail为从detail数据中抓取数据。all为抓取所有数据。day为更新每日数据
    @param {'single'|'mutil'} [conf.thread] 当数据抓取模式为'detail'时,采取的线程模式。single为单线程,mutil为多线程
    """
    logging.info("Start spider.")
    downloader=Downloader(conf)
    check = Check(conf)
    date = conf.get("date",Date.getDate())
    checkIndex = 0
    while checkIndex < conf.get("MIN_DATA_NUM",MIN_DATA_NUM):
        checkDate=Date.getDate(0-checkIndex,date)
        checkReport = check.check(checkDate)
        if not checkReport:
            logging.info("Download %s 's data." % checkDate)
            downloader.download(name="detail",conf={"date":checkDate})
        checkIndex += 1
    logging.info("Download finish.")
    return True
예제 #2
0
def parseArgs(conf):
    """
    parse args 
    """
    import argparse
    args={}
    argparser=argparse.ArgumentParser(description = __doc__.strip())
    argparser.add_argument("--version",action='version', \
                           version='%(prog)s '+str(conf.get("VERSION")))
    subparsers=argparser.add_subparsers(metavar="<action>")

    #start
    startparser=subparsers.add_parser("start",description="开始运行程序.")
    startparser.set_defaults(action="run")
    startparser.add_argument("--restart",type=str)
    startparser.add_argument("--from",type=str)
    startparser.add_argument("--date",type=str)

    #run
    runparser=subparsers.add_parser("run",description="运行指定模块.")
    runparser.set_defaults(action="run")
    runparser.add_argument("--module",type=str)
    runparser.add_argument("--ignore",type=str)
    runparser.add_argument("--from",type=str)
    runparser.add_argument("--date",type=str)
    runparser.add_argument("--debug",help='用debug模式计算,用于调试程序',action="store_true")

    #update
    updateparser=subparsers.add_parser("update",description="更新指定日期数据.")
    updateparser.set_defaults(action="update")
    updateparser.add_argument("--from",type=str)
    updateparser.add_argument("--date",type=str)

    #updateInfo
    updateInfoParser=subparsers.add_parser("updateInfo",description="更新整个市场的股票信息,如有多少股票,每个股票代码对应的名称等.")
    updateInfoParser.set_defaults(action="updateInfo")
    
    #shell
    shellparser = subparsers.add_parser("shell",description="shell.")
    shellparser.set_defaults(action="shell")
    
    #instant
    instantparser = subparsers.add_parser("instant",description="instant compute for sotck.")
    instantparser.set_defaults(action="instant")

    parsedArgs=argparser.parse_args()
    
    #generate conf
    #--date
    if parsedArgs and getattr(parsedArgs,"date",None):
        args['dates'] = parsedArgs.date.split(",")
    #--from
    if getattr(parsedArgs,"from",None):
        from lib.stk.data.Check import Check
        check=Check(conf)
        args['dates'] = check.getAvailableDate(date = getattr(parsedArgs,"from"),module = getattr(parsedArgs,"module",None))
    #--module
    if getattr(parsedArgs,"module",None):
        args["module"]=[]
        modules=parsedArgs.module.split(",")
        for module in modules:
            args["module"].append(module)
    #--ignore
    if getattr(parsedArgs,"ignore",None):
        args["module"]=STOCK_MODULES
        modules=parsedArgs.ignore.split(",")
        for module in modules:
            if module in args["module"]:
                del args["module"][args["module"].index(module)]
                logging.info("Ignore "+str(module))
    #--debug
    if getattr(parseArgs,"debug",None):
        args["DEBUG"]=True
    args['action']=parsedArgs.action
    return args