utils.py 文件源码

python
阅读 20 收藏 0 点赞 0 评论 0

项目:PokeAlarm 作者: tlkh2311 项目源码 文件源码
def set_config(root_path):
    config['ROOT_PATH'] = root_path
    configpath = get_path('config/config.ini')
    parser = configargparse.ArgParser(default_config_files=[configpath])
    parser.add_argument('-H', '--host', help='Set web server listening host', default='127.0.0.1')
    parser.add_argument('-P', '--port', type=int, help='Set web server listening port', default=4000)
    parser.add_argument('-k', '--key', help='Specify a Google Maps API Key to use.')
    parser.add_argument('-c', '--config', help='Alarms configuration file. default: alarms.json', default='alarms.json')
    parser.add_argument('-l', '--location', type=parse_unicode, help='Location, can be an address or coordinates')
    parser.add_argument('-L', '--locale', help='Locale for Pokemon names: default en, check locale folder for more options', default='en')
    parser.add_argument('-u' , '--units',  help='Specify either metric or imperial . Default: metric', choices=['metric', 'imperial'], default='metric')
    parser.add_argument('-d', '--debug', help='Debug Mode', action='store_true',  default=False)
    parser.add_argument('-gf', '--geofence', help='Specify a file of coordinates, limiting alerts to within this area')
    parser.add_argument('-tl', '--timelimit', type=int, help='Minimum number of seconds remaining on a pokemon to notify', default=0)
    parser.add_argument('-tz', '--timezone', help='Timezone used for notifications.  Ex: "America/Los_Angeles"')
    parser.add_argument('-sp', '--sp_url', help='SP_URL')

    args = parser.parse_args()

    config['HOST'] = args.host
    config['PORT'] = args.port
    config['CONFIG_FILE'] = args.config
    config['LOCALE'] = args.locale
    config['DEBUG'] = args.debug
    config['UNITS'] = args.units
    config['TIME_LIMIT'] = args.timelimit
    config['SP_URL'] = args.sp_url

    if args.key:
        config['API_KEY'] = key=args.key
        config['GMAPS_CLIENT'] = googlemaps.Client(key=args.key)

    if args.location:
        config['LOCATION'] =  get_pos_by_name(args.location)

    if args.geofence:
        config['GEOFENCE'] = Geofence(os.path.join(root_path, args.geofence))

    if args.timezone:
        try:
            config['TIMEZONE'] = pytz.timezone(args.timezone)
            log.info("Timezone set to: %s" % args.timezone)
        except pytz.exceptions.UnknownTimeZoneError:
            log.error("Invalid timezone. For a list of valid timezones, see https://en.wikipedia.org/wiki/List_of_tz_database_time_zones")
            sys.exit(1)

    config['REV_LOC'] = False
    config['DM_WALK'] = False
    config['DM_BIKE'] = False
    config['DM_DRIVE'] = False

    return config

#Returns +inf if True, else float, else None
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号