This repository has been archived by the owner on Feb 8, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
app.py
103 lines (74 loc) · 2.96 KB
/
app.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
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
from chalice import Chalice
from urllib import unquote
import json
import requests
app = Chalice(app_name='apple-system-status')
service_classes = {}
devjson = requests.get("https://www.apple.com/support/systemstatus/data/developer/system_status_en_US.js").text.split("(")[1].split(")")[0]
service_classes['dev'] = json.loads(devjson)['services']
prodjson = requests.get("https://www.apple.com/support/systemstatus/data/system_status_en_US.js").text
service_classes['prod'] = json.loads(prodjson)['services']
@app.route('/services')
def get_services():
result = []
for _, servicekeys in service_classes.iteritems():
for service in servicekeys:
serviceName = service.get('serviceName')
result.append(serviceName)
return json.dumps(result)
@app.route('/service/{name}')
def get_service(name):
result = {}
for _, servicekeys in service_classes.iteritems():
for service in servicekeys:
if unquote(name) in service['serviceName']:
result = service
return json.dumps(result)
@app.route('/service/{name}/{status}')
def get_service_status(name, status):
result = {}
down_status_list = ['']
up_status_list = ['resolved', 'completed']
for _, servicekeys in service_classes.iteritems():
for service in servicekeys:
if unquote(name) in service['serviceName']:
eventStatus = service['events'][0]['eventStatus']
if 'up' in status:
if len(service['events']) == 0:
result = True
elif len(service['events']) > 0:
if any(x in eventStatus for x in up_status_list):
result = True
else:
result = False
elif 'down' in status:
if len(service['events']) > 0:
if any(x in eventStatus for x in up_status_list):
result = False
else:
result = True
elif len(service['events']) == 0:
result = False
else:
result = 'Invalid status request'
return json.dumps(result)
@app.route('/devstatus')
def get_dev():
result = {}
for service in service_classes['dev']:
serviceName = service.get('serviceName')
if not service.get('events'):
result[serviceName] = [{'eventStatus': 'up'}]
else:
result[serviceName] = service.get('events')
return json.dumps(result)
@app.route('/prodstatus')
def get_prod():
result = {}
for service in service_classes['prod']:
serviceName = service.get('serviceName')
if not service.get('events'):
result[serviceName] = [{'eventStatus': 'up'}]
else:
result[serviceName] = service.get('events')
return json.dumps(result)