8000 functions/slack: config file -> env vars by ace-n · Pull Request #3695 · GoogleCloudPlatform/python-docs-samples · GitHub
[go: up one dir, main page]

Skip to content

functions/slack: config file -> env vars #3695

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
merged 1 commit into from
May 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions functions/ocr/app/config.json

This file was deleted.

17 changes: 7 additions & 10 deletions functions/ocr/app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

from google.cloud import pubsub_v1
from google.cloud import storage
from google.cloud import translate
from google.cloud import translate_v2 as translate
from google.cloud import vision

vision_client = vision.ImageAnnotatorClient()
Expand All @@ -27,10 +27,6 @@
storage_client = storage.Client()

project_id = os.environ['GCP_PROJECT']

with open('config.json') as f:
data = f.read()
config = json.loads(data)
# [END functions_ocr_setup]


Expand All @@ -55,10 +51,11 @@ def detect_text(bucket, filename):
print('Detected language {} for text {}.'.format(src_lang, text))

# Submit a message to the bus for each target language
for target_lang in config.get('TO_LANG', []):
topic_name = config['TRANSLATE_TOPIC']
to_langs = os.environ['TO_LANG'].split(',')
for target_lang in to_langs:
topic_name = os.environ['TRANSLATE_TOPIC']
if src_lang == target_lang or src_lang == 'und':
topic_name = config['RESULT_TOPIC']
topic_name = os.environ['RESULT_TOPIC']
message = {
'text': text,
'filename': filename,
Expand Down Expand Up @@ -120,7 +117,7 @@ def translate_text(event, context):
translated_text = translate_client.translate(text,
target_language=target_lang,
source_language=src_lang)
topic_name = config['RESULT_TOPIC']
topic_name = os.environ['RESULT_TOPIC']
message = {
'text': translated_text['translatedText'],
'filename': filename,
Expand All @@ -147,7 +144,7 @@ def save_result(event, context):

print('Received request to save file {}.'.format(filename))

bucket_name = config['RESULT_BUCKET']
bucket_name = os.environ['RESULT_BUCKET']
result_filename = '{}_{}.txt'.format(filename, lang)
bucket = storage_client.get_bucket(bucket_name)
blob = bucket.blob(result_filename)
Expand Down
0