httplib2 should be an explicit dependency for Google integrations.

Plus, some misc LINT/Black chores.
This commit is contained in:
Fabio Manganiello 2023-10-01 00:52:59 +02:00
parent a7bb81553c
commit 966a6ce29e
Signed by: blacklight
GPG key ID: D90FBA7F76362774
12 changed files with 184 additions and 89 deletions

View file

@ -25,7 +25,7 @@ class DbPlugin(Plugin):
_db_error_wait_interval = 5.0 _db_error_wait_interval = 5.0
_db_error_retries = 3 _db_error_retries = 3
def __init__(self, engine=None, **kwargs): def __init__(self, engine=None, *args, **kwargs):
""" """
:param engine: Default SQLAlchemy connection engine string (e.g. :param engine: Default SQLAlchemy connection engine string (e.g.
``sqlite:///:memory:`` or ``mysql://user:pass@localhost/test``) ``sqlite:///:memory:`` or ``mysql://user:pass@localhost/test``)
@ -42,7 +42,7 @@ class DbPlugin(Plugin):
super().__init__() super().__init__()
self.engine_url = engine self.engine_url = engine
self.engine = self.get_engine(engine, **kwargs) self.engine = self.get_engine(engine, *args, **kwargs)
def get_engine( def get_engine(
self, engine: Optional[Union[str, Engine]] = None, *args, **kwargs self, engine: Optional[Union[str, Engine]] = None, *args, **kwargs

View file

@ -15,7 +15,8 @@ class FoursquarePlugin(Plugin):
- Copy the ``client_id`` and ``client_secret``. - 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 - 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/. 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``. - 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. 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 - Allow the application. You will be redirected to the URL you provided. Copy the ``access_token`` provided in
the URL. the URL.
@ -26,14 +27,16 @@ class FoursquarePlugin(Plugin):
def __init__(self, access_token: str, **kwargs): def __init__(self, access_token: str, **kwargs):
""" """
:param access_token: :param access_token: The access token to use to authenticate to the Foursquare API.
""" """
super().__init__(**kwargs) super().__init__(**kwargs)
self.access_token = access_token self.access_token = access_token
def _get_url(self, endpoint): def _get_url(self, endpoint):
return '{url}/{endpoint}?oauth_token={token}&v={version}'.format( return '{url}/{endpoint}?oauth_token={token}&v={version}'.format(
url=self.api_base_url, endpoint=endpoint, token=self.access_token, url=self.api_base_url,
endpoint=endpoint,
token=self.access_token,
version=datetime.date.today().strftime('%Y%m%d'), version=datetime.date.today().strftime('%Y%m%d'),
) )
@ -44,11 +47,18 @@ class FoursquarePlugin(Plugin):
:return: A list of checkins, as returned by the Foursquare API. :return: A list of checkins, as returned by the Foursquare API.
""" """
url = self._get_url('users/self/checkins') url = self._get_url('users/self/checkins')
return requests.get(url).json().get('response', {}).get('checkins', {}).get('items', []) return (
requests.get(url)
.json()
.get('response', {})
.get('checkins', {})
.get('items', [])
)
# noinspection DuplicatedCode # noinspection DuplicatedCode
@action @action
def search(self, def search(
self,
latitude: Optional[float] = None, latitude: Optional[float] = None,
longitude: Optional[float] = None, longitude: Optional[float] = None,
altitude: Optional[float] = None, altitude: Optional[float] = None,
@ -61,7 +71,8 @@ class FoursquarePlugin(Plugin):
categories: Optional[List[str]] = None, categories: Optional[List[str]] = None,
radius: Optional[int] = None, radius: Optional[int] = None,
sw: Optional[Union[Tuple[float], List[float]]] = None, sw: Optional[Union[Tuple[float], List[float]]] = None,
ne: Optional[Union[Tuple[float], List[float]]] = None,) -> List[Dict[str, Any]]: ne: Optional[Union[Tuple[float], List[float]]] = None,
) -> List[Dict[str, Any]]:
""" """
Search for venues. Search for venues.
@ -82,7 +93,9 @@ class FoursquarePlugin(Plugin):
:param ne: North/east boundary box as a ``[latitude, longitude]`` pair. :param ne: North/east boundary box as a ``[latitude, longitude]`` pair.
:return: A list of venues, as returned by the Foursquare API. :return: A list of venues, as returned by the Foursquare API.
""" """
assert (latitude and longitude) or near, 'Specify either latitude/longitude or near' assert (
latitude and longitude
) or near, 'Specify either latitude/longitude or near'
args = {} args = {}
if latitude and longitude: if latitude and longitude:
@ -111,11 +124,14 @@ class FoursquarePlugin(Plugin):
args['ne'] = ne args['ne'] = ne
url = self._get_url('venues/search') url = self._get_url('venues/search')
return requests.get(url, params=args).json().get('response', {}).get('venues', []) return (
requests.get(url, params=args).json().get('response', {}).get('venues', [])
)
# noinspection DuplicatedCode # noinspection DuplicatedCode
@action @action
def explore(self, def explore(
self,
latitude: Optional[float] = None, latitude: Optional[float] = None,
longitude: Optional[float] = None, longitude: Optional[float] = None,
altitude: Optional[float] = None, altitude: Optional[float] = None,
@ -131,7 +147,8 @@ class FoursquarePlugin(Plugin):
sort_by_distance: Optional[bool] = None, sort_by_distance: Optional[bool] = None,
sort_by_popularity: Optional[bool] = None, sort_by_popularity: Optional[bool] = None,
price: Optional[List[int]] = None, price: Optional[List[int]] = None,
saved: Optional[bool] = None) -> List[Dict[str, Any]]: saved: Optional[bool] = None,
) -> List[Dict[str, Any]]:
""" """
Explore venues around a location. Explore venues around a location.
@ -168,7 +185,9 @@ class FoursquarePlugin(Plugin):
:return: A list of venues, as returned by the Foursquare API. :return: A list of venues, as returned by the Foursquare API.
""" """
assert (latitude and longitude) or near, 'Specify either latitude/longitude or near' assert (
latitude and longitude
) or near, 'Specify either latitude/longitude or near'
args = {} args = {}
if latitude and longitude: if latitude and longitude:
@ -203,15 +222,19 @@ class FoursquarePlugin(Plugin):
args['price'] = ','.join([str(p) for p in price]) args['price'] = ','.join([str(p) for p in price])
url = self._get_url('venues/explore') url = self._get_url('venues/explore')
return requests.get(url, params=args).json().get('response', {}).get('venues', []) return (
requests.get(url, params=args).json().get('response', {}).get('venues', [])
)
@action @action
def trending(self, def trending(
self,
latitude: Optional[float] = None, latitude: Optional[float] = None,
longitude: Optional[float] = None, longitude: Optional[float] = None,
near: Optional[str] = None, near: Optional[str] = None,
limit: Optional[int] = None, limit: Optional[int] = None,
radius: Optional[int] = None) -> List[Dict[str, Any]]: radius: Optional[int] = None,
) -> List[Dict[str, Any]]:
""" """
Get the trending venues around a location. Get the trending venues around a location.
@ -224,7 +247,9 @@ class FoursquarePlugin(Plugin):
:return: A list of venues, as returned by the Foursquare API. :return: A list of venues, as returned by the Foursquare API.
""" """
assert (latitude and longitude) or near, 'Specify either latitude/longitude or near' assert (
latitude and longitude
) or near, 'Specify either latitude/longitude or near'
args = {} args = {}
if latitude and longitude: if latitude and longitude:
@ -237,24 +262,29 @@ class FoursquarePlugin(Plugin):
args['radius'] = radius args['radius'] = radius
url = self._get_url('venues/trending') url = self._get_url('venues/trending')
return requests.get(url, params=args).json().get('response', {}).get('venues', []) return (
requests.get(url, params=args).json().get('response', {}).get('venues', [])
)
@staticmethod @staticmethod
def _parse_time(t): def _parse_time(t):
if isinstance(t, int) or isinstance(t, float): if isinstance(t, (int, float)):
return datetime.datetime.fromtimestamp(t) return datetime.datetime.fromtimestamp(t)
if isinstance(t, str): if isinstance(t, str):
return datetime.datetime.fromisoformat(t) return datetime.datetime.fromisoformat(t)
assert isinstance(t, datetime.datetime), 'Cannot parse object of type {} into datetime: {}'.format( assert isinstance(
type(t), t) t, datetime.datetime
), 'Cannot parse object of type {} into datetime: {}'.format(type(t), t)
return t return t
@action @action
def time_series(self, def time_series(
self,
venue_id: Union[str, List[str]], venue_id: Union[str, List[str]],
start_at: Union[int, float, datetime.datetime, str], start_at: Union[int, float, datetime.datetime, str],
end_at: Union[int, float, datetime.datetime, str]) -> List[Dict[str, Any]]: end_at: Union[int, float, datetime.datetime, str],
) -> List[Dict[str, Any]]:
""" """
Get the visitors stats about one or multiple venues over a time range. The user must be a manager of Get the visitors stats about one or multiple venues over a time range. The user must be a manager of
those venues. those venues.
@ -275,13 +305,17 @@ class FoursquarePlugin(Plugin):
} }
url = self._get_url('venues/timeseries') url = self._get_url('venues/timeseries')
return requests.get(url, params=args).json().get('response', {}).get('venues', []) return (
requests.get(url, params=args).json().get('response', {}).get('venues', [])
)
@action @action
def stats(self, def stats(
self,
venue_id: str, venue_id: str,
start_at: Union[int, float, datetime.datetime, str], start_at: Union[int, float, datetime.datetime, str],
end_at: Union[int, float, datetime.datetime, str]) -> List[Dict[str, Any]]: end_at: Union[int, float, datetime.datetime, str],
) -> List[Dict[str, Any]]:
""" """
Get the stats about a venue over a time range. The user must be a manager of that venue. Get the stats about a venue over a time range. The user must be a manager of that venue.
@ -297,7 +331,9 @@ class FoursquarePlugin(Plugin):
} }
url = self._get_url('venues/{}/stats'.format(venue_id)) url = self._get_url('venues/{}/stats'.format(venue_id))
return requests.get(url, params=args).json().get('response', {}).get('venues', []) return (
requests.get(url, params=args).json().get('response', {}).get('venues', [])
)
@action @action
def managed(self) -> List[Dict[str, Any]]: def managed(self) -> List[Dict[str, Any]]:
@ -306,10 +342,17 @@ class FoursquarePlugin(Plugin):
:return: A list of venues, as returned by the Foursquare API. :return: A list of venues, as returned by the Foursquare API.
""" """
url = self._get_url('venues/managed') url = self._get_url('venues/managed')
return requests.get(url).json().get('response', {}).get('venues', []).get('items', []) return (
requests.get(url)
.json()
.get('response', {})
.get('venues', [])
.get('items', [])
)
@action @action
def checkin(self, def checkin(
self,
venue_id: str, venue_id: str,
latitude: Optional[float] = None, latitude: Optional[float] = None,
longitude: Optional[float] = None, longitude: Optional[float] = None,
@ -317,7 +360,8 @@ class FoursquarePlugin(Plugin):
latlng_accuracy: Optional[float] = None, latlng_accuracy: Optional[float] = None,
altitude_accuracy: Optional[float] = None, altitude_accuracy: Optional[float] = None,
shout: Optional[str] = None, shout: Optional[str] = None,
broadcast: Optional[List[str]] = None) -> Dict[str, Any]: broadcast: Optional[List[str]] = None,
) -> Dict[str, Any]:
""" """
Create a new check-in. Create a new check-in.
@ -350,10 +394,14 @@ class FoursquarePlugin(Plugin):
if shout: if shout:
args['shout'] = shout args['shout'] = shout
if broadcast: if broadcast:
args['broadcast'] = ','.join(broadcast) if isinstance(broadcast, list) else broadcast args['broadcast'] = (
','.join(broadcast) if isinstance(broadcast, list) else broadcast
)
url = self._get_url('checkins/add') url = self._get_url('checkins/add')
return requests.post(url, data=args).json().get('response', {}).get('checkin', {}) return (
requests.post(url, data=args).json().get('response', {}).get('checkin', {})
)
# vim:sw=4:ts=4:et: # vim:sw=4:ts=4:et:

