Exemple #1
0
def post_universe_names(
    callbacks: Optional[models.CallbackCollection] = None, ):
    if callbacks is None:
        callbacks = default_callback_collection()
        callbacks.success.append(
            models.JobCallback(
                callback_id="save_esi_job_to_json_file",
                kwargs={
                    "file_path_template":
                    "data/post_universe_names-${esi_job_uid}-esi-job.json"
                },
            ))
        callbacks.success.append(
            models.JobCallback(
                callback_id="save_result_to_json_file",
                kwargs={
                    "file_path_template":
                    "data/post_universe_names-${esi_job_uid}.json"
                },
            ))
    job = models.EsiJob(
        op_id="post_universe_names",
        name="post_universe_names",
        callbacks=callbacks,
    )
    job.parameters = {"ids": [95465499, 30000142]}
    return job
Exemple #2
0
def get_markets_region_id_history(
    region_id: int,
    type_id: int,
    callbacks: Optional[models.CallbackCollection] = None,
):
    if callbacks is None:
        callbacks = default_callback_collection()
        callbacks.success.append(
            models.JobCallback(
                callback_id="save_esi_job_to_json_file",
                kwargs={
                    "file_path_template":
                    "data/market-history-${region_id}-${type_id}-esi-job.json"
                },
            ))
        callbacks.success.append(
            models.JobCallback(
                callback_id="save_result_to_json_file",
                kwargs={
                    "file_path_template":
                    "data/market-history-${region_id}-${type_id}-esi-job.json"
                },
            ))
    job = models.EsiJob(
        op_id="get_markets_region_id_history",
        name="get_markets_region_id_history",
        callbacks=callbacks,
    )
    job.parameters = {"region_id": region_id, "type_id": type_id}
    return job
Exemple #3
0
def example():
    # If the ESI schema does not exist locally, download and save it.
    PATH_TO_SCHEMA: Path = Path.home() / Path("tmp/esi-schema.json")
    if PATH_TO_SCHEMA.is_file():
        schema = PATH_TO_SCHEMA.read_text()
    else:
        URL = "https://esi.evetech.net/latest/swagger.json"
        with urllib.request.urlopen(URL) as response:
            schema_bytes = response.read()
            PATH_TO_SCHEMA.parent.mkdir(parents=True, exist_ok=True)
            PATH_TO_SCHEMA.write_bytes(schema_bytes)
            print(f"Downloaded schema from {URL}")
            schema = PATH_TO_SCHEMA.read_text()
            print(f"Schema saved to {PATH_TO_SCHEMA}")

    schema_json = json.loads(schema)
    operation_manifest = OperationManifest(schema_json)

    workorder = models.EsiWorkOrder()
    workorder.name = "Script-Example"
    workorder.id_ = "script_example"
    # not used for this example, as the default_callback_collection()
    # has no file output callbacks.
    workorder.output_path = "${ewo_name}/output/"

    job_1 = models.EsiJob(op_id="get_markets_region_id_history")
    job_1.name = "First-Job"
    job_1.parameters = {"region_id": 10000002, "type_id": 34}
    job_1.callbacks = default_callback_collection()
    workorder.jobs.append(job_1)

    job_2 = models.EsiJob(op_id="get_markets_region_id_history")
    job_2.name = "Second-Job"
    job_2.parameters = {"region_id": 10000002, "type_id": 36}
    job_2.callbacks = default_callback_collection()
    workorder.jobs.append(job_2)

    do_workorder(workorder, operation_manifest)

    print(workorder.name)
    for job in workorder.jobs:
        print(job.name)
        print(job.result.data[:3])
def missing_parameter_job():
    job = models.EsiJob(
        name="missing-parameter",
        description=
        "A job with a missing parameter, should result in a validation failure.",
        id_="missing-parameter",
        op_id="get_markets_region_id_history",
        parameters={"region_id": 10000002},
        callbacks=default_callback_collection(),
    )
    return job
def bad_parameter_job():
    job = models.EsiJob(
        name="bad-parameter",
        description=
        "A job with a bad parameter, should result in a 400 bad request.",
        id_="bad-parameter",
        op_id="get_markets_region_id_history",
        parameters={
            "region_id": 10000002,
            "type_id": 0
        },
        callbacks=default_callback_collection(),
    )
    return job
