-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsendTest.py
More file actions
127 lines (117 loc) · 4.21 KB
/
sendTest.py
File metadata and controls
127 lines (117 loc) · 4.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
import json, random
import datetime as dt
import alertProcessor as ap
config = {}
def load_config():
global config
with open("boiler.cfg", "r") as config_file:
config = json.load(config_file)
config_file.close()
def get_details():
alert_id = f"test-" + str(random.randint(1000,9999))
alert_type = None
alert_org = None
alert_minutes = None
alert_audio = None # Not developing this rn because i'm just gonna steal the AP's store_alert function, so any audio that gets passed will need an ATTN and EOMs... in other words, i don't feel like making a bypass
alert_audio_y = None
alert_text = None
alert_fips = []
exit_fips_entry_flag = False
print(f"Creating alert '{alert_id}'")
while not alert_type:
i = input("Event Code (DMO): ")
if not i:
alert_type = "DMO"
break
if len(i) > 3 or len(i) < 3:
print("Event code must only be 3 characters long.")
else:
alert_type = i
while not alert_org:
i = input("Originator (EAS): ")
if not i:
alert_org = "EAS"
break
if len(i) > 3 or len(i) < 3:
print("Originator must only be 3 characters long.")
else:
alert_org = i
while not alert_minutes:
i = input("Effective time in minutes (30): ")
if not i:
alert_minutes = 30
break
try:
i = int(i)
alert_minutes = i
except:
print(f"The value you gave was not an integer. Please try again.")
while not exit_fips_entry_flag:
i = input("FIPS Area (011001): ")
if not i and len(alert_fips) == 0:
alert_fips.append("011001")
exit_fips_entry_flag = True
break
elif not i and len(alert_fips) > 0:
exit_fips_entry_flag = True
break
if len(i) < 6 or len(i) > 6:
print("FIPS code must consist of 6 numerical characters.")
else:
alert_fips.append(i)
while not alert_text:
i = input("Alert Text: ")
if not i:
alert_text = "BoilerCAP Message. This is a test of the Boiler CAP feed emulator. This test is being performed to verify compatibility with all digital Emergency Alert System platforms. If you are hearing this message, the station you are listening to is part of a network equipped with Boiler CAP. No action is required. Message is from: CCTL."
break
else:
alert_text = i
while alert_audio_y == None:
i = input("Use Audio from URL? (Y/N): ")
i = i.lower()
if not i:
alert_audio_y = False
break
elif i == "yes" or i == "y":
alert_audio_y = True
break
else:
alert_audio_y = False
break
print(alert_audio_y)
if alert_audio_y == True:
while alert_audio == None:
i = input(f"Alert Audio URL: ")
if not i:
print("Audio aborted.")
alert_audio_y = False
alert_audio = None
break
else:
alert_audio = i # i dont care to verify it's an actual url
break
alert_sent_time = dt.datetime.now(tz=dt.timezone.utc)
alert_end_time = dt.datetime.now(tz=dt.timezone.utc) + dt.timedelta(minutes=alert_minutes)
alert_sent_time_iso = alert_sent_time.isoformat(timespec='seconds').replace("+00:00", "")
alert_end_time_iso = alert_end_time.isoformat(timespec='seconds').replace("+00:00", "")
alert_sent_time_epoch = alert_sent_time.timestamp()
alert_end_time_epoch = alert_end_time.timestamp()
entry = {
"id": alert_id,
"hash": alert_id,
"type": alert_type,
"originator": alert_org,
"fipsCodes": alert_fips,
"startTimeEpoch": alert_sent_time_epoch,
"startTime": alert_sent_time_iso,
"endTimeEpoch": alert_end_time_epoch,
"endTime": alert_end_time_iso,
"audioUrl": alert_audio,
"translation": alert_text
}
print(entry)
return entry
if __name__ == "__main__":
load_config()
details = get_details()
ap.store_alert(details, config)