parent
fe23a237c5
commit
d834187bb5
@ -0,0 +1,45 @@
|
||||
import configparser
|
||||
import datetime
|
||||
import json
|
||||
import os
|
||||
import pathlib
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
import persistqueue
|
||||
|
||||
|
||||
config = configparser.ConfigParser()
|
||||
config.read(os.getenv('CHEDDAR_KNIGHT_CONFIG', 'settings.cfg'))
|
||||
|
||||
|
||||
storage_path = config.get('General', 'storage_path')
|
||||
|
||||
|
||||
class Timer:
|
||||
@classmethod
|
||||
def schedule(cls, time, data):
|
||||
subprocess.run((
|
||||
'/usr/bin/systemd-run',
|
||||
'--user',
|
||||
'--working-directory={0}'.format(pathlib.Path(__file__).parent),
|
||||
'--timer-property=AccuracySec=1s',
|
||||
'--on-calendar={0}'.format(time.strftime('%Y-%m-%d %H:%M:%S UTC')),
|
||||
'/usr/bin/python3',
|
||||
__file__,
|
||||
json.dumps(data)
|
||||
))
|
||||
|
||||
@classmethod
|
||||
def execute(cls, data):
|
||||
queue = persistqueue.SQLiteQueue(storage_path)
|
||||
queue.put(data)
|
||||
queue.task_done()
|
||||
|
||||
|
||||
def main():
|
||||
Timer.execute(json.loads(sys.argv[1]))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
Loading…
Reference in new issue