This repository was archived by the owner on Sep 16, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathcommon.py
More file actions
76 lines (53 loc) · 1.63 KB
/
common.py
File metadata and controls
76 lines (53 loc) · 1.63 KB
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
75
76
import copy
import os
import time
from contextlib import contextmanager
import moment
from conf import config
from log import info
@contextmanager
def checkTimes(level=3):
timeStart = time.time()
yield
info(f'cost times: {round(time.time()-timeStart,level)}s')
def checkCount(func):
def checker(*args, **kwargs):
try:
res = func(*args, **kwargs)
config.status['success'] += 1
return res
except Exception:
config.status['failed'] += 1
raise
return checker(func)
def addsucess():
config.status['success'] += 1
def addfailed():
config.status['failed'] += 1
def addtotal():
config.status['total'] += 1
def addupdate():
config.status['updated'] += 1
def checkPath(path):
return os.path.exists(path)
def initPath(path):
if not checkPath(path):
os.makedirs(path)
def timeSections(starttimes=None, endtimes=None, sectiondays=30, sectionshours=1, formats=None):
if not starttimes:
starttimes = moment.now().replace(minutes=0, seconds=0).add(days=-sectiondays)
else:
starttimes = moment.date(starttimes)
if not endtimes:
endtimes = moment.now().replace(minutes=0, seconds=0)
else:
endtimes = moment.date(endtimes)
while starttimes < endtimes:
nexttimes = copy.deepcopy(starttimes).add(hours=sectionshours)
if formats:
yield starttimes.format(formats), nexttimes.format(formats)
else:
yield starttimes, nexttimes
starttimes = nexttimes
if __name__ == "__main__":
print(list(timeSections(formats='YYYY-MM-DD hh:mm:ss')))