def check(in_stream):
    input = json.load(in_stream)
    api_root = input["source"]["api_root"]
    status_id = input["source"].get("status_id")
    job_type_id = input["source"].get("job_type_id")
    version = input.get("version")

    if not status_id:
        return [version] if version else []
    else:
        jobs = get_jobs(api_root)
        msg("jobs: {}", jobs)
        msg("Inputs: {}", input)

        jobs = [job for job in jobs if int(job["status_id"]) == status_id]

        if job_type_id is not None:
            jobs = [
                job for job in jobs
                if int(job.get("job_type_id")) == job_type_id
            ]

        if version:
            previous_id = version["id"]
            jobs = [job for job in jobs if int(job["id"]) > int(previous_id)]

        return [{"id": job["id"]} for job in jobs]
Example #2
0
def in_(dest_path, in_stream):
    input = json.load(in_stream)
    msg("Input: {}", input)

    version = input["version"]["version"]
    msg("Version Returned: {}", version)

    # Write out files
    write_file(os.path.join(dest_path, "version"), version)

    return {"version": {"version": version}}
Example #3
0
def check(in_stream):
    input = json.load(in_stream)
    api_root = input["source"]["api_root"]
    status = input["source"]["status"]

    events = get_events(api_root)
    msg("{}", events)

    events = [event for event in events if event["status"] == status]

    if input["version"]:
        previous_id = input["version"]["id"]
        events = [event for event in events if event["id"] > previous_id]

    return [{"id": event["id"]} for event in events]
Example #4
0
def in_(dest_path, in_stream):
    input = json.load(in_stream)
    api_root = input["source"]["api_root"]
    event_id = input["version"]["id"]

    event = api.get_event(api_root, event_id)
    msg("Event Returned: {}", event["id"])

    # Write out files
    with open(os.path.join(dest_path, "id"), "w") as file:
        file.write(str(event_id))

    with open(os.path.join(dest_path, "ident_hash"), "w") as file:
        file.write(event["ident_hash"])

    with open(os.path.join(dest_path, "event.json"), "w") as file:
        json.dump(event, file)

    return {"version": {"id": event_id}}
Example #5
0
def check(in_stream):
    input = json.load(in_stream)
    api_root = input["source"]["api_root"]
    status_id = int(input["source"]["status_id"])

    events = get_events(api_root)
    msg("Events: {}", events)
    msg("Inputs: {}", input)

    events = [
        event for event in events if int(event["status_id"]) == status_id
    ]

    if input["version"]:
        previous_id = input["version"]["id"]
        events = [
            event for event in events if int(event["id"]) > int(previous_id)
        ]

    return [{"id": event["id"]} for event in events]
Example #6
0
def out(src_path, in_stream):
    input = json.load(in_stream)
    data = input["params"]

    # Remove the id which represents the path in resource.
    # Keep the rest of the information to update the event.
    id_path = data.pop("id")

    msg("Input: {}", input)

    with open(os.path.join(src_path, id_path), "r") as infile:
        id = infile.read()

    pdf_url = data.get("pdf_url")
    if pdf_url:
        with open(os.path.join(src_path, pdf_url), "r") as infile:
            pdf_url = infile.read()
            data["pdf_url"] = pdf_url

    msg("Params: {}", data)
    msg(f"Updating status of event id {id}")

    response = update_event(input["source"]["api_root"], id, data)

    return {"version": {"id": response["id"]}}
Example #7
0
def in_(dest_path, in_stream):
    input = json.load(in_stream)
    msg("Input: {}", input)

    api_root = input["source"]["api_root"]
    event_id = input["version"]["id"]

    event = api.get_event(api_root, event_id)
    msg("Event Returned: {}", event)

    collection_id = event["collection_id"]
    collection_version = event["version"] or "latest"
    content_server = event["content_server"]["hostname"]

    # Write out files
    write_file(os.path.join(dest_path, "id"), event_id)
    write_file(os.path.join(dest_path, "collection_id"), collection_id)
    write_file(os.path.join(dest_path, "version"), collection_version)
    write_file(os.path.join(dest_path, "content_server"), content_server)
    write_file(os.path.join(dest_path, "event.json"), event)

    return {"version": {"id": event_id}}
Example #8
0
def in_(dest_path, in_stream):
    input = json.load(in_stream)
    msg("Input: {}", input)

    api_root = input["source"]["api_root"]
    job_id = input["version"]["id"]

    job = api.get_job(api_root, job_id)
    msg("job Returned: {}", job)

    collection_id = job["collection_id"]
    collection_version = job["version"] or "latest"
    collection_style = job["style"]
    content_server = (job["content_server"] or {"hostname": None})["hostname"]

    # Write out files
    write_file(os.path.join(dest_path, "id"), job_id)
    write_file(os.path.join(dest_path, "collection_id"), collection_id)
    write_file(os.path.join(dest_path, "version"), collection_version)
    write_file(os.path.join(dest_path, "collection_style"), collection_style)
    write_file(os.path.join(dest_path, "content_server"), content_server)
    write_file(os.path.join(dest_path, "job.json"), job)

    return {"version": {"id": job_id}}
Example #9
0
def main():
    dest_path = sys.argv[1]
    msg("Output dir {}", dest_path)
    version = in_(dest_path, sys.stdin)
    print(json.dumps(version))
Example #10
0
def main():
    src_path = sys.argv[1]
    msg("Source dir {}", src_path)
    print(json.dumps(out(src_path, sys.stdin)))
def update_job(api_root, job_id, data):
    url = build_url(api_root, "jobs", job_id)
    response = requests.put(url, data=json.dumps(data))
    msg(response.text)
    return response.json()
def get_job(api_root, job_id):
    url = build_url(api_root, "jobs", job_id)
    response = requests.get(url)
    msg(response.text)
    return response.json()
Example #13
0
def update_event(api_root, event_id, data):
    url = build_url(api_root, "events", event_id)
    response = requests.put(url, data=json.dumps(data))
    msg(response.text)
    return response.json()
Example #14
0
def get_event(api_root, event_id):
    url = build_url(api_root, "events", event_id)
    response = requests.get(url)
    msg(response.text)
    return response.json()