Files
YYeTsBot/yyetsweb/commands/change_datetime.py
2023-02-13 18:28:07 +01:00

40 lines
1002 B
Python

#!/usr/local/bin/python3
# coding: utf-8
# YYeTsBot - change_datetime.py
# 6/15/21 14:15
#
__author__ = "Benny <benny.think@gmail.com>"
import time
from common import Mongo
client = Mongo().client
comment = client["zimuzu"]["comment"] # date
users = client["zimuzu"]["users"] # date
all_comments = list(comment.find())
all_users = list(users.find())
for item in all_comments:
object_id = item["_id"]
old_date = time.strptime(item["date"], "%a %b %d %H:%M:%S %Y")
new_date = time.strftime("%Y-%m-%d %H:%M:%S", old_date)
condition = {"_id": object_id}
update = {"$set": {"date": new_date}}
comment.find_one_and_update(condition, update)
for item in all_users:
# unique for username
object_id = item["_id"]
old_date = time.strptime(item["date"], "%a %b %d %H:%M:%S %Y")
new_date = time.strftime("%Y-%m-%d %H:%M:%S", old_date)
condition = {"_id": object_id}
update = {"$set": {"date": new_date}}
users.find_one_and_update(condition, update)