How to set a dynamic variable in Python that changes with system time?
巴扎黑
巴扎黑 2017-05-18 10:52:07
0
3
1263

Newbie, I am making a python program, or script, to process logs. After processing and inserting it into elastic search, how to set a dynamic variable that can change with the system time. For example, the variable is num0508 today and will become num0509 tomorrow?

巴扎黑
巴扎黑

reply all(3)
小葫芦
import datetime
>>> datetime.datetime.now().strftime("%Y-%m-%d)
'2017-05-08'
漂亮男人

I guess you want to insert logs or data into an index named after date. If so, you can just use a string

import time
from elasticsearch import Elasticsearch

index_name = 'num_%s' % time.strftime('%m%d', time.localtime())
es = Es()
es.index(index_name, ...(自己补充其他参数内容))

If you explain your scenario more clearly, I believe we will provide a method that better meets your needs

仅有的幸福

Follow the code in the picture below to implement it

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template