|
| 1 | +# Copyright 2020 Google LLC |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# https://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | + |
| 15 | +# [START job_search_batch_create_jobs] |
| 16 | + |
| 17 | +from google.cloud import talent |
| 18 | +import six |
| 19 | + |
| 20 | + |
| 21 | +def batch_create_jobs( |
| 22 | + project_id, |
| 23 | + tenant_id, |
| 24 | + company_name_one, |
| 25 | + requisition_id_one, |
| 26 | + title_one, |
| 27 | + description_one, |
| 28 | + job_application_url_one, |
| 29 | + address_one, |
| 30 | + language_code_one, |
| 31 | + company_name_two, |
| 32 | + requisition_id_two, |
| 33 | + title_two, |
| 34 | + description_two, |
| 35 | + job_application_url_two, |
| 36 | + address_two, |
| 37 | + language_code_two, |
| 38 | +): |
| 39 | + """ |
| 40 | + Batch Create Jobs |
| 41 | +
|
| 42 | + Args: |
| 43 | + project_id Your Google Cloud Project ID |
| 44 | + tenant_id Identifier of the Tenant |
| 45 | + """ |
| 46 | + |
| 47 | + client = talent.JobServiceClient() |
| 48 | + |
| 49 | + # project_id = 'Your Google Cloud Project ID' |
| 50 | + # tenant_id = 'Your Tenant ID (using tenancy is optional)' |
| 51 | + # company_name_one = 'Company name, e.g. projects/your-project/companies/company-id' |
| 52 | + # requisition_id_one = 'Job requisition ID, aka Posting ID. Unique per job.' |
| 53 | + # title_one = 'Software Engineer' |
| 54 | + # description_one = 'This is a description of this <i>wonderful</i> job!' |
| 55 | + # job_application_url_one = 'https://www.example.org/job-posting/123' |
| 56 | + # address_one = '1600 Amphitheatre Parkway, Mountain View, CA 94043' |
| 57 | + # language_code_one = 'en-US' |
| 58 | + # company_name_two = 'Company name, e.g. projects/your-project/companies/company-id' |
| 59 | + # requisition_id_two = 'Job requisition ID, aka Posting ID. Unique per job.' |
| 60 | + # title_two = 'Quality Assurance' |
| 61 | + # description_two = 'This is a description of this <i>wonderful</i> job!' |
| 62 | + # job_application_url_two = 'https://www.example.org/job-posting/123' |
| 63 | + # address_two = '111 8th Avenue, New York, NY 10011' |
| 64 | + # language_code_two = 'en-US' |
| 65 | + |
| 66 | + if isinstance(project_id, six.binary_type): |
| 67 | + project_id = project_id.decode("utf-8") |
| 68 | + if isinstance(tenant_id, six.binary_type): |
| 69 | + tenant_id = tenant_id.decode("utf-8") |
| 70 | + if isinstance(company_name_one, six.binary_type): |
| 71 | + company_name_one = company_name_one.decode("utf-8") |
| 72 | + if isinstance(requisition_id_one, six.binary_type): |
| 73 | + requisition_id_one = requisition_id_one.decode("utf-8") |
| 74 | + if isinstance(title_one, six.binary_type): |
| 75 | + title_one = title_one.decode("utf-8") |
| 76 | + if isinstance(description_one, six.binary_type): |
| 77 | + description_one = description_one.decode("utf-8") |
| 78 | + if isinstance(job_application_url_one, six.binary_type): |
| 79 | + job_application_url_one = job_application_url_one.decode("utf-8") |
| 80 | + if isinstance(address_one, six.binary_type): |
| 81 | + address_one = address_one.decode("utf-8") |
| 82 | + if isinstance(language_code_one, six.binary_type): |
| 83 | + language_code_one = language_code_one.decode("utf-8") |
| 84 | + if isinstance(company_name_two, six.binary_type): |
| 85 | + company_name_two = company_name_two.decode("utf-8") |
| 86 | + if isinstance(requisition_id_two, six.binary_type): |
| 87 | + requisition_id_two = requisition_id_two.decode("utf-8") |
| 88 | + if isinstance(title_two, six.binary_type): |
| 89 | + title_two = title_two.decode("utf-8") |
| 90 | + if isinstance(description_two, six.binary_type): |
| 91 | + description_two = description_two.decode("utf-8") |
| 92 | + if isinstance(job_application_url_two, six.binary_type): |
| 93 | + job_application_url_two = job_application_url_two.decode("utf-8") |
| 94 | + if isinstance(address_two, six.binary_type): |
| 95 | + address_two = address_two.decode("utf-8") |
| 96 | + if isinstance(language_code_two, six.binary_type): |
| 97 | + language_code_two = language_code_two.decode("utf-8") |
| 98 | + parent = client.tenant_path(project_id, tenant_id) |
| 99 | + uris = [job_application_url_one] |
| 100 | + application_info = {"uris": uris} |
| 101 | + addresses = [address_one] |
| 102 | + jobs_element = { |
| 103 | + "company": company_name_one, |
| 104 | + "requisition_id": requisition_id_one, |
| 105 | + "title": title_one, |
| 106 | + "description": description_one, |
| 107 | + "application_info": application_info, |
| 108 | + "addresses": addresses, |
| 109 | + "language_code": language_code_one, |
| 110 | + } |
| 111 | + uris_2 = [job_application_url_two] |
| 112 | + application_info_2 = {"uris": uris_2} |
| 113 | + addresses_2 = [address_two] |
| 114 | + jobs_element_2 = { |
| 115 | + "company": company_name_two, |
| 116 | + "requisition_id": requisition_id_two, |
| 117 | + "title": title_two, |
| 118 | + "description": description_two, |
| 119 | + "application_info": application_info_2, |
| 120 | + "addresses": addresses_2, |
| 121 | + "language_code": language_code_two, |
| 122 | + } |
| 123 | + jobs = [jobs_element, jobs_element_2] |
| 124 | + |
| 125 | + operation = client.batch_create_jobs(parent, jobs) |
| 126 | + |
| 127 | + print("Waiting for operation to complete...") |
| 128 | + response = operation.result(90) |
| 129 | + |
| 130 | + print("Batch response: {}".format(response)) |
| 131 | + |
| 132 | + |
| 133 | +# [END job_search_batch_create_jobs] |
0 commit comments