CoolFace
Apppublic

pvanand/hf-model-chat-copy-2

sourceHugging Faceupdated 3y agoView on Hugging Face
0likes
dir_script.py32 linesDownload Raw Back to root
1import os2import datetime3import boto34import time5from botocore.exceptions import ClientError6import json7 8AWS_ACCESS_KEY_ID = os.environ['aws_key']9AWS_SECRET_ACCESS_KEY = os.environ['aws_secret']10BUCKET_NAME = 'app-data-storage-354897'11 12def upload_to_s3(current_time):13    local_file_path = "/db/rasa/rasa.db" 14    s3_object_key = f'data_{current_time}.db'15  16    try:17        s3 = boto3.client('s3', aws_access_key_id=AWS_ACCESS_KEY_ID, aws_secret_access_key=AWS_SECRET_ACCESS_KEY)18        s3.upload_file(local_file_path, BUCKET_NAME, s3_object_key)19        print(f"Uploaded '{local_file_path}' to '{s3_object_key}' in bucket '{BUCKET_NAME}' at {current_time}")20    except FileNotFoundError:21        print(f"Local file '{local_file_path}' not found at {current_time}")22    except ClientError as e:23        print(f"An error occurred during S3 upload: {e} at {current_time}")24 25if __name__ == '__main__':26    while True:27        current_time = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")28        time.sleep(120)29        print("-" * 20)30        upload_to_s3(current_time)31        print("-" * 20)32        time.sleep(12*60*60)