View file

@ -5,20 +5,25 @@ manifest:
- py3-google-api-python-client - py3-google-api-python-client
- py3-google-auth - py3-google-auth
- py3-oauth2client - py3-oauth2client
- py3-httplib2
apt: apt:
- python3-google-auth - python3-google-auth
- python3-oauth2client - python3-oauth2client
- python3-httplib2
dnf: dnf:
- python-google-api-client - python-google-api-client
- python-google-auth - python-google-auth
- python-oauth2client - python-oauth2client
- python-httplib2
pacman: pacman:
- python-google-api-python-client - python-google-api-python-client
- python-google-auth - python-google-auth
- python-oauth2client - python-oauth2client
- python-httplib2
pip: pip:
- google-api-python-client - google-api-python-client
- google-auth - google-auth
- oauth2client - oauth2client
- httplib2
package: platypush.plugins.google.calendar package: platypush.plugins.google.calendar
type: plugin type: plugin

View file

@ -5,20 +5,25 @@ manifest:
- py3-google-api-python-client - py3-google-api-python-client
- py3-google-auth - py3-google-auth
- py3-oauth2client - py3-oauth2client
- py3-httplib2
apt: apt:
- python3-google-auth - python3-google-auth
- python3-oauth2client - python3-oauth2client
- python3-httplib2
dnf: dnf:
- python-google-api-client - python-google-api-client
- python-google-auth - python-google-auth
- python-oauth2client - python-oauth2client
- python-httplib2
pacman: pacman:
- python-google-api-python-client - python-google-api-python-client
- python-google-auth - python-google-auth
- python-oauth2client - python-oauth2client
- python-httplib2
pip: pip:
- google-api-python-client - google-api-python-client
- google-auth - google-auth
- oauth2client - oauth2client
- httplib2
package: platypush.plugins.google.drive package: platypush.plugins.google.drive
type: plugin type: plugin

