-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutil.py
74 lines (59 loc) · 1.75 KB
/
util.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import os
import gzip
start_time = "2020-01-01"
end_time = "2020-12-30"
def is_in_time(path):
time_path = path.find("2020")
if start_time <= path[time_path:time_path+10] <= end_time:
return True
else:
return False
def is_zhubi_raw_file(path):
if os.path.isfile(path) and \
is_in_time(path) and \
path.find("zhubi") > 0 and not path.endswith(".gz") \
and not path.endswith(".swp"):
return True
else:
return False
def is_tick_raw_file(path):
if os.path.isfile(path) \
and is_in_time(path) \
and path.find("tick") > 0 and not path.endswith(".gz") \
and not path.endswith(".swp"):
return True
else:
return False
def is_zhubi_gz_file(path):
if os.path.isfile(path) \
and is_in_time(path) \
and path.find("zhubi") > 0 and path.endswith(".gz"):
return True
else:
return False
def is_tick_gz_file(path):
if os.path.isfile(path) \
and is_in_time(path) \
and path.find("tick") > 0 and path.endswith(".gz"):
return True
else:
return False
def is_gz_file(path):
if os.path.isfile(path) \
and is_in_time(path) \
and path.endswith(".gz"):
return True
else:
return False
# 解压gz,事实上就是读出当中的单一文件
def un_gz(file_name):
"""ungz zip file"""
f_name = file_name.replace(".gz", "")
# 获取文件的名称,去掉
g_file = gzip.GzipFile(file_name)
# 创建gzip对象
open(f_name, "w").write(g_file.read().__str__())
# gzip对象用read()打开后,写入open()建立的文件里。
g_file.close()
return f_name
# 关闭gzip对象