Skip to content

Commit

Permalink
testing send image to api
Browse files Browse the repository at this point in the history
  • Loading branch information
patriciacatandi committed Jun 15, 2024
1 parent f163d89 commit 62b6cc1
Showing 1 changed file with 31 additions and 3 deletions.
34 changes: 31 additions & 3 deletions pipelines/rj_cor/meteorologia/satelite/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
from pathlib import Path
from typing import Union

import requests

import pandas as pd
import pendulum
from prefect import task
Expand All @@ -28,9 +30,9 @@
get_variable_values,
remap_g16,
save_data_in_file,
upload_image_to_api,
# upload_image_to_api,
)
from pipelines.utils.utils import log
from pipelines.utils.utils import log, get_vault_secret


@task()
Expand Down Expand Up @@ -248,6 +250,32 @@ def create_image_and_upload_to_api(info: dict, output_filepath: Path):
save_image_path = create_and_save_image(data, info, var)

log(f"\nStart uploading image for variable {var} on API\n")
upload_image_to_api(var, save_image_path, point_value)
# upload_image_to_api(var, save_image_path, point_value)
var = "cp" if var == "cape" else var

log("Getting API url")
url_secret = get_vault_secret("rionowcast")["data"]
log(f"urlsecret1 {url_secret}")
url_secret = url_secret["url_api_satellite_products"]
log(f"urlsecret2 {url_secret}")
api_url = f"{url_secret}/{var.lower()}"
log(
f"\n Sending image {save_image_path} to API: {api_url} with value {point_value}\n"
)

payload = {"value": point_value}

# Convert from Path to string
save_image_path = str(save_image_path)

with open(save_image_path, "rb") as image_file:
files = {"image": (save_image_path, image_file, "image/jpeg")}
response = requests.post(api_url, data=payload, files=files)

if response.status_code == 200:
print("Finished the request successful!")
print(response.json())

Check failure

Code scanning / CodeQL

Clear-text logging of sensitive information High

This expression logs
sensitive data (secret)
as clear text.
This expression logs
sensitive data (secret)
as clear text.
This expression logs
sensitive data (secret)
as clear text.
else:
print(f"Error: {response.status_code}, {response.text}")

Check failure

Code scanning / CodeQL

Clear-text logging of sensitive information High

This expression logs
sensitive data (secret)
as clear text.
This expression logs
sensitive data (secret)
as clear text.
This expression logs
sensitive data (secret)
as clear text.
log(save_image_path)
log(f"\nEnd uploading image for variable {var} on API\n")

0 comments on commit 62b6cc1

Please sign in to comment.