""" Note: Please do absolute imports, it allows me to clean up shit we don't use, and doesn't import extra code. It should be more efficient anyways. """ # Standard Library from datetime import datetime as DT from email.mime.multipart import MIMEMultipart from email.mime.text import MIMEText from enum import Enum from io import BytesIO from json import dump, loads from os import system from platform import system as osType from smtplib import SMTP from threading import Lock from time import localtime, timezone # Third-Party from discord_webhook import DiscordEmbed, DiscordWebhook from EAS2Text.EAS2Text import EAS2Text class severity(Enum): ## 6 trace = [6, "TRACELOG > {}"] # For extra data text (Ex. Startup) ## 5 playoutStats = [ 5, "PLAYLOG > {}", ] # For playout stats (Now Playing, Header/Tone/EOM logs) ## 4 debug = [4, "{}"] # For extra data text (Ex. Startup) debugWarn = [ 4, "WARNING > *** {} ***", ] # For notice text in DBG mode only (Ex. Monitor Down) debugErr = [ 4, "ERROR > *** {} ***", ] # For extra data text in DBG mode only (Ex. Startup) ## 3 info = [3, "{}"] # For common text (Ex. Mon start/stop) ## 2 alert = [2, "{}"] # For alert recv messages ## 1 warning = [1, "WARNING > *** {} ***"] # For notice text (Ex. Monitor Down) ## 0 error = [ 0, "ERROR > *** {} ***", ] # For critical error text (Ex. Program Error) fatal = [ 0, "FATAL > *** {} ***", ] # For fatal error text (Ex. Program crash) boot = [0, ""] ## Boot and info scripts ## -1 menu = [-1, "{}"] # For menus class utilities: __printLock__ = Lock() __emailLock__ = Lock() __verbosity__ = 0 __defConfig__ = loads( """{ "Monitors": [], "Callsign": "ASMARA/1", "Emulation": "", "Logger": { "Email": { "Enabled": false, "Server": "eas@server.com", "Port": 587, "Username": "user", "Password": "hackme", "To": [ "user.name@server.com" ] }, "Enabled": false, "Audio": false, "Webhooks": [] }, "LocalFIPS": [ "055079" ], "PlayoutManager": { "Channels": 2, "SampleRate": 44100, "Icecast":{ "Enabled": false, "WaitingStatus": "WACN Radio - No Audio", "Address": "127.0.0.1", "Port": "8000", "Source": "source", "Pass": "None", "Mountpoint": "Test", "Bitrate": "128k" }, "Audio": false, "Export": { "Enabled": false, "Folder": "OldAlerts" }, "Override": { "Enabled": false, "Folder": "Override" }, "AutoDJ": { "Enabled": true, "Folder": "PlayoutAudio", "IDFolder": "IDAudio", "IDSongs": 4, "Tone": true }, "LeadIn": { "Enabled": false, "File": "", "Type": "" }, "LeadOut": { "Enabled": false, "File": "", "Type": "" } }, "Filters": [ { "Name": "Local Alerts", "Originators": [ "*" ], "EventCodes": [ "*" ], "SameCodes": [ "LOCAL" ], "CallSigns": [ "*" ], "Action": "Live:Now" }, { "Name": "Tests", "Originators": [ "*" ], "EventCodes": [ "RWT", "DMO" ], "SameCodes": [ "*" ], "CallSigns": [ "*" ], "Action": "Ignore:Now" }, { "Name": "Catch All", "Originators": [ "*" ], "EventCodes": [ "*" ], "SameCodes": [ "*" ], "CallSigns": [ "*" ], "Action": "Relay:Now" } ], "LogFile": ".log" }""" ) __stats__ = loads( """{ "EVENTS": { "ADR": "http://acrn.gwes-eas.network/Icons/index.php?img=chat&hex=", "AVA": "http://acrn.gwes-eas.network/Icons/index.php?img=avalanche&hex=", "AVW": "http://acrn.gwes-eas.network/Icons/index.php?img=avalanche&hex=", "BHW": "http://acrn.gwes-eas.network/Icons/index.php?img=biohazard&hex=", "BLU": "http://acrn.gwes-eas.network/Icons/index.php?img=policeman&hex=", "BWW": "http://acrn.gwes-eas.network/Icons/index.php?img=water-heating&hex=", "BZW": "http://acrn.gwes-eas.network/Icons/index.php?img=snow&hex=", "CAE": "http://acrn.gwes-eas.network/Icons/index.php?img=child-with-pacifier&hex=", "CDW": "http://acrn.gwes-eas.network/Icons/index.php?img=break&hex=", "CEM": "http://acrn.gwes-eas.network/Icons/index.php?img=break&hex=", "CFA": "http://acrn.gwes-eas.network/Icons/index.php?img=beach&hex=", "CFW": "http://acrn.gwes-eas.network/Icons/index.php?img=beach&hex=", "CHW": "http://acrn.gwes-eas.network/Icons/index.php?img=biohazard&hex=", "CWW": "http://acrn.gwes-eas.network/Icons/index.php?img=biohazard&hex=", "DBA": "http://acrn.gwes-eas.network/Icons/index.php?img=dam&hex=", "DBW": "http://acrn.gwes-eas.network/Icons/index.php?img=dam&hex=", "DEW": "http://acrn.gwes-eas.network/Icons/index.php?img=biohazard&hex=", "DMO": "http://acrn.gwes-eas.network/Icons/index.php?img=test-tube&hex=", "DSW": "http://acrn.gwes-eas.network/Icons/index.php?img=wind&hex=", "EAN": "http://acrn.gwes-eas.network/Icons/index.php?img=mushroom-cloud&hex=", "EAT": "http://acrn.gwes-eas.network/Icons/index.php?img=mushroom-cloud&hex=", "EQW": "http://acrn.gwes-eas.network/Icons/index.php?img=earthquakes&hex=", "EVA": "http://acrn.gwes-eas.network/Icons/index.php?img=escape&hex=", "EVI": "http://acrn.gwes-eas.network/Icons/index.php?img=escape&hex=", "EWW": "http://acrn.gwes-eas.network/Icons/index.php?img=wind&hex=", "FCW": "http://acrn.gwes-eas.network/Icons/index.php?img=biohazard&hex=", "FFS": "http://acrn.gwes-eas.network/Icons/index.php?img=floods&hex=", "FFA": "http://acrn.gwes-eas.network/Icons/index.php?img=floods&hex=", "FFW": "http://acrn.gwes-eas.network/Icons/index.php?img=floods&hex=", "FLS": "http://acrn.gwes-eas.network/Icons/index.php?img=sea-waves&hex=", "FLA": "http://acrn.gwes-eas.network/Icons/index.php?img=sea-waves&hex=", "FLW": "http://acrn.gwes-eas.network/Icons/index.php?img=sea-waves&hex=", "FRW": "http://acrn.gwes-eas.network/Icons/index.php?img=fire&hex=", "FSW": "http://acrn.gwes-eas.network/Icons/index.php?img=snowflake&hex=", "FZW": "http://acrn.gwes-eas.network/Icons/index.php?img=snowflake&hex=", "HMW": "http://acrn.gwes-eas.network/Icons/index.php?img=biohazard&hex=", "HUS": "http://acrn.gwes-eas.network/Icons/index.php?img=hurricane&hex=", "HUA": "http://acrn.gwes-eas.network/Icons/index.php?img=hurricane&hex=", "HUW": "http://acrn.gwes-eas.network/Icons/index.php?img=hurricane&hex=", "HWA": "http://acrn.gwes-eas.network/Icons/index.php?img=wind&hex=", "HWW": "http://acrn.gwes-eas.network/Icons/index.php?img=wind&hex=", "IBW": "http://acrn.gwes-eas.network/Icons/index.php?img=snowflake&hex=", "IFW": "http://acrn.gwes-eas.network/Icons/index.php?img=fire&hex=", "LAE": "http://acrn.gwes-eas.network/Icons/index.php?img=break&hex=", "LEW": "http://acrn.gwes-eas.network/Icons/index.php?img=policeman&hex=", "LSW": "http://acrn.gwes-eas.network/Icons/index.php?img=avalanche&hex=", "NAT": "http://acrn.gwes-eas.network/Icons/index.php?img=speaker&hex=", "NIC": "http://acrn.gwes-eas.network/Icons/index.php?img=chat&hex=", "NMN": "http://acrn.gwes-eas.network/Icons/index.php?img=chat&hex=", "NPT": "http://acrn.gwes-eas.network/Icons/index.php?img=test-tube&hex=", "NST": "http://acrn.gwes-eas.network/Icons/index.php?img=quiet&hex=", "NUW": "http://acrn.gwes-eas.network/Icons/index.php?img=radio-active&hex=", "POS": "http://acrn.gwes-eas.network/Icons/index.php?img=electrical&hex=", "RHW": "http://acrn.gwes-eas.network/Icons/index.php?img=radio-active&hex=", "RMT": "http://acrn.gwes-eas.network/Icons/index.php?img=important-month&hex=", "RWT": "http://acrn.gwes-eas.network/Icons/index.php?img=important-week&hex=", "SCS": "http://acrn.gwes-eas.network/Icons/index.php?img=school&hex=", "SMW": "http://acrn.gwes-eas.network/Icons/index.php?img=beach&hex=", "SPS": "http://acrn.gwes-eas.network/Icons/index.php?img=rain&hex=", "SPW": "http://acrn.gwes-eas.network/Icons/index.php?img=cottage&hex=", "SQW": "http://acrn.gwes-eas.network/Icons/index.php?img=snow&hex=", "SSA": "http://acrn.gwes-eas.network/Icons/index.php?img=beach&hex=", "SSW": "http://acrn.gwes-eas.network/Icons/index.php?img=beach&hex=", "SVA": "http://acrn.gwes-eas.network/Icons/index.php?img=cloudshot&hex=", "SVR": "http://acrn.gwes-eas.network/Icons/index.php?img=cloudshot&hex=", "SVS": "http://acrn.gwes-eas.network/Icons/index.php?img=rain&hex=", "TOA": "http://acrn.gwes-eas.network/Icons/index.php?img=tornado&hex=", "TOR": "http://acrn.gwes-eas.network/Icons/index.php?img=tornado&hex=", "TOE": "http://acrn.gwes-eas.network/Icons/index.php?img=call&hex=", "TRA": "http://acrn.gwes-eas.network/Icons/index.php?img=beach&hex=", "TRW": "http://acrn.gwes-eas.network/Icons/index.php?img=beach&hex=", "TSA": "http://acrn.gwes-eas.network/Icons/index.php?img=tsunami&hex=", "TSW": "http://acrn.gwes-eas.network/Icons/index.php?img=tsunami&hex=", "TXB": "http://acrn.gwes-eas.network/Icons/index.php?img=internet-antenna&hex=", "TXF": "http://acrn.gwes-eas.network/Icons/index.php?img=internet-antenna&hex=", "TXO": "http://acrn.gwes-eas.network/Icons/index.php?img=internet-antenna&hex=", "TXP": "http://acrn.gwes-eas.network/Icons/index.php?img=internet-antenna&hex=", "VOA": "http://acrn.gwes-eas.network/Icons/index.php?img=volcano&hex=", "VOW": "http://acrn.gwes-eas.network/Icons/index.php?img=volcano&hex=", "WFA": "http://acrn.gwes-eas.network/Icons/index.php?img=fire&hex=", "WFW": "http://acrn.gwes-eas.network/Icons/index.php?img=fire&hex=", "WSA": "http://acrn.gwes-eas.network/Icons/index.php?img=snow&hex=", "WSW": "http://acrn.gwes-eas.network/Icons/index.php?img=snow&hex=" } } """ ) # Class variable __unk__ = 0x797979 __adv__ = 0xFFCC00 __wat__ = 0xFF6600 __war__ = 0xFF0000 @classmethod def cls(cls): if osType() == "Windows": system("cls") else: system("clear") @classmethod def getOS(cls): return osType() @classmethod def setVerbosity(cls, __verbosity__: int = 0): cls.__verbosity__ = __verbosity__ @classmethod def autoPrint( cls, text: str, classType: str = "MAIN", sev: Enum = severity.info, end: str = "\n", ): if sev == severity.boot or sev == severity.menu: if sev.value[0] <= cls.__verbosity__: with cls.__printLock__: for line in text.split("\n"): print(f"{line}", end=end) else: if sev.value[0] <= cls.__verbosity__: now = f"[{DT.now().strftime('%H:%M:%S')}{cls.__getTZ__()[0]}]" with cls.__printLock__: for line in text.split("\n"): print( f"{now} > [{classType}] {sev.value[1].format(line)}", end=end, ) @classmethod def writeDefConfig(cls, config): with open(config, "w") as f: dump(cls.__defConfig__, f, indent=4) with open(".log", "w") as f: f.write('{"ASMARA/1": {"Alerts":{}, "Weekly":{"Timestamp": 0}}}') @classmethod def __getTZ__(cls): tzone = str(timezone / 3600.0) locTime = localtime().tm_isdst TMZ = "UTC" if tzone == "4.0": TMZ = "AST" if locTime > 0 == True: TMZ = "ADT" elif tzone == "5.0": TMZ = "EST" if locTime > 0 == True: TMZ = "EDT" elif tzone == "6.0": TMZ = "CST" if locTime > 0 == True: TMZ = "CDT" elif tzone == "7.0": TMZ = "MST" if locTime > 0 == True: TMZ = "MDT" elif tzone == "8.0": TMZ = "PST" if locTime > 0 == True: TMZ = "PDT" return TMZ @classmethod def __genEmailSig__(cls, call, version): return f"""
| ||||
P Save a tree. Don't print this e-mail unless it's necessary. |
{mon if mon != "" else ""}{filt if filt != "" else ""}
EAS Text Translation: {EASData.EASText}
EAS Protocol Data: {header}