-
Notifications
You must be signed in to change notification settings - Fork 0
/
record.py
47 lines (37 loc) · 1.13 KB
/
record.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
#!/usr/bin/env python3
import asyncio
import os
from datetime import datetime
from update_image import UpdateImage
interval = 180
filename_template = "autosave/autosave_{:%Y_%m_%d-%H_%M_%S}.gif"
def print_log(filename):
print("@%s record current image, save file %s" %
(datetime.now(), filename))
async def wakeup():
""" Keep script responsive to Ctrl+C
"""
while True:
await asyncio.sleep(1)
async def recording(up):
while True:
await up.perform_update_image()
filename = filename_template.format(datetime.now())
up.save_buffer_to_file(filename)
print_log(filename)
await asyncio.sleep(interval)
if __name__ == "__main__":
if not os.path.exists('autosave'):
print("Create output folder autosave")
os.makedirs("autosave")
up = UpdateImage()
print("Start @%s" % datetime.now())
loop = asyncio.get_event_loop()
try:
loop.run_until_complete(asyncio.gather(recording(up), wakeup()))
except KeyboardInterrupt:
print("Ctrl+C pressed, existing")
finally:
up.close()
loop.stop()
loop.close()