项目的结构图示
trans/tools
from datetime
import datetime
import random
def gen_trans_id(date
=None):
"""
根据所传入的时间得到一个唯一的交易流水ID
:param date: 日期
:return: 交易流水的ID字符串
"""
if date
is None:
date
= datetime
.now
()
return date
.strftime
('%Y%m%d%H%M%S%f') + str(random
.randint
(10000,999999))
work/tools
import os
.path
import constants
def get_file_type(file_name
):
"""
根据文件的名称来判断文件的类型
:param file_name: str 文件名称
:return: int 文件类型
-1:未知文件类型
0:图片类型的文档
1:word 文档
2:excel 文档
3. ppt 文档
"""
result
= constants
.FILE_TYPE_UNKNOWN
if not os
.path
.isfile
(file_name
):
return result
path_name
, ext
= os
.path
.splitext
(file_name
)
ext
= ext
.lower
()
if ext
in ('.png', 'jpg', 'gif', '.bmp'):
result
= constants
.FILE_TYPE_IMG
elif ext
in ('.doc', '.docx'):
result
= constants
.FILE_TYPE_DOC
elif ext
in ('.xls', '.xlsx'):
result
= constants
.FILE_TYPE_EXCEL
elif ext
in ('.ppt', '.pptx'):
result
= constants
.FILE_TYPE_PPT
return result
constants
"""
文件类型常量
"""
FILE_TYPE_UNKNOWN
= 10
FILE_TYPE_IMG
= 11
FILE_TYPE_DOC
= 12
FILE_TYPE_EXCEL
= 13
FILE_TYPE_PPT
= 14
test_module
from trans import tools as trans_tools from work import tools as work_tools
from datetime
import datetime
from trans
import tools
as trans_tools
from work
import tools
as work_tools
def test_trans_tool():
"""测试trans包下的tools模块"""
id1
= trans_tools
.gen_trans_id
()
print(id1
)
date
= datetime
(2015, 10, 1, 15, 1, 30)
id2
= trans_tools
.gen_trans_id
(date
)
print(id2
)
def test_work_tools():
"""测试work模块"""
file_name
= 'C:\\Users\\徐达\\Pictures\\Saved Pictures\\151165695.jpg'
rest
= work_tools
.get_file_type
(file_name
)
print(rest
)
if __name__
== '__main__':
test_trans_tool
()
test_work_tools
()
转载请注明原文地址:https://blackberry.8miu.com/read-730.html