View file

@ -5,20 +5,25 @@ manifest:
- py3-google-api-python-client - py3-google-api-python-client
- py3-google-auth - py3-google-auth
- py3-oauth2client - py3-oauth2client
- py3-httplib2
apt: apt:
- python3-google-auth - python3-google-auth
- python3-oauth2client - python3-oauth2client
- python3-httplib2
dnf: dnf:
- python-google-api-client - python-google-api-client
- python-google-auth - python-google-auth
- python-oauth2client - python-oauth2client
- python-httplib2
pacman: pacman:
- python-google-api-python-client - python-google-api-python-client
- python-google-auth - python-google-auth
- python-oauth2client - python-oauth2client
- python-httplib2
pip: pip:
- google-api-python-client - google-api-python-client
- google-auth - google-auth
- oauth2client - oauth2client
- httplib2
package: platypush.plugins.google.fit package: platypush.plugins.google.fit
type: plugin type: plugin

View file

@ -5,20 +5,25 @@ manifest:
- py3-google-api-python-client - py3-google-api-python-client
- py3-google-auth - py3-google-auth
- py3-oauth2client - py3-oauth2client
- py3-httplib2
apt: apt:
- python3-google-auth - python3-google-auth
- python3-oauth2client - python3-oauth2client
- python3-httplib2
dnf: dnf:
- python-google-api-client - python-google-api-client
- python-google-auth - python-google-auth
- python-oauth2client - python-oauth2client
- python-httplib2
pacman: pacman:
- python-google-api-python-client - python-google-api-python-client
- python-google-auth - python-google-auth
- python-oauth2client - python-oauth2client
- python-httplib2
pip: pip:
- google-api-python-client - google-api-python-client
- google-auth - google-auth
- oauth2client - oauth2client
- httplib2
package: platypush.plugins.google.mail package: platypush.plugins.google.mail
type: plugin type: plugin

