1
- import json
2
1
import logging
3
2
import time
4
3
14
13
15
14
16
15
def check_emerg ():
17
- """Fetch from FCPS and CSL emergency announcement pages.
16
+ """Fetch from FCPS emergency announcement pages.
18
17
19
- URLs defined in settings.FCPS_EMERGENCY_PAGE and settings.CSL_STATUS_PAGE
18
+ URLs defined in settings.FCPS_EMERGENCY_PAGE
20
19
21
20
Request timeout defined in settings.FCPS_EMERGENCY_TIMEOUT
22
21
23
22
"""
24
23
fcps_page = settings .FCPS_EMERGENCY_PAGE
25
- csl_page = settings .CSL_STATUS_PAGE
26
24
announcements = []
27
25
28
26
if settings .EMERGENCY_MESSAGE :
29
27
return True , settings .EMERGENCY_MESSAGE
30
- if not fcps_page or not csl_page :
28
+ if not fcps_page :
31
29
return None , None
32
30
33
31
timeout = settings .EMERGENCY_TIMEOUT
@@ -67,44 +65,10 @@ def check_emerg():
67
65
68
66
announcements .append ({"title" : f"<a target='_blank' href=\" { get_domain_name (fcps_page )} \" >{ title } </a>" , "body" : body })
69
67
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> • <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
-
103
68
message = "" .join (
104
69
[
105
70
f"<h3><i class='fas fa-exclamation-triangle'></i> { announcement ['title' ]} </h3><hr />{ announcement ['body' ]} \n "
106
71
for announcement in announcements
107
- if announcement not in bad_text
108
72
]
109
73
)
110
74
@@ -117,12 +81,12 @@ def get_emerg_result(*, custom_logger=None):
117
81
custom_logger = logger
118
82
119
83
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" )
121
85
return {"status" : status , "message" : message }
122
86
123
87
124
88
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.
126
90
127
91
Timeout defined in settings.CACHE_AGE["emerg"]
128
92
0 commit comments