Exemple #1
0
def testServer():
    configPath = "config_example.json"
    parentPath = os.environ.get('HOME')
    if not parentPath:
        print('can not fetch $HOME')
        parentPath = "."
    parentPath += "/airbnb"
    if not os.path.exists(parentPath):
        os.mkdir(parentPath, mode=0o755)

    logPath = parentPath + "/all_logs.log"
    storagePath = parentPath + "/rooms.db"
    config = parseConfigFile(configPath)
    if not config:
        sys.exit(0)
    config.localStoragePath = storagePath
    # 配置日志模块
    Log.config(logPath, echo=True)

    # 初始化service
    service = SearchService(config)

    # 准备入住日期数据
    start_date = datetime.datetime.now() + datetime.timedelta(weeks=1)
    time_title = '{:%Y-%m-%d}'.format(start_date)
    leave_dates = [start_date + datetime.timedelta(days=x) for x in [1, 2, 3]]
    checkin_date = '{:%Y-%m-%d}'.format(start_date)
    # 2020.03.22 一次尝试多种入住时间(1天,2天,3天),因为有些房源只有在1天以上入住时间下才能搜到
    checkout_dates = ['{:%Y-%m-%d}'.format(leave_date) for leave_date in leave_dates]

    # 启动查询
    service.doQuery(checkin_date, checkout_dates, time_title)
Exemple #2
0
def main():
    sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8')
    configPath = None
    parentPath = os.environ.get('HOME')
    if not parentPath:
        print('can not fetch $HOME')
        parentPath = "."
    parentPath += "/airbnb"
    if not os.path.exists(parentPath):
        os.mkdir(parentPath, mode=0o755)

    pidFilePath = parentPath + "/" + PID_FILE_NAME
    logPath = parentPath + "/all_logs.log"
    storagePath = parentPath + "/rooms.db"
    shortopts = 'h:c:d:l:s:v'  # 命令行参数简写
    longopts = [
        'help', 'storage-file=', 'log-file=', 'version', 'config-file='
    ]  # 完整体
    # 执行动作 start 后台运行,stop 结束后台已经运行的实例
    operation = None

    optlist, args = getopt.getopt(sys.argv[1:], shortopts, longopts)
    # 拿到命令行参数的key value
    for key, value in optlist:
        if key in ('-v', '--version'):
            print("version: airbnb fetcher 0.1")
            sys.exit(0)
        if key in ('-h', '--help'):
            printHelp()
            sys.exit(0)
        if key in ('-c', '--config-file'):
            configPath = value
        if key in ('-l', '--log-file'):
            logPath = value
        if key in ('-s', '--storage-file'):
            storagePath = value
        if key == '-d':
            operation = value

    # 配置日志模块
    Log.config(logPath, echo=False)
    if operation == "start":
        daemon_start(pidFilePath)
    elif operation == "stop":
        daemon_stop(pidFilePath)
        sys.exit(0)

    if not configPath:
        Log.e(MAIN_TAG, "config path not provided")
        sys.exit(0)
    config = parseConfigFile(configPath)
    if not config:
        sys.exit(0)
    config.localStoragePath = storagePath
    service = SearchService(config)
    service.start()