diff --git a/app/main.py b/app/main.py index fd74c42..df27c97 100644 --- a/app/main.py +++ b/app/main.py @@ -116,7 +116,10 @@ def hello(): @app.get("/tgMessage") def tgMessagefun(openid: Optional[str] = None, db: Session = Depends(get_db)): current_time = datetime.now() - print("Current Date and Time:", current_time) + # 格式化日期和时间,不包含空格 + formatted_now = current_time.strftime("%Y%m%d%H%M%S") + + print("Current Date and Time:", formatted_now) # 发送tg消息通知 wxid_4413224132412 || o7LFAwR32hWGq9XOpd7ZxK1wZxq8 # openid = "o7LFAwR32hWGq9XOpd7ZxK1wZxq8" @@ -130,14 +133,14 @@ def tgMessagefun(openid: Optional[str] = None, db: Session = Depends(get_db)): if userInfo: # print('userInfo==>', userInfo) # message = f"{userInfo['nickname']}/{userInfo['gender']}在{current_time}进行了访问" - message = f"{userInfo.nickname}/{userInfo.gender}在{current_time}进行了访问" + message = f"{userInfo.nickname}/{userInfo.gender}在{formatted_now}进行了访问" print(message) sengTgmesage(message) # tgMessage.sendTg(message) else: print('openid未关联') - message = f'openid: {openid}-未关联,在{current_time}访问网页' + message = f'openid: {openid}-未关联,在{formatted_now}访问网页' print(message) sengTgmesage(message) @@ -203,10 +206,12 @@ def generateqr(url="http://nomad.hackrobot.cn", group_image.height - qr_image.height - 50) # 距离20像素 # 在原图上添加二维码 group_image.paste(qr_image, qr_position) - + current_time = datetime.now() + # 格式化日期和时间,不包含空格 + formatted_now = current_time.strftime("%Y%m%d%H%M%S") # 保存合成的图像 # combined_image_path = f"images/combined_{wxid}_{datetime.now()}.jpg" - combined_image_path = f"images/combined_{wxid}_{datetime.date.today()}.jpg" + combined_image_path = f"images/combined_{wxid}_{formatted_now}.jpg" group_image.save(combined_image_path) # 压缩图片 @@ -239,7 +244,7 @@ def add_user(nickname: Optional[Any] = None, wxid=wxid, gender=gender, # friendaddtime=friendaddtime, - friendaddtime=str(datetime.now()), + friendaddtime=str(datetime.now().strftime("%Y%m%d%H%M%S")), openid=openid) if background_tasks: background_tasks.add_task(create_user_task, db, user_data)