Skip to content

Commit

Permalink
Migrated to Black (#10)
Browse files Browse the repository at this point in the history
* black configuration

* black formatted
  • Loading branch information
exxamalte committed Jun 7, 2021
1 parent ef4b190 commit e26f291
Show file tree
Hide file tree
Showing 8 changed files with 196 additions and 155 deletions.
6 changes: 6 additions & 0 deletions .pre-commit-config.yaml
@@ -0,0 +1,6 @@
repos:
- repo: https://github.com/psf/black
rev: 20.8b1
hooks:
- id: black
language_version: python3
34 changes: 17 additions & 17 deletions aio_georss_gdacs/consts.py
Expand Up @@ -5,30 +5,30 @@
XML_ATTRIBUTE_VALUE = "@value"
XML_TEXT = "#text"

XML_TAG_DC_SUBJECT = 'dc:subject'
XML_TAG_GDACS_ALERT_LEVEL = 'gdacs:alertlevel'
XML_TAG_GDACS_COUNTRY = 'gdacs:country'
XML_TAG_GDACS_DURATION_IN_WEEK = 'gdacs:durationinweek'
XML_TAG_GDACS_EVENT_ID = 'gdacs:eventid'
XML_TAG_GDACS_EVENT_NAME = 'gdacs:eventname'
XML_TAG_GDACS_EVENT_TYPE = 'gdacs:eventtype'
XML_TAG_GDACS_FROM_DATE = 'gdacs:fromdate'
XML_TAG_GDACS_ICON = 'gdacs:icon'
XML_TAG_GDACS_IS_CURRENT = 'gdacs:iscurrent'
XML_TAG_GDACS_POPULATION = 'gdacs:population'
XML_TAG_GDACS_SEVERITY = 'gdacs:severity'
XML_TAG_GDACS_TEMPORARY = 'gdacs:temporary'
XML_TAG_GDACS_TO_DATE = 'gdacs:todate'
XML_TAG_GDACS_VERSION = 'gdacs:version'
XML_TAG_GDACS_VULNERABILITY = 'gdacs:vulnerability'
XML_TAG_DC_SUBJECT = "dc:subject"
XML_TAG_GDACS_ALERT_LEVEL = "gdacs:alertlevel"
XML_TAG_GDACS_COUNTRY = "gdacs:country"
XML_TAG_GDACS_DURATION_IN_WEEK = "gdacs:durationinweek"
XML_TAG_GDACS_EVENT_ID = "gdacs:eventid"
XML_TAG_GDACS_EVENT_NAME = "gdacs:eventname"
XML_TAG_GDACS_EVENT_TYPE = "gdacs:eventtype"
XML_TAG_GDACS_FROM_DATE = "gdacs:fromdate"
XML_TAG_GDACS_ICON = "gdacs:icon"
XML_TAG_GDACS_IS_CURRENT = "gdacs:iscurrent"
XML_TAG_GDACS_POPULATION = "gdacs:population"
XML_TAG_GDACS_SEVERITY = "gdacs:severity"
XML_TAG_GDACS_TEMPORARY = "gdacs:temporary"
XML_TAG_GDACS_TO_DATE = "gdacs:todate"
XML_TAG_GDACS_VERSION = "gdacs:version"
XML_TAG_GDACS_VULNERABILITY = "gdacs:vulnerability"

EVENT_TYPE_MAP = {
"DR": "Drought",
"EQ": "Earthquake",
"FL": "Flood",
"TC": "Tropical Cyclone",
"TS": "Tsunami",
"VO": "Volcano"
"VO": "Volcano",
}

URL = "https://www.gdacs.org/xml/rss.xml"
34 changes: 20 additions & 14 deletions aio_georss_gdacs/feed.py
Expand Up @@ -15,21 +15,27 @@
class GdacsFeed(GeoRssFeed[GdacsFeedEntry]):
"""GDACS feed."""

def __init__(self,
websession: ClientSession,
home_coordinates: Tuple[float, float],
filter_radius: float = None,
filter_categories: List[str] = None):
def __init__(
self,
websession: ClientSession,
home_coordinates: Tuple[float, float],
filter_radius: float = None,
filter_categories: List[str] = None,
):
"""Initialise this service."""
super().__init__(websession,
home_coordinates,
URL,
filter_radius=filter_radius,
filter_categories=filter_categories)
super().__init__(
websession,
home_coordinates,
URL,
filter_radius=filter_radius,
filter_categories=filter_categories,
)

def _new_entry(self,
home_coordinates: Tuple[float, float],
feature: FeedItem,
global_data: Dict) -> GdacsFeedEntry:
def _new_entry(
self,
home_coordinates: Tuple[float, float],
feature: FeedItem,
global_data: Dict,
) -> GdacsFeedEntry:
"""Generate a new entry."""
return GdacsFeedEntry(home_coordinates, feature)
79 changes: 43 additions & 36 deletions aio_georss_gdacs/feed_entry.py
Expand Up @@ -8,23 +8,33 @@
from aio_georss_client.xml_parser.feed_item import FeedItem
from aio_georss_client.xml_parser.geometry import Geometry, Polygon, Point

from .consts import (ATTRIBUTION, EVENT_TYPE_MAP, XML_ATTRIBUTE_VALUE,
XML_TAG_GDACS_ALERT_LEVEL, XML_TAG_GDACS_COUNTRY,
XML_TAG_GDACS_DURATION_IN_WEEK, XML_TAG_GDACS_EVENT_NAME,
XML_TAG_GDACS_EVENT_TYPE, XML_TAG_GDACS_FROM_DATE,
XML_TAG_GDACS_ICON, XML_TAG_GDACS_IS_CURRENT,
XML_TAG_GDACS_POPULATION, XML_TAG_GDACS_SEVERITY,
XML_TAG_GDACS_TEMPORARY, XML_TAG_GDACS_TO_DATE,
XML_TAG_GDACS_VERSION, XML_TAG_GDACS_VULNERABILITY,
XML_TEXT, XML_TAG_GDACS_EVENT_ID)
from .consts import (
ATTRIBUTION,
EVENT_TYPE_MAP,
XML_ATTRIBUTE_VALUE,
XML_TAG_GDACS_ALERT_LEVEL,
XML_TAG_GDACS_COUNTRY,
XML_TAG_GDACS_DURATION_IN_WEEK,
XML_TAG_GDACS_EVENT_NAME,
XML_TAG_GDACS_EVENT_TYPE,
XML_TAG_GDACS_FROM_DATE,
XML_TAG_GDACS_ICON,
XML_TAG_GDACS_IS_CURRENT,
XML_TAG_GDACS_POPULATION,
XML_TAG_GDACS_SEVERITY,
XML_TAG_GDACS_TEMPORARY,
XML_TAG_GDACS_TO_DATE,
XML_TAG_GDACS_VERSION,
XML_TAG_GDACS_VULNERABILITY,
XML_TEXT,
XML_TAG_GDACS_EVENT_ID,
)


class GdacsFeedEntry(FeedEntry):
"""GDACS feed entry."""

def __init__(self,
home_coordinates: Tuple[float, float],
feature: FeedItem):
def __init__(self, home_coordinates: Tuple[float, float], feature: FeedItem):
"""Initialise this service."""
super().__init__(home_coordinates, feature)

Expand All @@ -47,16 +57,14 @@ def category(self) -> Optional[str]:
def alert_level(self) -> Optional[str]:
"""Return the alert level of this entry."""
if self._rss_entry:
return self._rss_entry.get_additional_attribute(
XML_TAG_GDACS_ALERT_LEVEL)
return self._rss_entry.get_additional_attribute(XML_TAG_GDACS_ALERT_LEVEL)
return None

@property
def country(self) -> Optional[str]:
"""Return the country of this entry."""
if self._rss_entry:
return self._rss_entry.get_additional_attribute(
XML_TAG_GDACS_COUNTRY)
return self._rss_entry.get_additional_attribute(XML_TAG_GDACS_COUNTRY)
return None

@property
Expand All @@ -67,7 +75,8 @@ def duration_in_week(self) -> Optional[int]:
# 1 = Second week
# etc.
duration_in_week = self._rss_entry.get_additional_attribute(
XML_TAG_GDACS_DURATION_IN_WEEK)
XML_TAG_GDACS_DURATION_IN_WEEK
)
if duration_in_week:
return int(duration_in_week)
return None
Expand All @@ -76,8 +85,7 @@ def duration_in_week(self) -> Optional[int]:
def event_id(self) -> Optional[int]:
"""Return the event id of this entry."""
if self._rss_entry:
event_id = self._rss_entry.get_additional_attribute(
XML_TAG_GDACS_EVENT_ID)
event_id = self._rss_entry.get_additional_attribute(XML_TAG_GDACS_EVENT_ID)
if event_id:
return int(event_id)
return None
Expand All @@ -86,16 +94,14 @@ def event_id(self) -> Optional[int]:
def event_name(self) -> Optional[str]:
"""Return the event name of this entry."""
if self._rss_entry:
return self._rss_entry.get_additional_attribute(
XML_TAG_GDACS_EVENT_NAME)
return self._rss_entry.get_additional_attribute(XML_TAG_GDACS_EVENT_NAME)
return None

