foursquare#

Description#

Plugin to interact with the Foursquare Places API.

It also raises events when a new check-in occurs on the user’s account.

In order to enable the Foursquare API on your account you need to:

  • Create a new app on the Foursquare developers website.

  • Copy the client_id and client_secret.

  • Add a redirect URL. It must point to a valid IP/hostname with a web server running, even if it runs

    locally. You can also use the local URL of the platypush web server - e.g. http://192.168.1.2:8008/.

  • Open the following URL:

    https://foursquare.com/oauth2/authenticate?client_id=CLIENT_ID&response_type=token&redirect_uri=REDIRECT_URI. Replace CLIENT_ID and REDIRECT_URI with the parameters from your app.

  • Allow the application. You will be redirected to the URL you provided. Copy the access_token provided in

    the URL.

Configuration#

foursquare:
  # [Required]
  # The access token to use to authenticate to the Foursquare API.
  access_token:   # type=str

  # [Optional]
  # How often the `RunnablePlugin.loop <https://docs.platypush.tech/platypush/plugins/.html#platypush.plugins.RunnablePlugin.loop>`_ function should be
  # executed (default: 15 seconds). *NOTE*: For back-compatibility
  # reasons, the `poll_seconds` argument is also supported, but it's
  # deprecated.
  # poll_interval: 120  # type=float

  # [Optional]
  # How long we should wait for any running
  # threads/processes to stop before exiting (default: 5 seconds).
  # stop_timeout: 5  # type=Optional[float]

  # [Optional]
  # If set to True then the plugin will not monitor
  # for new events. This is useful if you want to run a plugin in
  # stateless mode and only leverage its actions, without triggering any
  # events. Defaults to False.
  # disable_monitor: False  # type=bool

Triggered events#

Actions#

Module reference#

class platypush.plugins.foursquare.FoursquarePlugin(access_token: str, poll_interval: float = 120, **kwargs)[source]#

Bases: RunnablePlugin

Plugin to interact with the Foursquare Places API.

It also raises events when a new check-in occurs on the user’s account.

In order to enable the Foursquare API on your account you need to:

  • Create a new app on the Foursquare developers website.

  • Copy the client_id and client_secret.

  • Add a redirect URL. It must point to a valid IP/hostname with a web server running, even if it runs

    locally. You can also use the local URL of the platypush web server - e.g. http://192.168.1.2:8008/.

  • Open the following URL:

    https://foursquare.com/oauth2/authenticate?client_id=CLIENT_ID&response_type=token&redirect_uri=REDIRECT_URI. Replace CLIENT_ID and REDIRECT_URI with the parameters from your app.

  • Allow the application. You will be redirected to the URL you provided. Copy the access_token provided in

    the URL.

__init__(access_token: str, poll_interval: float = 120, **kwargs)[source]#
Parameters:

access_token – The access token to use to authenticate to the Foursquare API.

checkin(venue_id: str, latitude: float | None = None, longitude: float | None = None, altitude: float | None = None, latlng_accuracy: float | None = None, altitude_accuracy: float | None = None, shout: str | None = None, broadcast: List[str] | None = None) Dict[str, Any][source]#

Create a new check-in.

Parameters:
  • venue_id – ID of the venue to check-in.

  • latitude – Check-in latitude.

  • longitude – Check-in longitude.

  • altitude – Check-in altitude.

  • latlng_accuracy – Latitude/longitude accuracy in meters.

  • altitude_accuracy – Altitude accuracy in meters.

  • shout – Add a custom message to the check-in.

  • broadcast

    List of Visibility/share types of the check-in. Default: public. Possible values are:

    • private

    • public

    • followers

    • facebook

    • twitter

Returns:

Foursquare API response.

explore(latitude: float | None = None, longitude: float | None = None, altitude: float | None = None, latlng_accuracy: float | None = None, altitude_accuracy: float | None = None, section: str | None = None, near: str | None = None, query: str | None = None, limit: int | None = None, categories: List[str] | None = None, radius: int | None = None, open_now: bool = True, sort_by_distance: bool | None = None, sort_by_popularity: bool | None = None, price: List[int] | None = None, saved: bool | None = None) List[Dict[str, Any]][source]#

Explore venues around a location.

