Skip to content

Commit

Permalink
Merge pull request #12 from aserper/listen_to_all_alert_types
Browse files Browse the repository at this point in the history
Support all alert types
  • Loading branch information
aserper committed Jun 8, 2024
2 parents 7c9a94e + cfe5a1d commit 9f3f152
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 7 deletions.
2 changes: 1 addition & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def main():
print("Event is None.")
else:
print("Processing event...")
messageManager.postMessage(alerts)
messageManager.postMessage(eventData)
print("Event processed completed successfully.")

except KeyboardInterrupt:
Expand Down
14 changes: 12 additions & 2 deletions message_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,22 @@ class AlertMessageBuilder:
# Main entry point to build alert messages.
# Returns a message string comprised of a rocket alert header
# and alert location list
def buildAlerts(self, alerts):
def buildAlerts(self, eventData):
alerts = eventData["alerts"]

if not isinstance(alerts, (list)):
alerts = [alerts]

alertList = self.__buildAlertList(alerts)
header = f"Rocket alert {alerts[0]['timeStamp']}:"

alertTypeId = eventData["alertTypeId"]
if (alertTypeId == 1):
header = "Rocket alert"
elif (alertTypeId == 2):
header = "Hostile UAV alert"
else:
header = "Red alert"
header += f" {alerts[0]['timeStamp']}:"
return f"{header}\n\n" \
f"{alertList}\n\n"

Expand Down
6 changes: 3 additions & 3 deletions message_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,13 @@ def buildMarker(self, alert):
lon = str(alert["lon"])
return f"pin-s+{self.strokeColor}({lon},{lat})"

def postMessage(self, alerts):
def postMessage(self, eventData):
print("Building alert message...")
content = AlertMessageBuilder().buildAlerts(alerts)
content = AlertMessageBuilder().buildAlerts(eventData)
print(content)

print("Generating static map...")
hasMap = self.buildStaticMap(alerts)
hasMap = self.buildStaticMap(eventData["alerts"])
file = self.mapFile if hasMap else None

print("Sending message...")
Expand Down
2 changes: 1 addition & 1 deletion rocket_alert_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ def __init__(self):
# print("Please note the function only takes dates in string format (YYYY-MM-DD).")

def listenToServerEvents(self):
return requests.get(f"{self.baseURL}/real-time", headers=self.headers, stream=True)
return requests.get(f"{self.baseURL}/real-time?alertTypeId=-1", headers=self.headers, stream=True)

0 comments on commit 9f3f152

Please sign in to comment.