You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
48 lines
997 B
48 lines
997 B
#!/usr/bin/python3
|
|
|
|
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()
|