Spaces:
Running
on
Zero
Running
on
Zero
import os | |
from line_data_retriever import LineDataRetriever | |
from image_saver import ImageSaver | |
from s3_uploader import S3Uploader | |
def main(): | |
line_api_token = os.environ["LINE_API_TOKEN"] | |
aws_access_key_id = os.environ["AWS_ACCESS_KEY_ID"] | |
aws_secret_access_key = os.environ["AWS_SECRET_ACCESS_KEY"] | |
bucket_name = os.environ["S3_BUCKET_NAME"] | |
retriever = LineDataRetriever(line_api_token) | |
data = retriever.retrieve_data() | |
for message in data["messages"]: | |
if message["type"] == "image": | |
image_data = message["image"] | |
saver = ImageSaver(image_data) | |
file_path = "temp.jpg" | |
saver.save_image(file_path) | |
uploader = S3Uploader(aws_access_key_id, aws_secret_access_key, bucket_name) | |
key = f"images/{os.path.basename(file_path)}" | |
uploader.upload_file(file_path, key) | |
os.remove(file_path) | |
if __name__ == "__main__": | |
main() |