Skip to content

Commit 3fbf7d8

Browse files
committed
feat: add betterstatus embed
and remove old method of scraping the TJCSL status page
1 parent 73e0311 commit 3fbf7d8

File tree

4 files changed

+26
-43
lines changed

4 files changed

+26
-43
lines changed

intranet/apps/emerg/views.py

Lines changed: 5 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import json
21
import logging
32
import time
43

@@ -14,20 +13,19 @@
1413

1514

1615
def check_emerg():
17-
"""Fetch from FCPS and CSL emergency announcement pages.
16+
"""Fetch from FCPS emergency announcement pages.
1817
19-
URLs defined in settings.FCPS_EMERGENCY_PAGE and settings.CSL_STATUS_PAGE
18+
URLs defined in settings.FCPS_EMERGENCY_PAGE
2019
2120
Request timeout defined in settings.FCPS_EMERGENCY_TIMEOUT
2221
2322
"""
2423
fcps_page = settings.FCPS_EMERGENCY_PAGE
25-
csl_page = settings.CSL_STATUS_PAGE
2624
announcements = []
2725

2826
if settings.EMERGENCY_MESSAGE:
2927
return True, settings.EMERGENCY_MESSAGE
30-
if not fcps_page or not csl_page:
28+
if not fcps_page:
3129
return None, None
3230

3331
timeout = settings.EMERGENCY_TIMEOUT
@@ -67,44 +65,10 @@ def check_emerg():
6765

6866
announcements.append({"title": f"<a target='_blank' href=\"{get_domain_name(fcps_page)}\">{title}</a>", "body": body})
6967

70-
try:
71-
r = requests.get(csl_page, timeout=timeout)
72-
except requests.exceptions.Timeout:
73-
pass
74-
75-
try:
76-
csl_status = json.loads(r.text)
77-
except json.decoder.JSONDecodeError:
78-
return False, None
79-
80-
for system in csl_status["systems"]:
81-
if system["status"] != "ok":
82-
status = True
83-
issues = system["unresolvedIssues"]
84-
for issue in issues:
85-
desc = requests.get(issue["permalink"], timeout=timeout).text
86-
soup = BeautifulSoup(desc, "html.parser")
87-
88-
text = soup.find_all(["p", "hr"])
89-
desc = text[2 : len(text) - 5]
90-
a = {
91-
"title": f"<a target='_blank' href=\"{get_domain_name(csl_page)}\">{issue['title']}</a>",
92-
"body": "".join(d.prettify() for d in desc),
93-
}
94-
if a not in announcements and issue["severity"] != "notice":
95-
announcements.append(a)
96-
97-
# Not needed due to the filtering of "p" elements, but as a backup:
98-
bad_text = [
99-
'<p><strong class="bold">© tjCSL Status, 2022</strong>&nbsp; • &nbsp; <a href="#">Back to top</a></p>',
100-
"<p>We continuously monitor the status of our services and if there are any interruptions, a note will be posted here.</p>",
101-
]
102-
10368
message = "".join(
10469
[
10570
f"<h3><i class='fas fa-exclamation-triangle'></i>&nbsp; {announcement['title']}</h3><hr />{announcement['body']}\n"
10671
for announcement in announcements
107-
if announcement not in bad_text
10872
]
10973
)
11074

@@ -117,12 +81,12 @@ def get_emerg_result(*, custom_logger=None):
11781
custom_logger = logger
11882

11983
status, message = check_emerg()
120-
custom_logger.debug("Fetched emergency info from FCPS and CSL status")
84+
custom_logger.debug("Fetched emergency info from FCPS")
12185
return {"status": status, "message": message}
12286

12387

12488
def get_emerg():
125-
"""Get the cached FCPS emergency page and CSL status page, or check it again.
89+
"""Get the cached FCPS emergency page, or check it again.
12690
12791
Timeout defined in settings.CACHE_AGE["emerg"]
12892

intranet/settings/__init__.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -885,8 +885,6 @@ def get_log(name): # pylint: disable=redefined-outer-name; 'name' is used as th
885885
# The timeout for the request to FCPS' emergency page (in seconds)
886886
EMERGENCY_TIMEOUT = 5
887887

888-
CSL_STATUS_PAGE = "https://status.tjhsst.edu/index.json"
889-
890888
# How frequently the emergency announcement cache should be updated by the Celerybeat task.
891889
# This should be less than CACHE_AGE["emerg"].
892890
FCPS_EMERGENCY_CACHE_UPDATE_INTERVAL = CACHE_AGE["emerg"] - 30

intranet/static/css/page_base.scss

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,23 @@ h1 {
211211
}
212212
}
213213

214+
.header .csl-apps .betterstatus-indicator {
215+
display: inline;
216+
vertical-align: middle;
217+
218+
@media only screen and (max-width: 900px) {
219+
width: 30px;
220+
margin-right: -10px;
221+
}
222+
223+
@media only screen and (min-width: 901px) {
224+
width: 200px;
225+
margin-right: -30px;
226+
margin-bottom: 5px;
227+
}
228+
}
229+
230+
214231
.header .username {
215232
margin-right: 10px;
216233
}

intranet/templates/page_with_header.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,10 @@ <h1>Ion</h1>
8484
</li>
8585
{% endif %}
8686

87+
<li class="csl-apps">
88+
<iframe src="https://status.tjhsst.edu/badge?theme=dark" height="30" scrolling="no" style="color-scheme: normal;" class="betterstatus-indicator"></iframe>
89+
</li>
90+
8791
{% if csl_apps|length > 0 %}
8892
<li class="csl-apps has-dropdown">
8993
<div class="dropdown-item-wrapper">

0 commit comments

Comments
 (0)