import platform,socket,re,uuid,json,psutil,logging from datetime import datetime as dt from google_sheet import log_repo, conf_repo, SheetCRUDRepository from version import VERSION import pytz def get_now(): current_time = dt.now(pytz.timezone('Asia/Ho_Chi_Minh')) return current_time def get_sys_info(): try: info={} info['platform']=platform.system() info['platform-release']=platform.release() info['platform-version']=platform.version() info['architecture']=platform.machine() info['hostname']=socket.gethostname() info['ip-address']=socket.gethostbyname(socket.gethostname()) info['mac-address']=':'.join(re.findall('..', '%012x' % uuid.getnode())) info['processor']=platform.processor() info['ram']=str(round(psutil.virtual_memory().total / (1024.0 **3)))+" GB" return json.dumps(info) except Exception as e: logging.exception(e) class SheetLogger: def __init__(self, log_repo: SheetCRUDRepository, config_repo: SheetCRUDRepository): self.log_repo = log_repo self.config_repo = config_repo def log(self, log='', nb='', username=''): self.log_repo.create({ "time": str(get_now()), "notebook_name": nb, "kaggle_username": username, "log": log, "device": str(get_sys_info()), "version": VERSION }) def update_job_status(self, row, validate_status: str = None, notebook_status: str = None): data = self.config_repo.read(row) data.update({"last_updated": str(get_now())}) if validate_status is not None: data.update({"validate_status": validate_status}) if notebook_status is not None: data.update({"notebook_status": notebook_status}) self.config_repo.update(row, data) # print(self.config_repo.find({"config": "hahunavth/vlsp-sv-2023-s2pecnet-train"})) sheet_logger = SheetLogger(log_repo, conf_repo) if __name__ == "__main__": sheet_logger.update_job_status(5, "abc" , )