juftin / camply

camply, the campsite finder ⛺️ - a tool to find campsites at sold out campgrounds through sites like recreation.gov
https://juftin.com/camply/
MIT License
486 stars 94 forks source link

yaml search with ReserveCalifornia fails with TypeError: object of type 'NoneType' has no len() #279

Closed smilinggoat closed 1 year ago

smilinggoat commented 1 year ago

Describe the bug

When configuring camply to use a yaml file for searches, if the provider is ReserveCalifornia, it consistently exits with TypeError: object of type 'NoneType' has no len()

Original Camply Command (with --debug)

camply campsites --yaml-config my_search.yaml --debug

my_search.yaml content

provider: ReserveCalifornia
recreation_area: 1077
start_date: 2023-07-21
end_date: 2023-07-23

Expected behavior

Command should have the same output as when ReserveCalifornia is used with inline arguments.

Console Output (with --debug)

[2023-07-05 15:37:05] CAMPLY   camply, the campsite finder ⛺️                                                                                                                         
[2023-07-05 15:37:05] DEBUG    Setting up camply debugging                                                                                                                            
[2023-07-05 15:37:05] DEBUG    Camply Version: 0.27.0                                                                                                                                 
[2023-07-05 15:37:05] DEBUG    Python Version: 3.11.4                                                                                                                                 
[2023-07-05 15:37:05] DEBUG    Platform: darwin                                                                                                                                       
[2023-07-05 15:37:05] INFO     YAML File Parsed: my_search.yaml                                                                                                                       
[2023-07-05 15:37:05] INFO     Using Camply Provider: "ReserveCalifornia"                                                                                                             
[2023-07-05 15:37:05] INFO     2 booking nights selected for search, ranging from 2023-07-21 to 2023-07-22                                                                            
[2023-07-05 15:37:05] CAMPLY   Exiting camply 👋                                                                                                                                      
╭─────────────────────────────── Traceback (most recent call last) ────────────────────────────────╮
│ /Users/ixtli/.local/bin/camply:8 in <module>                                                     │
│                                                                                                  │
│   5 from camply.cli import cli                                                                   │
│   6 if __name__ == '__main__':                                                                   │
│   7 │   sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])                         │
│ ❱ 8 │   sys.exit(cli())                                                                          │
│   9                                                                                              │
│                                                                                                  │
│ ╭─────────────────────────────────────────── locals ───────────────────────────────────────────╮ │
│ │ cli = <function cli at 0x12ec04040>                                                          │ │
│ │  re = <module 're' from                                                                      │ │
│ │       '/opt/homebrew/Cellar/python@3.11/3.11.4_1/Frameworks/Python.framework/Versions/3.11/… │ │
│ │ sys = <module 'sys' (built-in)>                                                              │ │
│ ╰──────────────────────────────────────────────────────────────────────────────────────────────╯ │
│                                                                                                  │
│ /Users/ixtli/.local/pipx/venvs/camply/lib/python3.11/site-packages/camply/cli.py:881 in cli      │
│                                                                                                  │
│   878 │   Camply Command Line Utility Wrapper                                                    │
│   879 │   """                                                                                    │
│   880 │   try:                                                                                   │
│ ❱ 881 │   │   camply_command_line()                                                              │
│   882 │   except KeyboardInterrupt:                                                              │
│   883 │   │   logger.debug("Handling Exit Request")                                              │
│   884 │   finally:                                                                               │
│                                                                                                  │
│ /Users/ixtli/.local/pipx/venvs/camply/lib/python3.11/site-packages/click/core.py:1130 in         │
│ __call__                                                                                         │
│                                                                                                  │
│ /Users/ixtli/.local/pipx/venvs/camply/lib/python3.11/site-packages/rich_click/rich_group.py:21   │
│ in main                                                                                          │
│                                                                                                  │
│ /Users/ixtli/.local/pipx/venvs/camply/lib/python3.11/site-packages/click/core.py:1055 in main    │
│                                                                                                  │
│ /Users/ixtli/.local/pipx/venvs/camply/lib/python3.11/site-packages/click/core.py:1657 in invoke  │
│                                                                                                  │
│ /Users/ixtli/.local/pipx/venvs/camply/lib/python3.11/site-packages/click/core.py:1404 in invoke  │
│                                                                                                  │
│ /Users/ixtli/.local/pipx/venvs/camply/lib/python3.11/site-packages/click/core.py:760 in invoke   │
│                                                                                                  │
│ /Users/ixtli/.local/pipx/venvs/camply/lib/python3.11/site-packages/click/decorators.py:38 in     │
│ new_func                                                                                         │
│                                                                                                  │
│ /Users/ixtli/.local/pipx/venvs/camply/lib/python3.11/site-packages/camply/cli.py:772 in          │
│ campsites                                                                                        │
│                                                                                                  │
│   769 │   │   │   yaml_config=yaml_config,                                                       │
│   770 │   │   )                                                                                  │
│   771 │   provider_class: Type[BaseCampingSearch] = CAMPSITE_SEARCH_PROVIDER[provider]           │
│ ❱ 772 │   camping_finder: BaseCampingSearch = provider_class(**provider_kwargs)                  │
│   773 │   camping_finder.get_matching_campsites(**search_kwargs)                                 │
│   774                                                                                            │
│   775                                                                                            │
│                                                                                                  │
│ ╭──────────────────────────────────────── locals ────────────────────────────────────────╮       │
│ │          campground = ()                                                               │       │
│ │            campsite = ()                                                               │       │
│ │             context = CamplyContext(debug=True, provider=None)                         │       │
│ │          continuous = False                                                            │       │
│ │                 day = ()                                                               │       │
│ │               debug = True                                                             │       │
│ │            end_date = ()                                                               │       │
│ │           equipment = ()                                                               │       │
│ │        equipment_id = None                                                             │       │
│ │              nights = 1                                                                │       │
│ │       notifications = ()                                                               │       │
│ │    notify_first_try = None                                                             │       │
│ │      offline_search = False                                                            │       │
│ │ offline_search_path = None                                                             │       │
│ │    polling_interval = None                                                             │       │
│ │            provider = 'ReserveCalifornia'                                              │       │
│ │      provider_class = <class 'camply.search.search_usedirect.SearchReserveCalifornia'> │       │
│ │     provider_kwargs = {                                                                │       │
│ │                       │   'search_window': SearchWindow(                               │       │
│ │                       │   │   start_date=datetime.date(2023, 7, 21),                   │       │
│ │                       │   │   end_date=datetime.date(2023, 7, 23)                      │       │
│ │                       │   ),                                                           │       │
│ │                       │   'recreation_area': 1077,                                     │       │
│ │                       │   'campgrounds': None,                                         │       │
│ │                       │   'campsites': None,                                           │       │
│ │                       │   'weekends_only': False,                                      │       │
│ │                       │   'days_of_the_week': None,                                    │       │
│ │                       │   'nights': 1,                                                 │       │
│ │                       │   'equipment': None,                                           │       │
│ │                       │   'offline_search': False,                                     │       │
│ │                       │   'offline_search_path': None                                  │       │
│ │                       }                                                                │       │
│ │            rec_area = ()                                                               │       │
│ │      search_forever = None                                                             │       │
│ │       search_kwargs = {                                                                │       │
│ │                       │   'log': True,                                                 │       │
│ │                       │   'verbose': True,                                             │       │
│ │                       │   'continuous': True,                                          │       │
│ │                       │   'polling_interval': 10,                                      │       │
│ │                       │   'notify_first_try': False,                                   │       │
│ │                       │   'notification_provider': 'silent',                           │       │
│ │                       │   'search_forever': False,                                     │       │
│ │                       │   'search_once': False                                         │       │
│ │                       }                                                                │       │
│ │         search_once = False                                                            │       │
│ │          start_date = ()                                                               │       │
│ │            weekends = False                                                            │       │
│ │         yaml_config = '/Users/ixtli/my_search.yaml'                                    │       │
│ ╰────────────────────────────────────────────────────────────────────────────────────────╯       │
│                                                                                                  │
│ /Users/ixtli/.local/pipx/venvs/camply/lib/python3.11/site-packages/camply/search/search_usedirec │
│ t.py:84 in __init__                                                                              │
│                                                                                                  │
│    81 │   │   self._recreation_area_ids: List[int] = make_list(recreation_area, coerce=int)      │
│    82 │   │   self._campground_ids: List[int] = make_list(campgrounds, coerce=int)               │
│    83 │   │   campsites = make_list(kwargs.get("campsites", []), coerce=int)                     │
│ ❱  84 │   │   if len(campsites) > 0:                                                             │
│    85 │   │   │   self.campsite_finder.validate_campsites(                                       │
│    86 │   │   │   │   campsites=campsites, facility_ids=self._campground_ids                     │
│    87 │   │   │   )                                                                              │
│                                                                                                  │
│ ╭─────────────────────────────────────────── locals ───────────────────────────────────────────╮ │
│ │     campgrounds = None                                                                       │ │
│ │       campsites = None                                                                       │ │
│ │          kwargs = {                                                                          │ │
│ │                   │   'campsites': None,                                                     │ │
│ │                   │   'days_of_the_week': None,                                              │ │
│ │                   │   'equipment': None,                                                     │ │
│ │                   │   'offline_search': False,                                               │ │
│ │                   │   'offline_search_path': None                                            │ │
│ │                   }                                                                          │ │
│ │          nights = 1                                                                          │ │
│ │ recreation_area = 1077                                                                       │ │
│ │   search_window = SearchWindow(                                                              │ │
│ │                   │   start_date=datetime.date(2023, 7, 21),                                 │ │
│ │                   │   end_date=datetime.date(2023, 7, 23)                                    │ │
│ │                   )                                                                          │ │
│ │            self = <camply.search.search_usedirect.SearchReserveCalifornia object at          │ │
│ │                   0x10eb89810>                                                               │ │
│ │   weekends_only = False                                                                      │ │
│ ╰──────────────────────────────────────────────────────────────────────────────────────────────╯ │
╰──────────────────────────────────────────────────────────────────────────────────────────────────╯
TypeError: object of type 'NoneType' has no len()

Additional context

Formatting the above search as an inline command successfully completes:

camply --debug campsites \
    --provider ReserveCalifornia \
    --rec-area 1077 \
    --start-date 2023-07-21 \
    --end-date 2023-07-23