Giter VIP home page Giter VIP logo

Comments (7)

stjohnjohnson avatar stjohnjohnson commented on August 16, 2024

I'm very interested in adding support for ReserveCalifornia. Looks like it's quite different of a layout.

I'd be happy to start poking at this. Any recommendation @juftin for how you would want this structured?

from camply.

juftin avatar juftin commented on August 16, 2024

Oh very nice. Here's a very rough guide for implementing a new "Provider" with camply:

  1. Implement a new BaseCampingSearch class:
    class BaseCampingSearch(ABC):
  • The BaseCampingSearch super class handles the high level interactions to do things like filter results to only weekends, look for consecutive nights, etc
  • This is an AbstractBaseClass that only requires you to define a single function: get_all_campsites which returns a list of AvailableCampsite data objects given the search parameters provided to the class
  • Here's an example of the Yellowstone implementation:
    class SearchYellowstone(BaseCampingSearch):
  1. Embed a BaseProvider into the newly created search class - this is used inside the BaseCampingSearch instance to actually search and create the camply.containers.AvailableCampsite objects

Hopefully this makes sense - if I were to totally rewrite camply today I might structure it differently, so maybe there's a way to do this better. I'm happy to help put things together as progress gets closer on the BaseProvider class as well

from camply.

juftin avatar juftin commented on August 16, 2024

Another note on how I parse results from the API: I use a custom pydantic.BaseModel class (CamplyModel) all over camply - it's a hashable data container class that defines core data containers like AvailableCampsite and CampgroundFacility but it also really helps to parse JSON responses from API's. Here's an example similar to what I'm doing in https://github.com/juftin/camply/blob/7b64c22994d4c9472317230b59b98da98eb224b9/camply/containers/api_responses.py.

import datetime
from enum import Enum
from typing import Dict

from camply.containers.base_container import CamplyModel

raw_campsite_api_response = {
    "campsite_id": "12345",
    "campsite_name": "example campsite",
    "campsite_availabilities": {
        "2022-03-05": "available",
        "2022-03-06": "unavailable",
        "2022-03-07": "unavailable",
        "2022-03-08": "unavailable",
        "2022-03-09": "available"
    },
    "campsite_location": "Anywhere, USA",
    "_non_useful_metadata_field": "sdcsad123431"

}


class ReserveCAAvailabilityOptions(str, Enum):
    available = "available"
    unavailable = "unavailable"


class ReserveCACampsiteResponse(CamplyModel):
    campsite_id: int
    campsite_name: str
    campsite_availabilities: Dict[datetime.date, ReserveCAAvailabilityOptions]
    campsite_location: str


easy_to_use_response = ReserveCACampsiteResponse(**raw_campsite_api_response)

That script defined our API response schema using pydantic, converted the raw dictionary into a data object using just the fields we defined, performed validation on the data provided and converted the string variables using python typing, and makes the data available in a way that's easy to code:

for datetime_obj, status in easy_to_use_response.campsite_availabilities.items():
    if status == ReserveCAAvailabilityOptions.available:
        print(f"{datetime_obj.strftime('%Y-%m-%d')} is available for camping!")

from camply.

bryanwhiting avatar bryanwhiting commented on August 16, 2024

👋 thanks for making Camply! I'm also interested in Reserve California. Any update on this?

from camply.

bryanwhiting avatar bryanwhiting commented on August 16, 2024

Here's another scraper that uses reserve_ca: https://github.com/ggydush/campsites - this is python based!

from camply.

juftin avatar juftin commented on August 16, 2024

At long last, I'm finally looking into implementing ReserveCalifornia. It's been tricky - but I've made some really amazing progress. https://github.com/ggydush/campsites has been super helpful - I ended up using a few APIs I haven't seen there or anywhere else as well. I'll have more to say here soon ✨

from camply.

juftin avatar juftin commented on August 16, 2024

ReserveCalifornia is ready! https://juftin.com/camply/providers/#reservecalifornia

@bryanwhiting @stjohnjohnson @magic7s I'd love your thoughts once you get around to using it. I tried testing it out on a number of Rec Areas and Campgrounds - but it could definitely use some more testing to make sure it supports all of ReserveCaliforna. Happy camping ⛺!

from camply.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.