client232/cron.py

37 lines
893 B
Python
Raw Normal View History

2018-11-27 09:20:00 +00:00
#!/usr/bin/env python3
from crontab import CronTab
import os
import csv
import sys
def whereami():
return os.path.dirname(os.path.abspath(__file__))
class Cron(CronTab):
def __init__(self, user=True):
CronTab.__init__(self, user=user)
def clearCron(self):
return self.remove_all()
def getJob(self, code):
return self.new(command="%s/send.py %s" % (whereami(), code))
def buildJob(self, code, minute=False, hour=False):
job = self.getJob(code)
job.setall(time(hour, minute))
job.enable()
def readCSV(self, path):
self.clearCron()
with open(path) as csvfile:
r = csv.DictReader(csvfile, [minute, hour, code])
for row in r:
self.buildJob(row["code"], row["minute"], row["hour"])
self.write()
if __name__ == "__main__":
Cron().readCSV(sys.argv[1])