@property
def event_type_short(self) -> Optional[str]:
"""Return the short event type of this entry."""
if self._rss_entry:
return self._rss_entry.get_additional_attribute(
XML_TAG_GDACS_EVENT_TYPE)
return self._rss_entry.get_additional_attribute(XML_TAG_GDACS_EVENT_TYPE)
return None

@property
Expand All @@ -111,7 +117,8 @@ def from_date(self) -> Optional[datetime]:
"""Return the from date of this entry."""
if self._rss_entry:
from_date = self._rss_entry.get_additional_attribute(
XML_TAG_GDACS_FROM_DATE)
XML_TAG_GDACS_FROM_DATE
)
if from_date:
return dateparser.parse(from_date)
return None
Expand All @@ -120,16 +127,16 @@ def from_date(self) -> Optional[datetime]:
def icon_url(self) -> Optional[str]:
"""Return the icon url of this entry."""
if self._rss_entry:
return self._rss_entry.get_additional_attribute(
XML_TAG_GDACS_ICON)
return self._rss_entry.get_additional_attribute(XML_TAG_GDACS_ICON)
return None

@property
def is_current(self) -> Optional[bool]:
"""Return if this entry is current."""
if self._rss_entry:
is_current = self._rss_entry.get_additional_attribute(
XML_TAG_GDACS_IS_CURRENT)
XML_TAG_GDACS_IS_CURRENT
)
if is_current:
return FeedEntry._string2boolean(is_current)
return None
Expand All @@ -139,7 +146,8 @@ def population(self) -> Optional[str]:
"""Return the population of this entry."""
if self._rss_entry:
population = self._rss_entry.get_additional_attribute(
XML_TAG_GDACS_POPULATION)
XML_TAG_GDACS_POPULATION
)
if population:
if isinstance(population, Mapping):
if XML_TEXT in population:
Expand All @@ -152,8 +160,7 @@ def population(self) -> Optional[str]:
def severity(self) -> Optional[str]:
"""Return the severity of this entry."""
if self._rss_entry:
severity = self._rss_entry.get_additional_attribute(
XML_TAG_GDACS_SEVERITY)
severity = self._rss_entry.get_additional_attribute(XML_TAG_GDACS_SEVERITY)
if severity:
if isinstance(severity, Mapping):
if XML_TEXT in severity:
Expand All @@ -167,7 +174,8 @@ def temporary(self) -> Optional[bool]:
"""Return if this entry is temporary."""
if self._rss_entry:
temporary = self._rss_entry.get_additional_attribute(
XML_TAG_GDACS_TEMPORARY)
XML_TAG_GDACS_TEMPORARY
)
if temporary:
return FeedEntry._string2boolean(temporary)
return None
Expand All @@ -176,8 +184,7 @@ def temporary(self) -> Optional[bool]:
def to_date(self) -> Optional[datetime]:
"""Return the to date of this entry."""
if self._rss_entry:
to_date = self._rss_entry.get_additional_attribute(
XML_TAG_GDACS_TO_DATE)
to_date = self._rss_entry.get_additional_attribute(XML_TAG_GDACS_TO_DATE)
if to_date:
return dateparser.parse(to_date)
return None
Expand All @@ -186,8 +193,7 @@ def to_date(self) -> Optional[datetime]:
def version(self) -> Optional[int]:
"""Return the version of this entry."""
if self._rss_entry:
version = self._rss_entry.get_additional_attribute(
XML_TAG_GDACS_VERSION)
version = self._rss_entry.get_additional_attribute(XML_TAG_GDACS_VERSION)
if version:
return int(version)
return None
Expand All @@ -197,7 +203,8 @@ def vulnerability(self) -> Optional[Union[str, float]]:
"""Return the vulnerability of this entry."""
if self._rss_entry:
vulnerability = self._rss_entry.get_additional_attribute(
XML_TAG_GDACS_VULNERABILITY)
XML_TAG_GDACS_VULNERABILITY
)
if vulnerability:
if isinstance(vulnerability, Mapping):
# 1. See if there is a textual value.
Expand Down
36 changes: 20 additions & 16 deletions aio_georss_gdacs/feed_manager.py
Expand Up @@ -11,24 +11,28 @@
class GdacsFeedManager(FeedManagerBase):
"""Feed Manager for GDACS feed."""

def __init__(self,
websession: ClientSession,
generate_async_callback: Callable[[str], Awaitable[None]],
update_async_callback: Callable[[str], Awaitable[None]],
remove_async_callback: Callable[[str], Awaitable[None]],
coordinates,
filter_radius: float = None,
filter_categories: List[str] = None,
status_async_callback: Callable[[StatusUpdate],
Awaitable[None]] = None):
def __init__(
self,
websession: ClientSession,
generate_async_callback: Callable[[str], Awaitable[None]],
update_async_callback: Callable[[str], Awaitable[None]],
remove_async_callback: Callable[[str], Awaitable[None]],
coordinates,
filter_radius: float = None,
filter_categories: List[str] = None,
status_async_callback: Callable[[StatusUpdate], Awaitable[None]] = None,
):
"""Initialize the GDACS Feed Manager."""
feed = GdacsFeed(
websession,
coordinates,
filter_radius=filter_radius,
filter_categories=filter_categories)
super().__init__(feed,
generate_async_callback,
update_async_callback,
remove_async_callback,
status_async_callback)
filter_categories=filter_categories,
)
super().__init__(
feed,
generate_async_callback,
update_async_callback,
remove_async_callback,
status_async_callback,
)

0 comments on commit e26f291

Please sign in to comment.