Parameters:
  • latitude – Search near this latitude. Note either latitude, longitude or near should be provided.

  • longitude – Search near this latitude. Note either latitude, longitude or near should be provided.

  • near – Search near this place (e.g. “Chicago, IL” or “Amsterdam, NL”). Note either latitude, longitude or near should be provided.

  • altitude – Search near this altitude in meters.

  • latlng_accuracy – Latitude/longitude accuracy in meters.

  • altitude_accuracy – Altitude accuracy in meters.

  • section

    Section to search. Supported values:

    • food

    • drinks

    • coffee

    • shops

    • arts

    • outdoors

    • sights

    • trending

    • nextVenues

  • query – Search query (e.g. “coffee shops” or “restaurants”). The parameter has no effect if section is specified.

  • limit – Maximum number of results.

  • categories – List of category IDs to be searched.

  • radius – Search radius in meters.

  • open_now – Filter by open/not open now.

  • sort_by_distance – Sort by distance.

  • sort_by_popularity – Sort by popularity

  • price – Price ranges, within the range [1,2,3,4].

  • saved – Filter by saved/unsaved venues.

Returns:

A list of venues, as returned by the Foursquare API.

get_checkins() List[Dict[str, Any]][source]#

Get the list of check-ins of the current user. :return: A list of checkins, as returned by the Foursquare API.

main()[source]#

Implementation of the main loop of the plugin.

managed() List[Dict[str, Any]][source]#

Get the list of venues managed by the user. :return: A list of venues, as returned by the Foursquare API.

search(latitude: float | None = None, longitude: float | None = None, altitude: float | None = None, latlng_accuracy: float | None = None, altitude_accuracy: float | None = None, near: str | None = None, query: str | None = None, limit: int | None = None, url: str | None = None, categories: List[str] | None = None, radius: int | None = None, sw: Tuple[float] | List[float] | None = None, ne: Tuple[float] | List[float] | None = None) List[Dict[str, Any]][source]#

Search for venues.

Parameters:
  • latitude – Search near this latitude. Note either latitude, longitude or near should be provided.

  • longitude – Search near this latitude. Note either latitude, longitude or near should be provided.

  • near – Search near this place (e.g. “Chicago, IL” or “Amsterdam, NL”). Note either latitude, longitude or near should be provided.

  • altitude – Search near this altitude in meters.

  • latlng_accuracy – Latitude/longitude accuracy in meters.

  • altitude_accuracy – Altitude accuracy in meters.

  • query – Search query (e.g. “coffee shops” or “restaurants”).

  • limit – Maximum number of results.

  • url – Venue URL to search.

  • categories

    List of category IDs to be searched.

  • radius – Search radius in meters.

  • sw – South/west boundary box as a [latitude, longitude] pair.

  • ne – North/east boundary box as a [latitude, longitude] pair.

Returns:

A list of venues, as returned by the Foursquare API.

start()#

Start the plugin.

stats(venue_id: str, start_at: int | float | datetime | str, end_at: int | float | datetime | str) List[Dict[str, Any]][source]#

Get the stats about a venue over a time range. The user must be a manager of that venue.

Parameters:
  • venue_id – Venue ID.

  • start_at – Stats start time. Can be a UNIX timestamp, a datetime object or an ISO format datetime.

  • end_at – Stats end time. Can be a UNIX timestamp, a datetime object or an ISO format datetime.

Returns:

A list of venues, as returned by the Foursquare API.

stop()#

Stop the plugin.

time_series(venue_id: str | List[str], start_at: int | float | datetime | str, end_at: int | float | datetime | str) List[Dict[str, Any]][source]#

Get the visitors stats about one or multiple venues over a time range. The user must be a manager of those venues.

Parameters:
  • venue_id – Venue ID or list of IDs to get the stats for.

  • start_at – Stats start time. Can be a UNIX timestamp, a datetime object or an ISO format datetime.

  • end_at – Stats end time. Can be a UNIX timestamp, a datetime object or an ISO format datetime.

Returns:

A list of venues, as returned by the Foursquare API.

trending(latitude: float | None = None, longitude: float | None = None, near: str | None = None, limit: int | None = None, radius: int | None = None) List[Dict[str, Any]][source]#

Get the trending venues around a location.

Parameters:
  • latitude – Search near this latitude. Note either latitude, longitude or near should be provided.

  • longitude – Search near this latitude. Note either latitude, longitude or near should be provided.

  • near – Search near this place (e.g. “Chicago, IL” or “Amsterdam, NL”). Note either latitude, longitude or near should be provided.

  • limit – Maximum number of results.

  • radius – Search radius in meters.

Returns:

A list of venues, as returned by the Foursquare API.

wait_stop(timeout=None)#

Wait until a stop event is received.