View file

@ -5,20 +5,25 @@ manifest:
- py3-google-api-python-client - py3-google-api-python-client
- py3-google-auth - py3-google-auth
- py3-oauth2client - py3-oauth2client
- py3-httplib2
apt: apt:
- python3-google-auth - python3-google-auth
- python3-oauth2client - python3-oauth2client
- python3-httplib2
dnf: dnf:
- python-google-api-client - python-google-api-client
- python-google-auth - python-google-auth
- python-oauth2client - python-oauth2client
- python-httplib2
pacman: pacman:
- python-google-api-python-client - python-google-api-python-client
- python-google-auth - python-google-auth
- python-oauth2client - python-oauth2client
- python-httplib2
pip: pip:
- google-api-python-client - google-api-python-client
- google-auth - google-auth
- oauth2client - oauth2client
- httplib2
package: platypush.plugins.google.maps package: platypush.plugins.google.maps
type: plugin type: plugin

View file

@ -5,21 +5,26 @@ manifest:
- py3-google-api-python-client - py3-google-api-python-client
- py3-google-auth - py3-google-auth
- py3-oauth2client - py3-oauth2client
- py3-httplib2
apt: apt:
- python3-google-auth - python3-google-auth
- python3-oauth2client - python3-oauth2client
- python3-httplib2
dnf: dnf:
- python-google-api-client - python-google-api-client
- python-google-auth - python-google-auth
- python-oauth2client - python-oauth2client
- python-httplib2
pacman: pacman:
- python-google-api-python-client - python-google-api-python-client
- python-google-auth - python-google-auth
- python-oauth2client - python-oauth2client
- python-httplib2
pip: pip:
- google-api-python-client - google-api-python-client
- google-auth - google-auth
- oauth2client - oauth2client
- google-cloud-pubsub - google-cloud-pubsub
- httplib2
package: platypush.plugins.google.pubsub package: platypush.plugins.google.pubsub
type: plugin type: plugin

