Spaces:
Runtime error
Runtime error
Download dir_script.py from pvanand/hf-model-chat-copy-2: direct link, hf CLI and curl.
- Browser
- Download file 1.13 kB
-
https://huggingface.co/spaces/pvanand/hf-model-chat-copy-2/resolve/main/dir_script.py
- Command line
-
hf download hf://spaces/pvanand/hf-model-chat-copy-2/dir_script.py
-
curl -L -o dir_script.py https://huggingface.co/spaces/pvanand/hf-model-chat-copy-2/resolve/main/dir_script.py
1.13 kB
| import os | |
| import datetime | |
| import boto3 | |
| import time | |
| from botocore.exceptions import ClientError | |
| import json | |
| AWS_ACCESS_KEY_ID = os.environ['aws_key'] | |
| AWS_SECRET_ACCESS_KEY = os.environ['aws_secret'] | |
| BUCKET_NAME = 'app-data-storage-354897' | |
| def upload_to_s3(current_time): | |
| local_file_path = "/db/rasa/rasa.db" | |
| s3_object_key = f'data_{current_time}.db' | |
| try: | |
| s3 = boto3.client('s3', aws_access_key_id=AWS_ACCESS_KEY_ID, aws_secret_access_key=AWS_SECRET_ACCESS_KEY) | |
| s3.upload_file(local_file_path, BUCKET_NAME, s3_object_key) | |
| print(f"Uploaded '{local_file_path}' to '{s3_object_key}' in bucket '{BUCKET_NAME}' at {current_time}") | |
| except FileNotFoundError: | |
| print(f"Local file '{local_file_path}' not found at {current_time}") | |
| except ClientError as e: | |
| print(f"An error occurred during S3 upload: {e} at {current_time}") | |
| if __name__ == '__main__': | |
| while True: | |
| current_time = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S") | |
| time.sleep(120) | |
| print("-" * 20) | |
| upload_to_s3(current_time) | |
| print("-" * 20) | |
| time.sleep(12*60*60) |