fix: some exception
This commit is contained in:
parent
65beca5067
commit
77b51204af
60
main.py
60
main.py
@ -11,7 +11,7 @@ DEBUG_MODE = False
|
||||
URL = 'https://www.cmlab.csie.ntu.edu.tw/status-gpu/'
|
||||
GPU_LIMIT = 2
|
||||
GOOGLE_CODE = os.environ['GOOGLE_CODE']
|
||||
MAIL_CD_HOUR = 6
|
||||
MAIL_CD_HOUR = 12
|
||||
MAIL_MESSAGE = '''
|
||||
Hi, {}<br>
|
||||
<br>
|
||||
@ -76,38 +76,40 @@ def get_server_gpu_status() -> list:
|
||||
for box in boxes[:-1]:
|
||||
soup = BeautifulSoup(box, 'html.parser')
|
||||
# get server name
|
||||
server_name = soup.find('span', class_='f7').text.replace(' ', '')
|
||||
gpu_names = []
|
||||
server = soup.find('span', class_='f7')
|
||||
if server:
|
||||
server_name = server.text.replace(' ', '')
|
||||
gpu_names = []
|
||||
|
||||
users = []
|
||||
gpus = box.split('\n')
|
||||
for i in gpus[:]:
|
||||
if 'f6' in i: # if this line is for a single GPU informations
|
||||
soup = BeautifulSoup(i, 'html.parser')
|
||||
users = []
|
||||
gpus = box.split('\n')
|
||||
for i in gpus[:]:
|
||||
if 'f6' in i: # if this line is for a single GPU informations
|
||||
soup = BeautifulSoup(i, 'html.parser')
|
||||
|
||||
# get all users who is using this server's GPU resources.
|
||||
user_objs = soup.findAll('span', class_='f0')
|
||||
user_in_this_gpu = set()
|
||||
|
||||
# get users on this GPU
|
||||
for user_obj in user_objs:
|
||||
if user_obj != None:
|
||||
username = user_obj.text
|
||||
if username != 'gdm':
|
||||
user_in_this_gpu.add(username)
|
||||
# get all users who is using this server's GPU resources.
|
||||
user_objs = soup.findAll('span', class_='f0')
|
||||
user_in_this_gpu = set()
|
||||
|
||||
# get users on this GPU
|
||||
for user_obj in user_objs:
|
||||
if user_obj != None:
|
||||
username = user_obj.text
|
||||
if username != 'gdm' and username != 'root':
|
||||
user_in_this_gpu.add(username)
|
||||
|
||||
# get gpu names
|
||||
gpu_name = soup.find('span', class_='f4').text.replace(' ', '')
|
||||
# get gpu names
|
||||
gpu_name = soup.find('span', class_='f4').text.replace(' ', '')
|
||||
|
||||
# log gpu name & users on this GPU
|
||||
gpu_names.append(gpu_name)
|
||||
users.append(list(user_in_this_gpu))
|
||||
# log gpu name & users on this GPU
|
||||
gpu_names.append(gpu_name)
|
||||
users.append(list(user_in_this_gpu))
|
||||
|
||||
servers.append({
|
||||
'name': server_name,
|
||||
'users': users,
|
||||
'gpus': gpu_names
|
||||
})
|
||||
servers.append({
|
||||
'name': server_name,
|
||||
'users': users,
|
||||
'gpus': gpu_names
|
||||
})
|
||||
return servers
|
||||
|
||||
def filter(server_status: list, limit: int = 2) -> list:
|
||||
@ -197,7 +199,7 @@ def mail_notify(violators: list) -> None:
|
||||
msg['Subject'] = f'[網管通知] 提醒您已經超過 CMLab GPU 使用限制!({username})'
|
||||
msg['From'] = 'unix_manager@cmlab.csie.ntu.edu.tw'
|
||||
msg['To'] = f'{username}@cmlab.csie.ntu.edu.tw' if not DEBUG_MODE else 'snsd0805@cmlab.csie.ntu.edu.tw'
|
||||
msg['Cc'] = 'unix_manager@cmlab.csie.ntu.edu.tw' if not DEBUG_MODE else 'snsd0805@cmlab.csie.ntu.edu.tw'
|
||||
# msg['Cc'] = 'unix_manager@cmlab.csie.ntu.edu.tw' if not DEBUG_MODE else 'snsd0805@cmlab.csie.ntu.edu.tw'
|
||||
|
||||
smtp = smtplib.SMTP('smtp.gmail.com', 587)
|
||||
smtp.ehlo()
|
||||
|
||||
Loading…
Reference in New Issue
Block a user