-
Notifications
You must be signed in to change notification settings - Fork 6.5k
Talent v4beta1 samples [Restoring deleted branch samples] #3273
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
tmatsuo
merged 44 commits into
GoogleCloudPlatform:master
from
munkhuushmgl:talent-v4beta1-samples
May 21, 2020
Merged
Changes from 7 commits
Commits
Show all changes
44 commits
Select commit
Hold shift + click to select a range
fcbd9f3
restored deleted samples
munkhuushmgl fed3630
fixed lint issues
munkhuushmgl a9d5334
added tests and formatted code
munkhuushmgl ffa5704
Merge branch 'master' into talent-v4beta1-samples
munkhuushmgl 2ac12c2
corrected test req.txt file
munkhuushmgl c05d682
Merge branch 'talent-v4beta1-samples' of https://github.com/munkhuush…
munkhuushmgl 6e79a1a
Merge branch 'master' into talent-v4beta1-samples
69a175b
made requested changes and added return val for samples
munkhuushmgl ea51187
Merge branch 'talent-v4beta1-samples' of https://github.com/munkhuush…
munkhuushmgl 84dcd99
Merge branch 'master' into talent-v4beta1-samples
munkhuushmgl e8a67b0
added secrets.txt to bash, script
munkhuushmgl 3f28e5e
Merge branch 'talent-v4beta1-samples' of https://github.com/munkhuush…
munkhuushmgl 64f06af
fixed the lint
munkhuushmgl 6f4fe16
Merge branch 'master' into talent-v4beta1-samples
munkhuushmgl 7d22192
Merge branch 'master' into talent-v4beta1-samples
88ff29e
moved to requirements-test.txt
5340974
delete resources in teardown just in case
e454c4e
Merge branch 'master' into talent-v4beta1-samples
3a3efe9
restored deleted samples
munkhuushmgl ee75d23
resolved the conflicts
munkhuushmgl 8974b3d
added some spacing
munkhuushmgl 69d471a
Merge branch 'master' into talent-v4beta1-samples
munkhuushmgl b41139d
restored deleted samples
munkhuushmgl 68c1c93
fixed merge conflicts
munkhuushmgl c44b313
fixed merge conflicts
munkhuushmgl 64a71ae
Merge branch 'master' into talent-v4beta1-samples
munkhuushmgl ef7be49
added conftest.py and refactored samples with loop
munkhuushmgl 6dd6793
Merge branch 'talent-v4beta1-samples' of https://github.com/munkhuush…
munkhuushmgl a133f36
removed talent secret.txt from bash script
munkhuushmgl 640151f
Merge branch 'master' into talent-v4beta1-samples
munkhuushmgl ab3bf67
fixed the lint issue
munkhuushmgl db5d438
Merge branch 'talent-v4beta1-samples' of https://github.com/munkhuush…
munkhuushmgl 72540a8
removed unnecessary env vars
munkhuushmgl 489d96c
deleted global random ids, deleted unnecessary setup code from delete…
munkhuushmgl 642aa6c
Merge branch 'master' into talent-v4beta1-samples
munkhuushmgl 15ad14a
removed unused imports
munkhuushmgl 55ec1cc
Merge branch 'talent-v4beta1-samples' of https://github.com/munkhuush…
munkhuushmgl 75ce337
removed pytest
munkhuushmgl e117bf4
removed unused IDs
munkhuushmgl 6e05a60
Merge branch 'master' into talent-v4beta1-samples
munkhuushmgl 7ec8505
deleted unused uuid imports
munkhuushmgl 740f227
Merge branch 'talent-v4beta1-samples' of https://github.com/munkhuush…
munkhuushmgl 76e3762
Merge branch 'master' into talent-v4beta1-samples
munkhuushmgl 6526fbd
Merge branch 'master' into talent-v4beta1-samples
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
# Copyright 2020 Google LLC | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# https://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
# [START job_search_autocomplete_job_title] | ||
|
||
from google.cloud import talent_v4beta1 | ||
from google.cloud.talent import enums | ||
import six | ||
|
||
|
||
def complete_query(project_id, tenant_id, query): | ||
"""Complete job title given partial text (autocomplete)""" | ||
|
||
client = talent_v4beta1.CompletionClient() | ||
|
||
# project_id = 'Your Google Cloud Project ID' | ||
# tenant_id = 'Your Tenant ID (using tenancy is optional)' | ||
# query = '[partially typed job title]' | ||
|
||
if isinstance(project_id, six.binary_type): | ||
project_id = project_id.decode("utf-8") | ||
if isinstance(tenant_id, six.binary_type): | ||
tenant_id = tenant_id.decode("utf-8") | ||
if isinstance(query, six.binary_type): | ||
query = query.decode("utf-8") | ||
|
||
parent = client.tenant_path(project_id, tenant_id) | ||
|
||
response = client.complete_query( | ||
parent, | ||
query, | ||
page_size=5, # limit for number of results | ||
language_codes=["en-US"], # language code | ||
) | ||
for result in response.completion_results: | ||
print("Suggested title: {}".format(result.suggestion)) | ||
# Suggestion type is JOB_TITLE or COMPANY_TITLE | ||
print( | ||
"Suggestion type: {}".format( | ||
enums.CompleteQueryRequest.CompletionType(result.type).name | ||
) | ||
) | ||
|
||
|
||
# [END job_search_autocomplete_job_title] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# Copyright 2020 Google LLC | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
import os | ||
import job_search_autocomplete_job_title | ||
|
||
PROJECT_ID = os.environ["GOOGLE_CLOUD_PROJECT"] | ||
TENANT_ID = "b603d325-3fb5-4979-8994-eba4ecf726f4" | ||
munkhuushmgl marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
|
||
def test_autocomplete_job_title(capsys): | ||
job_search_autocomplete_job_title.complete_query(PROJECT_ID, TENANT_ID, "Software") | ||
out, _ = capsys.readouterr() | ||
assert "Suggested title:" in out |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
# Copyright 2020 Google LLC | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# https://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
# [START job_search_batch_create_jobs] | ||
|
||
from google.cloud import talent | ||
import six | ||
|
||
|
||
def batch_create_jobs( | ||
project_id, | ||
tenant_id, | ||
company_name_one, | ||
requisition_id_one, | ||
title_one, | ||
description_one, | ||
job_application_url_one, | ||
address_one, | ||
language_code_one, | ||
company_name_two, | ||
requisition_id_two, | ||
title_two, | ||
description_two, | ||
job_application_url_two, | ||
address_two, | ||
language_code_two, | ||
): | ||
""" | ||
Batch Create Jobs | ||
|
||
Args: | ||
project_id Your Google Cloud Project ID | ||
tenant_id Identifier of the Tenant | ||
""" | ||
|
||
client = talent.JobServiceClient() | ||
|
||
# project_id = 'Your Google Cloud Project ID' | ||
# tenant_id = 'Your Tenant ID (using tenancy is optional)' | ||
# company_name_one = 'Company name, e.g. projects/your-project/companies/company-id' | ||
# requisition_id_one = 'Job requisition ID, aka Posting ID. Unique per job.' | ||
# title_one = 'Software Engineer' | ||
# description_one = 'This is a description of this <i>wonderful</i> job!' | ||
# job_application_url_one = 'https://www.example.org/job-posting/123' | ||
# address_one = '1600 Amphitheatre Parkway, Mountain View, CA 94043' | ||
# language_code_one = 'en-US' | ||
# company_name_two = 'Company name, e.g. projects/your-project/companies/company-id' | ||
# requisition_id_two = 'Job requisition ID, aka Posting ID. Unique per job.' | ||
# title_two = 'Quality Assurance' | ||
# description_two = 'This is a description of this <i>wonderful</i> job!' | ||
# job_application_url_two = 'https://www.example.org/job-posting/123' | ||
# address_two = '111 8th Avenue, New York, NY 10011' | ||
# language_code_two = 'en-US' | ||
|
||
if isinstance(project_id, six.binary_type): | ||
project_id = project_id.decode("utf-8") | ||
if isinstance(tenant_id, six.binary_type): | ||
tenant_id = tenant_id.decode("utf-8") | ||
if isinstance(company_name_one, six.binary_type): | ||
company_name_one = company_name_one.decode("utf-8") | ||
if isinstance(requisition_id_one, six.binary_type): | ||
requisition_id_one = requisition_id_one.decode("utf-8") | ||
if isinstance(title_one, six.binary_type): | ||
title_one = title_one.decode("utf-8") | ||
if isinstance(description_one, six.binary_type): | ||
description_one = description_one.decode("utf-8") | ||
if isinstance(job_application_url_one, six.binary_type): | ||
job_application_url_one = job_application_url_one.decode("utf-8") | ||
if isinstance(address_one, six.binary_type): | ||
address_one = address_one.decode("utf-8") | ||
if isinstance(language_code_one, six.binary_type): | ||
language_code_one = language_code_one.decode("utf-8") | ||
if isinstance(company_name_two, six.binary_type): | ||
company_name_two = company_name_two.decode("utf-8") | ||
if isinstance(requisition_id_two, six.binary_type): | ||
requisition_id_two = requisition_id_two.decode("utf-8") | ||
if isinstance(title_two, six.binary_type): | ||
title_two = title_two.decode("utf-8") | ||
if isinstance(description_two, six.binary_type): | ||
description_two = description_two.decode("utf-8") | ||
if isinstance(job_application_url_two, six.binary_type): | ||
job_application_url_two = job_application_url_two.decode("utf-8") | ||
if isinstance(address_two, six.binary_type): | ||
address_two = address_two.decode("utf-8") | ||
if isinstance(language_code_two, six.binary_type): | ||
language_code_two = language_code_two.decode("utf-8") | ||
parent = client.tenant_path(project_id, tenant_id) | ||
uris = [job_application_url_one] | ||
application_info = {"uris": uris} | ||
addresses = [address_one] | ||
jobs_element = { | ||
"company": company_name_one, | ||
"requisition_id": requisition_id_one, | ||
"title": title_one, | ||
"description": description_one, | ||
"application_info": application_info, | ||
"addresses": addresses, | ||
"language_code": language_code_one, | ||
} | ||
uris_2 = [job_application_url_two] | ||
application_info_2 = {"uris": uris_2} | ||
addresses_2 = [address_two] | ||
jobs_element_2 = { | ||
"company": company_name_two, | ||
"requisition_id": requisition_id_two, | ||
"title": title_two, | ||
"description": description_two, | ||
"application_info": application_info_2, | ||
"addresses": addresses_2, | ||
"language_code": language_code_two, | ||
} | ||
jobs = [jobs_element, jobs_element_2] | ||
|
||
operation = client.batch_create_jobs(parent, jobs) | ||
|
||
print("Waiting for operation to complete...") | ||
response = operation.result() | ||
|
||
print("Batch response: {}".format(response)) | ||
|
||
|
||
# [END job_search_batch_create_jobs] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,143 @@ | ||
# Copyright 2020 Google LLC | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# https://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
# [START job_search_batch_update_jobs] | ||
|
||
from google.cloud import talent | ||
import six | ||
|
||
|
||
def batch_update_jobs( | ||
project_id, | ||
tenant_id, | ||
job_name_one, | ||
company_name_one, | ||
requisition_id_one, | ||
title_one, | ||
description_one, | ||
job_application_url_one, | ||
address_one, | ||
language_code_one, | ||
job_name_two, | ||
company_name_two, | ||
requisition_id_two, | ||
title_two, | ||
description_two, | ||
job_application_url_two, | ||
address_two, | ||
language_code_two, | ||
): | ||
""" | ||
Batch Update Jobs | ||
|
||
Args: | ||
project_id Your Google Cloud Project ID | ||
tenant_id Identifier of the Tenant | ||
""" | ||
|
||
client = talent.JobServiceClient() | ||
|
||
# project_id = 'Your Google Cloud Project ID' | ||
# tenant_id = 'Your Tenant ID (using tenancy is optional)' | ||
# job_name_one = 'job name, projects/your-project/tenants/tenant-id/jobs/job-id' | ||
# company_name_one = 'Company name, e.g. projects/your-project/companies/company-id' | ||
# requisition_id_one = 'Job requisition ID, aka Posting ID. Unique per job.' | ||
# title_one = 'Software Engineer' | ||
# description_one = 'This is a description of this <i>wonderful</i> job!' | ||
# job_application_url_one = 'https://www.example.org/job-posting/123' | ||
# address_one = '1600 Amphitheatre Parkway, Mountain View, CA 94043' | ||
# language_code_one = 'en-US' | ||
# job_name_two = 'job name, projects/your-project/tenants/tenant-id/jobs/job-id' | ||
# company_name_two = 'Company name, e.g. projects/your-project/companies/company-id' | ||
# requisition_id_two = 'Job requisition ID, aka Posting ID. Unique per job.' | ||
# title_two = 'Quality Assurance' | ||
# description_two = 'This is a description of this <i>wonderful</i> job!' | ||
# job_application_url_two = 'https://www.example.org/job-posting/123' | ||
# address_two = '111 8th Avenue, New York, NY 10011' | ||
# language_code_two = 'en-US' | ||
|
||
if isinstance(project_id, six.binary_type): | ||
project_id = project_id.decode("utf-8") | ||
if isinstance(tenant_id, six.binary_type): | ||
tenant_id = tenant_id.decode("utf-8") | ||
if isinstance(job_name_one, six.binary_type): | ||
job_name_one = job_name_one.decode("utf-8") | ||
if isinstance(company_name_one, six.binary_type): | ||
company_name_one = company_name_one.decode("utf-8") | ||
if isinstance(requisition_id_one, six.binary_type): | ||
requisition_id_one = requisition_id_one.decode("utf-8") | ||
if isinstance(title_one, six.binary_type): | ||
title_one = title_one.decode("utf-8") | ||
if isinstance(description_one, six.binary_type): | ||
description_one = description_one.decode("utf-8") | ||
if isinstance(job_application_url_one, six.binary_type): | ||
job_application_url_one = job_application_url_one.decode("utf-8") | ||
if isinstance(address_one, six.binary_type): | ||
address_one = address_one.decode("utf-8") | ||
if isinstance(language_code_one, six.binary_type): | ||
language_code_one = language_code_one.decode("utf-8") | ||
if isinstance(job_name_two, six.binary_type): | ||
job_name_two = job_name_two.decode("utf-8") | ||
if isinstance(company_name_two, six.binary_type): | ||
company_name_two = company_name_two.decode("utf-8") | ||
if isinstance(requisition_id_two, six.binary_type): | ||
requisition_id_two = requisition_id_two.decode("utf-8") | ||
if isinstance(title_two, six.binary_type): | ||
title_two = title_two.decode("utf-8") | ||
if isinstance(description_two, six.binary_type): | ||
description_two = description_two.decode("utf-8") | ||
if isinstance(job_application_url_two, six.binary_type): | ||
job_application_url_two = job_application_url_two.decode("utf-8") | ||
if isinstance(address_two, six.binary_type): | ||
address_two = address_two.decode("utf-8") | ||
if isinstance(language_code_two, six.binary_type): | ||
language_code_two = language_code_two.decode("utf-8") | ||
parent = client.tenant_path(project_id, tenant_id) | ||
uris = [job_application_url_one] | ||
application_info = {"uris": uris} | ||
addresses = [address_one] | ||
jobs_element = { | ||
"name": job_name_one, | ||
"company": company_name_one, | ||
"requisition_id": requisition_id_one, | ||
"title": title_one, | ||
"description": description_one, | ||
"application_info": application_info, | ||
"addresses": addresses, | ||
"language_code": language_code_one, | ||
} | ||
uris_2 = [job_application_url_two] | ||
application_info_2 = {"uris": uris_2} | ||
addresses_2 = [address_two] | ||
jobs_element_2 = { | ||
"name": job_name_two, | ||
"company": company_name_two, | ||
"requisition_id": requisition_id_two, | ||
"title": title_two, | ||
"description": description_two, | ||
"application_info": application_info_2, | ||
"addresses": addresses_2, | ||
"language_code": language_code_two, | ||
} | ||
jobs = [jobs_element, jobs_element_2] | ||
|
||
operation = client.batch_update_jobs(parent, jobs) | ||
|
||
print("Waiting for operation to complete...") | ||
response = operation.result() | ||
munkhuushmgl marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
print("Batch response: {}".format(response)) | ||
|
||
|
||
# [END job_search_batch_update_jobs] |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.