-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathwhisper-merge.py
executable file
·45 lines (34 loc) · 1.1 KB
/
whisper-merge.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
#!/usr/bin/python
import sys, time, shutil, whisper
from optparse import OptionParser
now = int( time.time() )
epoch = 0
option_parser = OptionParser(usage='''%prog [options] path1 path2''')
option_parser.add_option('--from', default=epoch, type='int', dest='_from',
help=("Unix epoch time of the beginning of "
"your requested interval (default: epoch)"))
option_parser.add_option('--until', default=now, type='int',
help="Unix epoch time of the end of your requested interval (default: now)")
(options, args) = option_parser.parse_args()
if len(args) != 2:
option_parser.print_usage()
sys.exit(1)
path1 = args[0]
path2 = args[1]
bakfile = path2 + '.bak'
shutil.copy2(path2, bakfile)
print "created backup file %s" % (bakfile)
from_time = int( options._from )
until_time = int( options.until )
(timeInfo, values) = whisper.fetch(path1, from_time, until_time)
(start,end,step) = timeInfo
t = start
for value in values:
timestr = str(t)
if value is None:
next
else:
valuestr = "%f" % value
datapoints = [timestr, valuestr]
whisper.update(path2, valuestr, timestr)
t += step