CMLAB-GPU-Mailer/weekly_report.py

32 lines
1020 B
Python

import os
import json
from mailer import Mailer
GOOGLE_OWNER = 'snsd0805@cmlab.csie.ntu.edu.tw'
GOOGLE_CODE = os.environ['GOOGLE_CODE']
if __name__ == '__main__':
with open('send_log.json') as fp:
data = json.load(fp)
msg = '''
<pre>
Every Wednesday 00:30
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \n
'''
for username, status in data.items():
week_count = status['week_count']
if week_count != 0:
print(username, week_count)
data[username]['week_count'] = 0
msg += f'\t{username}: notified <span style="color: red">{week_count}</span> times in this week\n'
msg += '''
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
</pre>
'''
mailer = Mailer(GOOGLE_OWNER, GOOGLE_CODE)
mailer.send('unix_manager@cmlab.csie.ntu.edu.tw', f'unix_manager@cmlab.csie.ntu.edu.tw', 'CML Server GPU Usage Weekly Report', msg)
with open('send_log.json', 'w') as fp:
json.dump(data, fp)