View file

@ -5,21 +5,26 @@ manifest:
- py3-google-api-python-client - py3-google-api-python-client
- py3-google-auth - py3-google-auth
- py3-oauth2client - py3-oauth2client
- py3-httplib2
apt: apt:
- python3-google-auth - python3-google-auth
- python3-oauth2client - python3-oauth2client
- python3-httplib2
dnf: dnf:
- python-google-api-client - python-google-api-client
- python-google-auth - python-google-auth
- python-oauth2client - python-oauth2client
- python-httplib2
pacman: pacman:
- python-google-api-python-client - python-google-api-python-client
- python-google-auth - python-google-auth
- python-oauth2client - python-oauth2client
- python-httplib2
pip: pip:
- google-api-python-client - google-api-python-client
- google-auth - google-auth
- oauth2client - oauth2client
- google-cloud-translate - google-cloud-translate
- httplib2
package: platypush.plugins.google.translate package: platypush.plugins.google.translate
type: plugin type: plugin

View file

@ -5,20 +5,25 @@ manifest:
- py3-google-api-python-client - py3-google-api-python-client
- py3-google-auth - py3-google-auth
- py3-oauth2client - py3-oauth2client
- py3-httplib2
apt: apt:
- python3-google-auth - python3-google-auth
- python3-oauth2client - python3-oauth2client
- python3-httplib2
dnf: dnf:
- python-google-api-client - python-google-api-client
- python-google-auth - python-google-auth
- python-oauth2client - python-oauth2client
- python-httplib2
pacman: pacman:
- python-google-api-python-client - python-google-api-python-client
- python-google-auth - python-google-auth
- python-oauth2client - python-oauth2client
- python-httplib2
pip: pip:
- google-api-python-client - google-api-python-client
- google-auth - google-auth
- oauth2client - oauth2client
- httplib2
package: platypush.plugins.google.youtube package: platypush.plugins.google.youtube
type: plugin type: plugin

