def test_format_now(): assert format_now(now=now_for_test) == "2021-08-06 12:00:00" nt = format_now() time.sleep(1.1) nt2 = format_now() assert nt != nt2
def __init__(self): from util import format_now self.context = "global" self.db_type_name = self.__class__.__name__ self.create_at = format_now() self.update_at = format_now() self.file_created = False
def __init__(self): from util import format_now self.context = "global" self.db_type_name = self.__class__.__name__ self.version = "" self.create_at = format_now() self.save_at = format_now() self._update_at = "2000-11-06 14:16:33.253591" self.file_created = False # 如果设置了,则使用该路径,否则根据db类型和context的md5来生成路径 self.db_filepath = ""
def main(): # 初始化 nm = NoticeManager(load_from_remote=False) # note: 在这里添加公告 title = "绑定手机领666代币券" message = """之前春节短暂上线又鸽掉的绑手机领666欢乐代币券活动又回来了,大家可以去点一点 1. 绑定手机 2. 点击领取 https://dnf.qq.com/cp/a20211230info/index.html (点确认后会弹出活动页面) """ open_url = "https://dnf.qq.com/cp/a20211230info/index.html" show_only_before_version = "" if title != "": nm.add_notice( title, message, send_at=format_now(), show_type=NoticeShowType.ONCE, open_url=open_url, valid_duration=timedelta(days=7), show_only_before_version=show_only_before_version, ) nm.save()
def save(self): from util import format_now db_file = self.prepare_env_and_get_db_filepath() try: if not os.path.isfile(db_file): self.create_at = format_now() self.file_created = True self.update_at = format_now() self.save_to_json_file(db_file) except Exception as e: logger.error(f"保存数据库失败,db_to_save={self}") logger.debug( f"保存数据库完毕 context={self.context} db_type_name={self.db_type_name} db_file={db_file}" )
def add_notice( self, title, message, sender="风之凌殇", send_at: str = "", show_type=NoticeShowType.ONCE, open_url="", valid_duration: Optional[timedelta] = None, show_only_before_version="", ): send_at = send_at or format_now() valid_duration = valid_duration or timedelta(days=7) if show_type not in valid_notice_show_type: logger.error( f"无效的show_type={show_type},有效值为{valid_notice_show_type}") return for old_notice in self.notices: if old_notice.title == title and old_notice.message == message and old_notice.sender == sender: logger.error( f"发现内容完全一致的公告,请确定是否是误操作,若非误操作请去文本直接修改。\n{old_notice}") return notice = Notice() notice.title = title notice.message = message notice.sender = sender notice.send_at = send_at notice.show_type = show_type notice.open_url = open_url notice.expire_at = format_time(get_now() + valid_duration) notice.show_only_before_version = show_only_before_version self.notices.append(notice) logger.info(f"添加公告:{notice}")
def is_last_day(self) -> bool: act_info = get_not_ams_act("集卡") day_fmt = "%Y-%m-%d" return format_time(parse_time(act_info.dtEndTime), day_fmt) == format_now(day_fmt)
def set_update_at(self): from util import format_now self._update_at = format_now(self.time_cmt_millseconds)