#!/usr/bin/python3 import json from urllib.request import urlopen, Request def get_jobs(url="http://localhost:8898"): """get_jobs fetch jobs from dkron""" fullurl = f"{url}/v1/jobs" req = Request(method="GET", url=fullurl) res = urlopen(req) dkron_ret = json.loads(res.read()) if res.status == 200: return dkron_ret return None def set_jobs(url="http://localhost:8898", job=None): """set_jobs set jobs on dkron""" fullurl = f"{url}/v1/jobs" data = json.dumps(job).encode('utf-8') req = Request(method="POST", url=fullurl, data=data) req.add_header('Content-Type', 'application/json') res = urlopen(req) dkron_ret = json.loads(res.read()) if res.status == 201: return dkron_ret return None