From 99fee9ce207c11d3a6773de7149346a288ad472a Mon Sep 17 00:00:00 2001 From: Fabio Manganiello Date: Mon, 4 May 2020 13:15:14 +0000 Subject: [PATCH] Parse countries from the official country list --- platypush/plugins/covid19.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/platypush/plugins/covid19.py b/platypush/plugins/covid19.py index 00878a0b..8689b521 100644 --- a/platypush/plugins/covid19.py +++ b/platypush/plugins/covid19.py @@ -21,14 +21,19 @@ class Covid19Plugin(Plugin): - ``all``: Get all the available stats. """ super().__init__(**kwargs) - self.country = country + self.country = [] + self.all_countries = requests.get('{}/countries'.format(self.base_url)).json() self.country = self._get_countries(country) def _get_countries(self, country: Optional[Union[str, List[str]]] = None) -> List[str]: country = country or self.country if isinstance(country, str): country = country.split(',') - return [c.upper().strip() for c in country] + lc_country = {c.lower() for c in country} + return [c['ISO2'] for c in self.all_countries + if c['ISO2'].lower() in lc_country + or c['Slug'].lower() in lc_country + or c['Country'].lower() in lc_country] @action def summary(self, country: Optional[Union[str, List[str]]] = None) -> List[Dict[str, Any]]: