-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsnapper.py
81 lines (65 loc) · 2.61 KB
/
snapper.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
75
76
77
78
79
80
81
from __future__ import division, print_function, absolute_import
import time
from datetime import datetime as dt
from ligmos import utils
from picamhelpers.capture import piCamCapture
from picamhelpers.classes import piCamSettings
from picamhelpers.utils import copyStaticFilenames
def main():
"""
"""
# Read in our config file
confFile = './config/picamSettings.conf'
# We ignore the second return value since searchCommon is False
camSettings, _ = utils.confparsers.parseConfig(confFile, piCamSettings,
passfile=None,
searchCommon=False,
enableCheck=False)
# We're cheating by grabbing the relevant config section directly
# but it's ok, I'm abusing my own API so it's fine.
camSettings = camSettings['picam']
# Another hack
try:
camSettings.interval = int(camSettings.interval)
except ValueError:
camSettings.interval = 90
maxagehrs = 24.
outloc = camSettings.savepath
lout = outloc + "/anim/"
staticname = 'snapper'
nstaticfiles = 24
# Start logging to a file
utils.logs.setup_logging(logName="./logs/snapper.log", nLogs=10)
# Set up our signal
runner = utils.common.HowtoStopNicely()
while runner.halt is False:
piCamCapture(camSettings, outloc, debug=True)
# Cull the images to the last XX days worth
print("Searching for old files...")
now = dt.utcnow()
young, old = utils.files.findOldFiles(outloc, "*.png", now,
maxage=maxagehrs,
dtfmt="%Y%m%d_%H%M%S.png")
print("Deleting old files...")
print(old)
utils.files.deleteOldFiles(old)
# Copy the static files that get animated
print("Copying new files to static names for animation...")
copyStaticFilenames(young, lout, staticname, nstaticfiles)
# Sleep for sleeptime in 1 second intervals
print("Sleeping for %f seconds..." % (camSettings.interval))
i = 0
if runner.halt is False:
print("Starting a big sleep")
# Sleep for bigsleep, but in small chunks to check abort
for _ in range(camSettings.interval):
time.sleep(1)
if (i + 1) % 30 == 0:
print(".", end=None)
i += 1
if runner.halt is True:
break
print()
if __name__ == "__main__":
main()
print("Pi snapper has exited!")