from pymongo import MongoClient import pymongo import datetime #CONNECTION_STRING = "mongodb+srv://:@.mongodb.net/test" CONNECTION_STRING = "mongodb://mongoAdmin:chan9eM3@hhh.ptt.cx" #CONNECTION_STRING = "mongodb://mongoAdmin:chan9eM3@hhh.ptt.cx/logs" client = MongoClient(CONNECTION_STRING) print(client) cols=client['logs'] #print(cols) col=cols['syslog'] #cursor=col.find({}).sort('time_rcvd',pymongo.DESCENDING) cursor=col.find({}) #cursor=col.find({}).sort('time_rcvd',pymongo.DESCENDING) cnt=0 for c in cursor: # print(c) # if 'clickbot_100' in c['msg']: if 'poibot' in c['msg']: dt=c['time_rcvd'] dt=dt.replace(tzinfo=datetime.timezone.utc) #Convert it to an aware datetime object in UTC time. dt=dt.astimezone() #Convert it to your local timezone (still aware) print(dt.strftime('%Y-%m-%d %H:%M:%S')) # print(dt.strftime("%d %b %Y %I:%M:%S:%f %p")) # print(c['time_rcvd']) print(c['msg']) cnt+=1 # if cnt>=100000: # break #print(col) #col.insert_one({"item_name" : "Bread",'id':1234,'name':'中文測試'})