Exemple #6
0
def get_industry_systems(
    callbacks: Optional[models.CallbackCollection] = None, ):
    if callbacks is None:
        callbacks = default_callback_collection()
        callbacks.success.append(
            models.JobCallback(
                callback_id="save_esi_job_to_json_file",
                kwargs={
                    "file_path_template": "data/industry-systems-esi-job.json"
                },
            ))
        callbacks.success.append(
            models.JobCallback(
                callback_id="save_result_to_json_file",
                kwargs={"file_path_template": "data/industry-systems.json"},
            ))
    job = models.EsiJob(
        op_id="get_industry_systems",
        name="get_industry_systems",
        callbacks=callbacks,
    )
    return job
def example_workorder():

    region_id = 10000002
    type_id = 34
    work_order = models.EsiWorkOrder(
        name="example_workorder",
        output_path="samples/workorder_output/${ewo_name}",
        description=
        ("An example of a workorder, with a collection of "
         "jobs whose output is gathered under a file path defined in the workorder."
         ),
    )
    job = get_markets_region_id_history(region_id, type_id,
                                        default_callback_collection())
    job.name = "Save market history as json"
    job.id_ = 1
    job.description = ("Get the market history for Tritainium in The Forge "
                       "region, and save it to a json file.")
    job.callbacks.success.append(
        models.JobCallback(
            callback_id="save_result_to_json_file",
            kwargs={
                "file_path_template":
                "${esi_job_id_}/market-history-${region_id}-${type_id}-esi-job.json"
            },
        ))
    job.callbacks.success.append(
        models.JobCallback(
            callback_id="save_result_to_yaml_file",
            kwargs={
                "file_path_template":
                "${esi_job_id_}/market-history-${region_id}-${type_id}-esi-job.yaml"
            },
        ))

    work_order.jobs.append(job)
    #####
    job_2 = get_markets_region_id_history(region_id, type_id,
                                          default_callback_collection())
    job_2.name = "Save market history and job as json"
    job_2.id_ = 2
    job_2.description = (
        "Get the market history for Tritainium in The Forge "
        "region, and save it to a json file. Also save the job,"
        " including the response metadata, to a separate json file.")
    job_2.callbacks.success.append(
        models.JobCallback(
            callback_id="save_esi_job_to_json_file",
            kwargs={
                "file_path_template":
                "${esi_job_id_}/market-history-${region_id}-${type_id}-esi-job.json"
            },
        ))
    job_2.callbacks.success.append(
        models.JobCallback(
            callback_id="save_result_to_json_file",
            kwargs={
                "file_path_template":
                "${esi_job_id_}/market-history-${region_id}-${type_id}.json"
            },
        ))
    work_order.jobs.append(job_2)
    #####
    job_3 = get_markets_region_id_history(region_id, type_id,
                                          default_callback_collection())
    job_3.name = "Save market history as csv and job with data as json"
    job_3.id_ = 3
    job_3.description = (
        "Get the market history for Tritainium in The Forge "
        "region, and save it to a csv file. The region_id and type_id added to each row, "
        "and the columns are given a custom order. "
        "Also save the job, including the response metadata and the result data, "
        "to a separate json file.")
    job_3.callbacks.success.append(
        models.JobCallback(callback_id="result_to_esi_job"))
    job_3.callbacks.success.append(
        models.JobCallback(
            callback_id="save_esi_job_to_json_file",
            kwargs={
                "file_path_template":
                "${esi_job_id_}/market-history-${region_id}-${type_id}-esi-job.json"
            },
        ))
    job_3.callbacks.success.append(
        models.JobCallback(
            callback_id="save_list_of_dict_result_to_csv_file",
            kwargs={
                "additional_fields": {
                    "region_id": 10000002,
                    "type_id": 34
                },
                "field_names": [
                    "date",
                    "average",
                    "highest",
                    "lowest",
                    "order_count",
                    "volume",
                    "region_id",
                    "type_id",
                ],
                "file_path_template":
                "${esi_job_id_}/market-history-${region_id}-${type_id}.csv",
            },
        ))
    work_order.jobs.append(job_3)
    #####
    job_4 = models.EsiJob(
        name="get paged data",
        description="Get the all the pages from a paged api.",
        id_=4,
        op_id="get_contracts_public_region_id",
        parameters={"region_id": 10000002},
        callbacks=default_callback_collection(),
    )
    job_4.callbacks.success.append(
        models.JobCallback(callback_id="check_for_pages"))
    job_4.callbacks.success.append(
        models.JobCallback(
            callback_id="save_result_to_json_file",
            kwargs={
                "file_path_template":
                "${esi_job_id_}/public-contracts/${region_id}.json"
            },
        ))
    work_order.jobs.append(job_4)
    return work_order