-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy paththreatenator.py
54 lines (44 loc) · 1.1 KB
/
threatenator.py
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
#!/usr/bin/env python3
import json
import requests
from bs4 import BeautifulSoup
from urllib.parse import urlparse
"""
Fetch the current DEFCON level from the Australia government site
"""
LEVELS = {
"error": 0,
"certain": 1,
"expected": 2,
"probable": 3,
"possible": 4,
"notexpected": 5
}
NATIONAL_SECURITY_URL = "http://www.nationalsecurity.gov.au/"
def get_level():
result = requests.get(NATIONAL_SECURITY_URL)
soup = BeautifulSoup(result.content, features="html.parser")
alert_level = soup.find("script", id="ThreatLevelJson")
threat_data = json.loads(alert_level.string)
return threat_data["ThreatLevelNo"]
def lambda_handler(event, context):
"""
Return our status
:param event:
:param context:
:return:
"""
return {
"statusCode": 200,
"body": json.dumps({
"data": {
"type": "status",
"id": "1",
"attributes": {
"status": get_level()
}
}
})
}
if __name__ == "__main__":
print(lambda_handler(None, None))