View file

@ -134,7 +134,7 @@ class DocstringParser:
return None return None
lines = text.split("\n") lines = text.split("\n")
return (lines[0] + " " + tw.dedent("\n".join(lines[1:]) or "")).strip() return (lines[0] + "\n" + tw.dedent("\n".join(lines[1:]) or "")).strip()
ctx = ParseContext(obj) ctx = ParseContext(obj)
yield ctx yield ctx
@ -203,13 +203,14 @@ class DocstringParser:
return return
# Update the current parameter docstring if required # Update the current parameter docstring if required
if ( if ctx.state == ParseState.PARAM and cls._is_continuation_line(line):
ctx.state == ParseState.PARAM if ctx.cur_param in ctx.parsed_params:
and cls._is_continuation_line(line)
and ctx.cur_param in ctx.parsed_params
):
ctx.parsed_params[ctx.cur_param].doc = ( ctx.parsed_params[ctx.cur_param].doc = (
((ctx.parsed_params[ctx.cur_param].doc or "") + "\n" + line.rstrip()) (
(ctx.parsed_params[ctx.cur_param].doc or "")
+ "\n"
+ line.rstrip()
)
if ctx.parsed_params.get(ctx.cur_param) if ctx.parsed_params.get(ctx.cur_param)
and ctx.parsed_params[ctx.cur_param].doc and ctx.parsed_params[ctx.cur_param].doc
else "" else ""

View file

@ -110,6 +110,7 @@ setup(
# Support for Google text2speech plugin # Support for Google text2speech plugin
'google-tts': [ 'google-tts': [
'oauth2client', 'oauth2client',
'httplib2',
'google-api-python-client', 'google-api-python-client',
'google-auth', 'google-auth',
'google-cloud-texttospeech', 'google-cloud-texttospeech',
@ -130,7 +131,12 @@ setup(
'google-assistant-legacy': ['google-assistant-library', 'google-auth'], 'google-assistant-legacy': ['google-assistant-library', 'google-auth'],
'google-assistant': ['google-assistant-sdk[samples]', 'google-auth'], 'google-assistant': ['google-assistant-sdk[samples]', 'google-auth'],
# Support for the Google APIs # Support for the Google APIs
'google': ['oauth2client', 'google-auth', 'google-api-python-client'], 'google': [
'oauth2client',
'google-auth',
'google-api-python-client',
'httplib2',
],
# Support for Last.FM scrobbler plugin # Support for Last.FM scrobbler plugin
'lastfm': ['pylast'], 'lastfm': ['pylast'],
# Support for custom hotword detection # Support for custom hotword detection
@ -213,9 +219,9 @@ setup(
# Support for Trello integration # Support for Trello integration
'trello': ['py-trello'], 'trello': ['py-trello'],
# Support for Google Pub/Sub # Support for Google Pub/Sub
'google-pubsub': ['google-cloud-pubsub', 'google-auth'], 'google-pubsub': ['google-cloud-pubsub', 'google-auth', 'httplib2'],
# Support for Google Translate # Support for Google Translate
'google-translate': ['google-cloud-translate', 'google-auth'], 'google-translate': ['google-cloud-translate', 'google-auth', 'httplib2'],
# Support for keyboard/mouse plugin # Support for keyboard/mouse plugin
'inputs': ['pyuserinput'], 'inputs': ['pyuserinput'],
# Support for Buienradar weather forecast # Support for Buienradar weather forecast