def result_to_json_file(): work_order = models.EsiWorkOrder( name="result_to_json_file", output_path="samples/order_output/${ewo_name}", description=("An example of saving the raw results to a json file."), ) job = models.EsiJob( op_id="get_markets_region_id_history", parameters={ "region_id": 10000002, "type_id": 34 }, ) work_order.jobs.append(job) job.callbacks.success.append( models.JobCallback(callback_id="response_content_to_json")) job.callbacks.success.append( models.JobCallback( callback_id="save_result_to_json_file", kwargs={ "file_path_template": "data/market-history/${region_id}-${type_id}.json" }, )) job.callbacks.fail.append( models.JobCallback(callback_id="response_to_esi_job")) job.callbacks.fail.append( models.JobCallback(callback_id="log_job_failure")) return work_order
def result_with_pages_to_json_file(): work_order = models.EsiWorkOrder( name="result_with_pages_to_json_file", output_path="samples/order_output/${ewo_name}", description= ("An example of saving the raw results with a paged api to a json file." ), ) job = models.EsiJob( op_id="get_contracts_public_region_id", parameters={"region_id": 10000002}, ) work_order.jobs.append(job) job.callbacks.success.append( models.JobCallback(callback_id="response_content_to_json")) job.callbacks.success.append( models.JobCallback(callback_id="check_for_pages")) job.callbacks.success.append( models.JobCallback( callback_id="save_result_to_json_file", kwargs={ "file_path_template": "data/public-contracts/${region_id}.json" }, )) job.callbacks.fail.append( models.JobCallback(callback_id="response_to_esi_job")) job.callbacks.fail.append( models.JobCallback(callback_id="log_job_failure")) return work_order
def bad_validation_workorder(): ewo = models.EsiWorkOrder( name="bad-validation-workorder", description="A workorder that contains jobs that will fail validation.", id_="bad-validation-workorder", output_path="samples/workorder_output/${ewo_name}", ) ewo.jobs.append(missing_parameter_job()) return ewo
def bad_status_workorder(): ewo = models.EsiWorkOrder( name="bad-status-workorder", description=( "A workorder that contains jobs that will fail on the server " "in various ways."), id_="bad-status-workorder", output_path="samples/workorder_output/${ewo_name}", ) ewo.jobs.append(bad_parameter_job()) return ewo
def result_to_csv_file(): work_order = models.EsiWorkOrder( name="result_to_csv_file", output_path="samples/order_output/${ewo_name}", description=( "An example of saving the json results to a csv file. Also, shows " "reordering columns, and adding additional columns"), ) job = models.EsiJob( op_id="get_markets_region_id_history", parameters={ "region_id": 10000002, "type_id": 34 }, ) work_order.jobs.append(job) job.callbacks.success.append( models.JobCallback(callback_id="response_content_to_json")) job.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": "data/market-history/${region_id}-${type_id}.csv", }, )) job.callbacks.fail.append( models.JobCallback(callback_id="response_to_esi_job")) job.callbacks.fail.append( models.JobCallback(callback_id="log_job_failure")) return work_order
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 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