from os import walk
from os.path import getsize
from os.path import getmtime
from datetime import datetime
from os import chdir
chdir(path)
resultFile = 'result.csv'
for (path, dir, files) in walk('.'):
for filename in files:
ext = filename.split('.')[-1]
size = getsize(path + '\\' + filename)
mtime = str(datetime.fromtimestamp(getmtime(path + '\\' + filename)))[:19]
lst = '#'.join([ path, filename, ext, str(size), str(mtime)+'\n' ])
with open(resultFile, 'a') as f:
f.writelines(lst)
import pandas as pd
import numpy as np
from datetime import datetime
from elasticsearch.helpers import bulk
from elasticsearch import Elasticsearch
es = Elasticsearch(hosts=' ',port=' ', timeout=600)
ix = 'filelist'
es.indices.create(index=ix)
data = pd.read_csv(filename
, engine='python'
, sep='#'
, header=None
, names=['path', 'filename', 'ext', 'size','mtime'])
data['mtime'] = pd.to_datetime(data['mtime'], format='%Y-%m-%d %H:%M:%S')
data['size'] = data['size'].astype(np.int)
documents = data.to_dict(orient='records')
bulk(es, documents, index=ix, doc_type='_doc')
'Python > Python Programming' 카테고리의 다른 글
[ Python ] requests 모듈 다양한 이용 (0) | 2023.05.25 |
---|---|
[ Python ] requests 모듈을 이용한 동영상 다운로드 (0) | 2023.05.25 |
[ Python ] 정규식 이용한 IP address 마스킹(감추기) 하기 (3) | 2023.05.24 |
[ Python ] Prometheus metric 값 가져오기 (0) | 2023.05.24 |
[ Python ] socket 모듈을 이용한 Port open / close check (0) | 2023.05.23 |
[ Python ] pandas DataFrame을 HTML 형식으로 export 하기. (모니터링 활용) (0) | 2023.05.17 |
[ Python ] 웹 서버 날짜 확인 하기 (0) | 2023.05.14 |
[ Python ] ntplib 모듈을 이용한 시간 동기화 점검 (0) | 2023.05.14 |