代码拉取完成,页面将自动刷新
import os
from datetime import datetime
import requests
import json
class Log:
"""logging system"""
def __init__(self,homepath, logfilename):
self.homepath = homepath
self.logfilename = logfilename
def inet_addr(self):
"""return public ip address"""
print "return public ip address..."
return requests.get("http://httpbin.org/ip").json()['origin']
def files_attr(self, path):
"""return home path files attributes"""
print "return file list...", path
fls = []
for p,ds,fs in os.walk(path):
for f in fs:
print str(os.path.join(p,f))
# 使用','.join("%s" % x for x in LIST),是为了避免抛出 sequence item 0 expected string int found的错误
fls.append( str(os.path.join(p,f)) + ':' + ','.join("%s"%x for x in os.stat(os.path.join(p,f))))
return json.dumps(fls)
def record(self):
"""write into log file"""
print "write into file..."
with open(self.logfilename,'a') as f:
sep = '-' * 40
f.write(sep)
f.write(str(datetime.now()))
f.write(sep + '\n')
f.write(self.inet_addr() + '\n')
f.write(self.files_attr(self.homepath) + '\n')
if __name__ == '__main__':
HOME_PATH = os.path.join('your','real','path')
LOG_FILENAME = os.path.join(os.getcwd(),'log.txt')
print LOG_FILENAME
log = Log(HOME_PATH,LOG_FILENAME)
log.record()
print "finished..."
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。