├── .python-version ├── lottie_animation_manager ├── __init__.py ├── utils.py ├── requirements.txt └── __main__.py ├── lottie_animation_manager.egg-info ├── dependency_links.txt ├── top_level.txt ├── requires.txt ├── entry_points.txt ├── SOURCES.txt └── PKG-INFO ├── documentation_images ├── create_bucket.png ├── get_started.png ├── cloudfront_home.png ├── cloudfront_create.png ├── test_image_asset.png ├── upload_test_image.png ├── create_distribution.png ├── application-screenshot.png ├── deployed_distribution.png └── sample_animation_folder_layout.png ├── dist ├── lottie-animation-manager-0.0.5.tar.gz └── lottie_animation_manager-0.0.5-py3-none-any.whl ├── .gitignore ├── LICENSE.txt ├── setup.py └── README.md /.python-version: -------------------------------------------------------------------------------- 1 | 3.6.5 2 | -------------------------------------------------------------------------------- /lottie_animation_manager/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /lottie_animation_manager.egg-info/dependency_links.txt: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /lottie_animation_manager.egg-info/top_level.txt: -------------------------------------------------------------------------------- 1 | lottie_animation_manager 2 | -------------------------------------------------------------------------------- /lottie_animation_manager.egg-info/requires.txt: -------------------------------------------------------------------------------- 1 | boto>=2.49 2 | click>=7.1 3 | colorama>=0.4 4 | emoji>=0.5 5 | pyfiglet>=0.8 6 | tinify>=1.5 7 | -------------------------------------------------------------------------------- /documentation_images/create_bucket.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bakztfuture/lottie_animation_manager/HEAD/documentation_images/create_bucket.png -------------------------------------------------------------------------------- /documentation_images/get_started.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bakztfuture/lottie_animation_manager/HEAD/documentation_images/get_started.png -------------------------------------------------------------------------------- /documentation_images/cloudfront_home.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bakztfuture/lottie_animation_manager/HEAD/documentation_images/cloudfront_home.png -------------------------------------------------------------------------------- /dist/lottie-animation-manager-0.0.5.tar.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bakztfuture/lottie_animation_manager/HEAD/dist/lottie-animation-manager-0.0.5.tar.gz -------------------------------------------------------------------------------- /documentation_images/cloudfront_create.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bakztfuture/lottie_animation_manager/HEAD/documentation_images/cloudfront_create.png -------------------------------------------------------------------------------- /documentation_images/test_image_asset.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bakztfuture/lottie_animation_manager/HEAD/documentation_images/test_image_asset.png -------------------------------------------------------------------------------- /documentation_images/upload_test_image.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bakztfuture/lottie_animation_manager/HEAD/documentation_images/upload_test_image.png -------------------------------------------------------------------------------- /documentation_images/create_distribution.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bakztfuture/lottie_animation_manager/HEAD/documentation_images/create_distribution.png -------------------------------------------------------------------------------- /documentation_images/application-screenshot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bakztfuture/lottie_animation_manager/HEAD/documentation_images/application-screenshot.png -------------------------------------------------------------------------------- /documentation_images/deployed_distribution.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bakztfuture/lottie_animation_manager/HEAD/documentation_images/deployed_distribution.png -------------------------------------------------------------------------------- /lottie_animation_manager.egg-info/entry_points.txt: -------------------------------------------------------------------------------- 1 | [console_scripts] 2 | lottie-animation-manager = lottie_animation_manager.__main__:initialize_configuration 3 | 4 | -------------------------------------------------------------------------------- /dist/lottie_animation_manager-0.0.5-py3-none-any.whl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bakztfuture/lottie_animation_manager/HEAD/dist/lottie_animation_manager-0.0.5-py3-none-any.whl -------------------------------------------------------------------------------- /documentation_images/sample_animation_folder_layout.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bakztfuture/lottie_animation_manager/HEAD/documentation_images/sample_animation_folder_layout.png -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | .python/ 3 | *.pyc 4 | __pycache__/ 5 | 6 | # virtualenv 7 | .venv/ 8 | venv/ 9 | ENV/ 10 | 11 | # Mac file 12 | .DS_Store 13 | 14 | # Ignore environment variable files for security reasons 15 | .env 16 | -------------------------------------------------------------------------------- /lottie_animation_manager/utils.py: -------------------------------------------------------------------------------- 1 | # get human readable version of a file size 2 | # taken from here: 3 | # https://stackoverflow.com/questions/1094841/reusable-library-to-get-human-readable-version-of-file-size 4 | def sizeof_fmt(num, suffix='B'): 5 | for unit in ['','Ki','Mi','Gi','Ti','Pi','Ei','Zi']: 6 | if abs(num) < 1024.0: 7 | return "%3.1f%s%s" % (num, unit, suffix) 8 | num /= 1024.0 9 | return "%.1f%s%s" % (num, 'Yi', suffix) -------------------------------------------------------------------------------- /lottie_animation_manager/requirements.txt: -------------------------------------------------------------------------------- 1 | astroid==2.3.3 2 | boto==2.49.0 3 | certifi==2019.11.28 4 | chardet==3.0.4 5 | click==7.1.1 6 | colorama==0.4.3 7 | emoji==0.5.4 8 | idna==2.9 9 | importlib-metadata==1.6.0 10 | isort==4.3.21 11 | keyring==21.2.0 12 | lazy-object-proxy==1.4.3 13 | mccabe==0.6.1 14 | pyfiglet==0.8.post1 15 | pylint==2.4.4 16 | requests==2.23.0 17 | six==1.14.0 18 | tinify==1.5.1 19 | typed-ast==1.4.1 20 | urllib3==1.25.8 21 | wrapt==1.11.2 22 | zipp==3.1.0 23 | -------------------------------------------------------------------------------- /lottie_animation_manager.egg-info/SOURCES.txt: -------------------------------------------------------------------------------- 1 | README.md 2 | setup.py 3 | lottie_animation_manager/__init__.py 4 | lottie_animation_manager/__main__.py 5 | lottie_animation_manager/utils.py 6 | lottie_animation_manager.egg-info/PKG-INFO 7 | lottie_animation_manager.egg-info/SOURCES.txt 8 | lottie_animation_manager.egg-info/dependency_links.txt 9 | lottie_animation_manager.egg-info/entry_points.txt 10 | lottie_animation_manager.egg-info/requires.txt 11 | lottie_animation_manager.egg-info/top_level.txt -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 BAKHTAWAR AWAN 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | import setuptools 2 | 3 | with open("README.md", "r") as fh: 4 | long_description = fh.read() 5 | 6 | setuptools.setup( 7 | name="lottie-animation-manager", # Replace with your own username 8 | version="0.0.5", 9 | author="Bakz T. Future", 10 | author_email="bakztfuture@gmail.com", 11 | description="The easiest way to manage, compress, and upload Lottie assets to a CDN.", 12 | long_description=long_description, 13 | long_description_content_type="text/markdown", 14 | url="https://github.com/bakztfuture/lottie_animation_manager", 15 | packages=setuptools.find_packages(), 16 | classifiers=[ 17 | "Development Status :: 3 - Alpha", 18 | "Programming Language :: Python :: 3", 19 | "License :: OSI Approved :: MIT License", 20 | "Operating System :: OS Independent", 21 | ], 22 | entry_points = { 23 | "console_scripts": [ 24 | "lottie-animation-manager = lottie_animation_manager.__main__:initialize_configuration", 25 | ] 26 | }, 27 | install_requires=[ 28 | 'boto>=2.49', 29 | 'click>=7.1', 30 | 'colorama>=0.4', 31 | 'emoji>=0.5', 32 | 'pyfiglet>=0.8', 33 | 'tinify>=1.5' 34 | ], 35 | python_requires='>=3.6', 36 | keywords='lottie animations bodymovin cloudfront cdn', 37 | ) -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Lottie Animation Manager :rocket: 2 | The easiest way to manage, compress, and upload Lottie assets to a CDN 3 | 4 | ![alt text](documentation_images/application-screenshot.png "Lottie Animation Manager Command Line Application Screenshot") 5 | 6 | # Philosophy 7 | Lottie Animation Manager was created to provide a new way of hosting and managing Lottie Animation Assets. Instead of including all lottie animations inside of the `static` folder in an application, we think all animation assets should be hosted on a CDN (content delivery network). 8 | 9 | This way, updates to animation assets don't require changes to the code repository or static asset folder. This also reduces the overall build size of an application, reducing the website load time for every user session. 10 | 11 | Lottie Animation Manager is the first half of a larger plan. Soon, there will be a companion Vue library as well which will let you easily reference your lottie assets hosted on a CDN from inside of your Vue Application. 12 | 13 | # Features 14 | - Upload your lottie animation assets to AWS S3 + Cloudfront CDN with a single command 15 | - Automatically compress image assets using TinyPNG to save load time before they are uploaded 16 | 17 | # Setup/Installation 18 | Simply install the Lottie Animation Manager library through **pip**: 19 | ```bash 20 | # most common way: 21 | pip install lottie-animation-manager 22 | # for people who have multiple versions of python: 23 | pip3 install lottie-animation-manager 24 | ``` 25 | # Usage 26 | 1. Install the [AWS CLI](https://docs.aws.amazon.com/cli/latest/userguide/install-linux.html) 27 | ``` 28 | pip3 install awscli --upgrade --user 29 | ``` 30 | 2. Configure / Add your AWS Security Access Keys by entering: 31 | ``` 32 | aws configure 33 | ``` 34 | 3. Now, using `cd` , navigate to your folder with your lottie asset (which was exported by the Bodymovin plugin). Your folder layout might look something like this: 35 | ![alt text](documentation_images/sample_animation_folder_layout.png "Example Lottie Animation Export Directory") 36 | 5. Call the python application from your command line like so from inside this animation directory: 37 | ``` 38 | lottie-animation-manager 39 | ``` 40 | 6. Once the application loads, follow the steps in the lottie animation wizard to upload, compress, and manage your assets to Cloudfront CDN :tada: 41 | 42 | # AWS Cloudfront CDN Setup (Background) 43 | Create an AWS Cloudfront deployment so that your lottie applications can load quickly worldwide whenever they are called within your application. 44 | Basic instructions to do this: 45 | 1. Create your AWS security keys by visiting `Your account Name > My Security Credentials` at the top, clicking `Access Keys`, and clicking `Create New Access Key` . Write down of these securities as you can only see them one time. 46 | 2. Create a basic [s3 bucket](https://s3.console.aws.amazon.com/s3/bucket/create): 47 | ![alt text](documentation_images/create_bucket.png "Create basic S3 bucket") 48 | image above is incorrect, disable block all public access 49 | 3. Uploaded an image asset and set it to read permission `everyone` 50 | ![alt text](documentation_images/upload_test_image.png "Upload a test image") 51 | 4. Visit [AWS Cloudfront](https://console.aws.amazon.com/cloudfront/home?#) home 52 | ![alt text](documentation_images/cloudfront_home.png "Cloudfront home") 53 | 5. Click `Create Distribution` 54 | 6. Click `Get Started` under **Web** 55 | ![alt text](documentation_images/get_started.png "Create Distribution - Get Started") 56 | 7. Enter an `origin domain name` where you are choosing your s3 bucket. Keep all other default settings the same: 57 | ![alt text](documentation_images/cloudfront_create.png "Create a distribution settings") 58 | Click **Create Distribution** 59 | 8. Let cloudfront create your deployment, this takes a few minutes to complete. 60 | 9. Eventually you will see the status change to `Deployed` and state change to `Enabled`: 61 | ![alt text](documentation_images/deployed_distribution.png "Deployed CDN Distribution") 62 | Note the domain name URL which cloudfront "creates" for your new deployment (ending in ****.cloudfront.net), you'll need this in the next step. 63 | 10. Visit your image asset with the new cloudfront endpoint URL to test to make sure your cloudfront CDN deployment is working. 64 | ![alt text](documentation_images/test_image_asset.png "Test your image asset on cloudfront") 65 | # AWS Cost Warning 66 | Please be careful using AWS services. This includes costs you might accumulate for uploading files to services such as AWS S3. 67 | 68 | The Author/copyright holders of this package are not liable for any costs you might incur for cloud hosting or any other fees while using Lottie Animation Manager. 69 | 70 | # MIT License 71 | 72 | Copyright (c) 2020 BAKZ T. FUTURE 73 | 74 | Permission is hereby granted, free of charge, to any person obtaining a copy 75 | of this software and associated documentation files (the "Software"), to deal 76 | in the Software without restriction, including without limitation the rights 77 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 78 | copies of the Software, and to permit persons to whom the Software is 79 | furnished to do so, subject to the following conditions: 80 | 81 | The above copyright notice and this permission notice shall be included in all 82 | copies or substantial portions of the Software. 83 | 84 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 85 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 86 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 87 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 88 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 89 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 90 | SOFTWARE. 91 | -------------------------------------------------------------------------------- /lottie_animation_manager.egg-info/PKG-INFO: -------------------------------------------------------------------------------- 1 | Metadata-Version: 2.1 2 | Name: lottie-animation-manager 3 | Version: 0.0.5 4 | Summary: The easiest way to manage, compress, and upload Lottie assets to a CDN. 5 | Home-page: https://github.com/bakztfuture/lottie_animation_manager 6 | Author: Bakz T. Future 7 | Author-email: bakztfuture@gmail.com 8 | License: UNKNOWN 9 | Description: # Lottie Animation Manager :rocket: 10 | The easiest way to manage, compress, and upload Lottie assets to a CDN 11 | 12 | ![alt text](documentation_images/application-screenshot.png "Lottie Animation Manager Command Line Application Screenshot") 13 | 14 | # Philosophy 15 | Lottie Animation Manager was created to provide a new way of hosting and managing Lottie Animation Assets. Instead of including all lottie animations inside of the `static` folder in an application, we think all animation assets should be hosted on a CDN (content delivery network). 16 | 17 | This way, updates to animation assets don't require changes to the code repository or static asset folder. This also reduces the overall build size of an application, reducing the website load time for every user session. 18 | 19 | Lottie Animation Manager is the first half of a larger plan. Soon, there will be a companion Vue library as well which will let you easily reference your lottie assets hosted on a CDN from inside of your Vue Application. 20 | 21 | # Features 22 | - Upload your lottie animation assets to AWS S3 + Cloudfront CDN with a single command 23 | - Automatically compress image assets using TinyPNG to save load time before they are uploaded 24 | 25 | # Setup/Installation 26 | Simply install the Lottie Animation Manager library through **pip**: 27 | ```bash 28 | # most common way: 29 | pip install lottie-animation-manager 30 | # for people who have multiple versions of python: 31 | pip3 install lottie-animation-manager 32 | ``` 33 | # Usage 34 | 1. Install the [AWS CLI](https://docs.aws.amazon.com/cli/latest/userguide/install-linux.html) 35 | ``` 36 | pip3 install awscli --upgrade --user 37 | ``` 38 | 2. Configure / Add your AWS Security Access Keys by entering: 39 | ``` 40 | aws configure 41 | ``` 42 | 3. Now, using `cd` , navigate to your folder with your lottie asset (which was exported by the Bodymovin plugin). Your folder layout might look something like this: 43 | ![alt text](documentation_images/sample_animation_folder_layout.png "Example Lottie Animation Export Directory") 44 | 5. Call the python application from your command line like so from inside this animation directory: 45 | ``` 46 | lottie-animation-manager 47 | ``` 48 | 6. Once the application loads, follow the steps in the lottie animation wizard to upload, compress, and manage your assets to Cloudfront CDN :tada: 49 | 50 | # AWS Cloudfront CDN Setup (Background) 51 | Create an AWS Cloudfront deployment so that your lottie applications can load quickly worldwide whenever they are called within your application. 52 | Basic instructions to do this: 53 | 1. Create your AWS security keys by visiting `Your account Name > My Security Credentials` at the top, clicking `Access Keys`, and clicking `Create New Access Key` . Write down of these securities as you can only see them one time. 54 | 2. Create a basic [s3 bucket](https://s3.console.aws.amazon.com/s3/bucket/create): 55 | ![alt text](documentation_images/create_bucket.png "Create basic S3 bucket") 56 | image above is incorrect, disable block all public access 57 | 3. Uploaded an image asset and set it to read permission `everyone` 58 | ![alt text](documentation_images/upload_test_image.png "Upload a test image") 59 | 4. Visit [AWS Cloudfront](https://console.aws.amazon.com/cloudfront/home?#) home 60 | ![alt text](documentation_images/cloudfront_home.png "Cloudfront home") 61 | 5. Click `Create Distribution` 62 | 6. Click `Get Started` under **Web** 63 | ![alt text](documentation_images/get_started.png "Create Distribution - Get Started") 64 | 7. Enter an `origin domain name` where you are choosing your s3 bucket. Keep all other default settings the same: 65 | ![alt text](documentation_images/cloudfront_create.png "Create a distribution settings") 66 | Click **Create Distribution** 67 | 8. Let cloudfront create your deployment, this takes a few minutes to complete. 68 | 9. Eventually you will see the status change to `Deployed` and state change to `Enabled`: 69 | ![alt text](documentation_images/deployed_distribution.png "Deployed CDN Distribution") 70 | Note the domain name URL which cloudfront "creates" for your new deployment (ending in ****.cloudfront.net), you'll need this in the next step. 71 | 10. Visit your image asset with the new cloudfront endpoint URL to test to make sure your cloudfront CDN deployment is working. 72 | ![alt text](documentation_images/test_image_asset.png "Test your image asset on cloudfront") 73 | # AWS Cost Warning 74 | Please be careful using AWS services. This includes costs you might accumulate for uploading files to services such as AWS S3. 75 | 76 | The Author/copyright holders of this package are not liable for any costs you might incur for cloud hosting or any other fees while using Lottie Animation Manager. 77 | 78 | # MIT License 79 | 80 | Copyright (c) 2020 BAKHTAWAR AWAN 81 | 82 | Permission is hereby granted, free of charge, to any person obtaining a copy 83 | of this software and associated documentation files (the "Software"), to deal 84 | in the Software without restriction, including without limitation the rights 85 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 86 | copies of the Software, and to permit persons to whom the Software is 87 | furnished to do so, subject to the following conditions: 88 | 89 | The above copyright notice and this permission notice shall be included in all 90 | copies or substantial portions of the Software. 91 | 92 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 93 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 94 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 95 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 96 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 97 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 98 | SOFTWARE. 99 | Keywords: lottie animations bodymovin cloudfront cdn 100 | Platform: UNKNOWN 101 | Classifier: Development Status :: 3 - Alpha 102 | Classifier: Programming Language :: Python :: 3 103 | Classifier: License :: OSI Approved :: MIT License 104 | Classifier: Operating System :: OS Independent 105 | Requires-Python: >=3.6 106 | Description-Content-Type: text/markdown 107 | -------------------------------------------------------------------------------- /lottie_animation_manager/__main__.py: -------------------------------------------------------------------------------- 1 | # Essential imports 2 | import os, sys, re 3 | import pathlib 4 | from .utils import * 5 | 6 | # AWS Related imports 7 | import boto 8 | import boto.s3.connection 9 | from boto.s3.key import Key 10 | from boto.exception import NoAuthHandlerFound 11 | bucket = None 12 | bucket_name_final = None 13 | 14 | # Command line related imports 15 | import click 16 | import emoji 17 | from pyfiglet import Figlet 18 | f = Figlet(font='slant') 19 | 20 | # for the purposes of securely storing tinypng API if necessary 21 | import keyring 22 | LOTTIE_KEYRING_SERVICE_ID = 'lottie_animation_manager' 23 | configured_tiny_png_key = None 24 | compression_enabled = True 25 | 26 | ''' 27 | The program actually initializes here. 28 | If the user does not already have AWS CLI configured with the appropriate details (AWS Access keys) 29 | they will not be able to continue in the program, not much they can do anyways! 30 | ''' 31 | try: 32 | conn = boto.connect_s3() 33 | except NoAuthHandlerFound: 34 | click.echo(click.style(emoji.emojize(' Lottie Animation Manager - AWS Config Error '), bg='red', fg="bright_white")) 35 | click.echo('\n') 36 | click.echo(click.style('In order to continue, please reconfigure and test your local AWS profile/configuration. You\'ll need to download the AWS CLI and configure it first before you can proceed.', fg="green")) 37 | sys.exit() 38 | except Exception: 39 | click.echo(click.style(emoji.emojize(' Lottie Animation Manager - AWS Config Error '), bg='red', fg="bright_white")) 40 | click.echo('\n') 41 | click.echo(click.style('In order to continue, please reconfigure and test your local AWS profile/configuration. You\'ll need to download the AWS CLI and configure it first before you can proceed.', fg="green")) 42 | sys.exit() 43 | 44 | def clear_keyring(): 45 | ''' 46 | This function is used for testing purposes. Basically clears existing keyring values so you can reconfigure 47 | the command line utility from scratch and see if configs are working. 48 | ''' 49 | global bucket 50 | global configured_tiny_png_key 51 | global compression_enabled 52 | 53 | keyring.delete_password(LOTTIE_KEYRING_SERVICE_ID, 'lottie_animation_manager_config_complete') 54 | keyring.delete_password(LOTTIE_KEYRING_SERVICE_ID, 's3_bucket_name') 55 | keyring.delete_password(LOTTIE_KEYRING_SERVICE_ID, 'tiny_png_credentials') 56 | click.echo("cleared keyring") 57 | 58 | 59 | def compress_image(file_name): 60 | ''' 61 | Compress a local PNG or JPEG image using the TinyPNG API 62 | ''' 63 | global bucket 64 | global configured_tiny_png_key 65 | global compression_enabled 66 | 67 | import tinify 68 | tinify.key = configured_tiny_png_key 69 | 70 | click.echo(click.style('Compressing image files:', 71 | fg="green"), 72 | nl=True) 73 | try: 74 | original_file_size = sizeof_fmt(os.path.getsize(file_name)) 75 | source = tinify.from_file(file_name) 76 | source.to_file(file_name) 77 | compressed_file_size = sizeof_fmt(os.path.getsize(file_name)) 78 | click.echo(click.style('{} - Compression successful'.format(file_name), 79 | fg="bright_cyan"), 80 | nl=False) 81 | click.echo(click.style(' {} ➟ {} '.format(original_file_size, compressed_file_size), 82 | fg="blue")) 83 | except Exception as e: 84 | click.echo(click.style('{} - Error compressing this file'.format(file_name), 85 | fg="red")) 86 | 87 | def uploadDirectory(directory_name): 88 | ''' 89 | This is the bread and butter of the application. Does a few things: 90 | 1. Let's the user know which files it has discovered 91 | 2. Confirm the want to proceed 92 | 3. Optionally compress the images 93 | 4. Upload the images to s3 under specified animation name, inside the request s3 bucket 94 | ''' 95 | global bucket 96 | global configured_tiny_png_key 97 | global compression_enabled 98 | 99 | # Screen Title 100 | click.echo(click.style(emoji.emojize(' Upload Current Working Directory :up_arrow: '), bg='green', fg="bright_white")) 101 | # Screen Instructions 102 | click.echo(click.style("Make sure you are 'inside' of the animation directory with all of your lottie assets.\n", fg="green")) 103 | click.echo(click.style(emoji.emojize('Lottie Animation Manager has discovered the following files in the current directory: '), 104 | fg='green'), 105 | nl=True) 106 | # list out current files which will be sent to the user, ignoring .ds_store files generated by MacOS 107 | file_count = 0 108 | for root, dirs, files in os.walk("."): 109 | for f in files: 110 | current_file = os.path.relpath(os.path.join(root, f), ".") 111 | if not ".DS_Store" in current_file: 112 | if os.sep in current_file: 113 | click.echo(click.style(" {}".format(current_file), fg="blue")) 114 | file_count += 1 115 | else: 116 | click.echo(click.style(current_file, fg="blue")) 117 | file_count += 1 118 | 119 | click.echo('\n') 120 | click.echo(click.style('The above', 121 | fg='white'), 122 | nl=False) 123 | click.echo(click.style(' {} files '.format(file_count), 124 | bold=True, 125 | fg='white'), 126 | nl=False) 127 | 128 | # confirm they want to proceed with the upload process 129 | if click.confirm(click.style('will be uploaded to AWS S3 Storage. Please confirm'.format(file_count), 130 | fg='white'), 131 | abort=True): 132 | # Clear screen 133 | if compression_enabled == True: 134 | click.clear() 135 | # Title 136 | click.echo(click.style(emoji.emojize(' Compressing & Uploading Animation Assets '), bg='green', fg="bright_white")) 137 | click.echo('\n') 138 | # compress any images first 139 | for root, dirs, files in os.walk("."): 140 | for f in files: 141 | current_file = os.path.relpath(os.path.join(root, f), ".") 142 | temp_current_file = current_file.lower() 143 | if temp_current_file.endswith(".png") or temp_current_file.endswith(".jpg") \ 144 | or temp_current_file.endswith(".jpeg"): 145 | compress_image(current_file) 146 | 147 | click.echo('\n') 148 | click.echo(click.style('Uploading animation asset files to AWS S3 Storage Bucket:', 149 | fg="green"), 150 | nl=True) 151 | # the user has confirmed, images are compressed, now send it up to s3 152 | for root, dirs, files in os.walk("."): 153 | for f in files: 154 | current_file = os.path.relpath(os.path.join(root, f), ".") 155 | if not ".DS_Store" in current_file: 156 | try: 157 | k = bucket.new_key("{}/{}".format(directory_name, current_file)) 158 | k.set_contents_from_filename(current_file) 159 | k.set_acl('public-read') 160 | click.echo(click.style('{} - Upload successful'.format(current_file), 161 | fg="bright_cyan")) 162 | except: 163 | click.echo('Error uploading file to s3!') 164 | 165 | # Send them to the view animations listing view, now that we're done here 166 | if(click.confirm('\nAll done! Do you want to continue to the animations listings section?')): 167 | list_hosted_animations() 168 | else: 169 | click.echo(click.style(emoji.emojize("Thanks for using Lottie Animation Manager, have a nice day :sun: \n"), fg='bright_green')) 170 | else: 171 | # terminate the program 172 | click.echo(click.style(emoji.emojize("Thanks for using Lottie Animation Manager, have a nice day :sun: \n"), fg='bright_green')) 173 | 174 | @click.command() 175 | def upload_current_lottie_directory(): 176 | ''' 177 | Main purpose of this function is to get the user to enter a valid name for the animation following s3 rules. 178 | ''' 179 | global bucket 180 | global configured_tiny_png_key 181 | global compression_enabled 182 | 183 | # Clear screen 184 | click.clear() 185 | # Screen Title 186 | click.echo(click.style(emoji.emojize(' Create a New Animation :rocket: '), bg='green', fg="bright_white")) 187 | # Screen Instructions 188 | click.echo(click.style("Create your new animation by giving it a name.\n", fg="green")) 189 | click.echo(click.style("The animation name is the name you will use in your vue project to reference/call the animation. It's also the name given to the 'folder' inside your S3 bucket where your assets will be stored. Please name it carefully and follow typical file naming conventions.\n", fg="green")) 190 | 191 | # Ask for a name for their new animation 192 | valid = False 193 | while (valid == False): 194 | animation_name = click.prompt('Please enter a CaSE SENSitive name for your new animation (eg. animation-1)') 195 | if (animation_name is None or len(animation_name) < 3 or len(animation_name) > 59): 196 | click.echo(click.style("Please enter a valid animation name. Longer than 3 characters, shorter than 60 characters.", fg="red")) 197 | elif (" " in animation_name): 198 | click.echo(click.style("Please avoid using spaces in your animation name (best practice)", fg="red")) 199 | elif not re.match(r'^[a-zA-Z0-9][ A-Za-z0-9_-]*$', animation_name): 200 | click.echo(click.style("Please avoid using special characters. Only alpha/numeric, dashes, and underscores are allowed.", fg="red")) 201 | else: 202 | click.echo(click.style("Now checking if '{}' already exists in your S3 Bucket...".format(animation_name), fg="blue")) 203 | 204 | # creating a working list of folders in the bucket 205 | existing_folders = [] 206 | folders = bucket.list("","/") 207 | for folder in folders: 208 | folder_name = folder.name 209 | # strip the folder name to just the root level, with no trailing slashes 210 | folder_name = pathlib.Path(folder_name).parts[0] 211 | folder_name = folder_name.lower() 212 | existing_folders.append(folder_name) 213 | 214 | # check if animation name actually exists in the bucket already 215 | if(animation_name.lower() not in existing_folders): 216 | valid = True 217 | else: 218 | click.echo(click.style("Sorry, please enter another animation name. '{}' already exists in your bucket.".format(animation_name), fg="red")) 219 | 220 | # Clear screen 221 | click.clear() 222 | # Go to the upload current directory wizard, pass on the name they have requested 223 | uploadDirectory(animation_name) 224 | 225 | # Main Menu Screen 226 | @click.command() 227 | def list_hosted_animations(): 228 | ''' List hosted animations / folders currently in the s3 bucket ''' 229 | global bucket 230 | global configured_tiny_png_key 231 | global compression_enabled 232 | global bucket_name_final 233 | 234 | # Clear screen 235 | click.clear() 236 | # Window Title 237 | click.echo(click.style(emoji.emojize(' List Animations '), bg='green', fg="bright_white")) 238 | click.echo('\n') 239 | 240 | click.echo(click.style('Found the following folders in your s3 bucket:', fg="green")) 241 | # creating a working list of folders in the bucket 242 | existing_folders = [] 243 | folders = bucket.list("","/") 244 | for folder in folders: 245 | folder_name = folder.name 246 | # strip the folder name to just the root level, with no trailing slashes 247 | folder_name = pathlib.Path(folder_name).parts[0] 248 | existing_folders.append(folder_name) 249 | 250 | if len(existing_folders) > 0: 251 | count = 1 252 | for folder in existing_folders: 253 | click.echo(click.style("{}) ".format(count), fg="bright_white"), nl=False) 254 | click.echo(click.style("{}".format(folder), bg='bright_white', fg="black"), nl=True) 255 | click.echo(click.style("https://s3.console.aws.amazon.com/s3/buckets/{}/{}/".format(bucket_name_final, folder), fg="bright_cyan"), nl=True) 256 | count += 1 257 | else: 258 | click.echo(click.style('Sorry - no existing animation folders were found!')) 259 | 260 | 261 | @click.command() 262 | def initialize_configuration(): 263 | """ 264 | This is for "first time" usage of the Lottie Animation Manager Command line Utility. 265 | If the user is already configured, they will just be redirected to the main menu. 266 | Otherwise, they will be asked for two things: 267 | 1) Which S3 Bucket they want to upload lottie animation assets to 268 | 2) What their TinyPNG API key is (if they actually want to use it) 269 | Lottie Animation Manager uses Python's keyring library in order to store this information sort of securely. 270 | """ 271 | global bucket 272 | global configured_tiny_png_key 273 | global compression_enabled 274 | global bucket_name_final 275 | 276 | # Detect if the configuration was successfully completed in the past 277 | if(keyring.get_password(LOTTIE_KEYRING_SERVICE_ID, 'lottie_animation_manager_config_complete') == 'true'): 278 | # grab the stored configuration values 279 | # s3 bucket 280 | bucket_name = keyring.get_password(LOTTIE_KEYRING_SERVICE_ID, 's3_bucket_name') 281 | bucket = conn.get_bucket(bucket_name) 282 | bucket_name_final = bucket_name 283 | 284 | # configured tinypng API info (if any) 285 | configured_tiny_png_key = keyring.get_password(LOTTIE_KEYRING_SERVICE_ID, 'tiny_png_credentials') 286 | 287 | if configured_tiny_png_key == False: 288 | compression_enabled = False 289 | main_menu() 290 | else: 291 | # Clear screen 292 | click.clear() 293 | # Window Title 294 | click.echo(click.style(emoji.emojize(' Lottie Animation Manager Setup Wizard '), bg='green', fg="bright_white")) 295 | click.echo('\n') 296 | # Initial instructions 297 | click.echo(click.style('Thanks for downloading Lottie Animation Manager!', fg="green")) 298 | click.echo(click.style('LAM depends on a few services:', fg="green")) 299 | click.echo(click.style('- Amazon Web Services S3 + Cloudfront', fg="bright_cyan")) 300 | click.echo(click.style('Follow the instructions in our docs on setting up these services.', fg="bright_cyan")) 301 | click.echo(click.style('LAM utilizes your local default AWS configuration/profile keys to upload media. You\'ll need to download the AWS CLI locally and configure it correctly.', fg="bright_cyan")) 302 | click.echo(click.style('- TinyPNG (optional)', fg="bright_cyan")) 303 | click.echo(click.style('Easily compress images in your lottie assets folder before uploading to them your CDN. API key needed for this.', fg="bright_cyan")) 304 | 305 | # Please enter your bucket name 306 | bucket_set = False 307 | while(bucket_set == False): 308 | bucket_name = click.prompt('Please enter the name of your AWS bucket where assets will be stored') 309 | try: 310 | bucket = conn.get_bucket(bucket_name) 311 | keyring.set_password(LOTTIE_KEYRING_SERVICE_ID, 's3_bucket_name', bucket_name) 312 | bucket_name_final = bucket_name 313 | bucket_set = True 314 | except: 315 | click.echo(click.style("Could not connect to '{}' bucket, please try again".format(bucket_name), fg="red")) 316 | 317 | # Please enter your tinyPNG stuff 318 | tiny_png_key = click.prompt('Please enter your TinyPNG Key or enter "skip" to disable image compression') 319 | if(tiny_png_key.lower() != 'skip'): 320 | keyring.set_password(LOTTIE_KEYRING_SERVICE_ID, 'tiny_png_credentials', tiny_png_key) 321 | configured_tiny_png_key = tiny_png_key 322 | compression_enabled = True 323 | else: 324 | compression_enabled = False 325 | keyring.set_password(LOTTIE_KEYRING_SERVICE_ID, 'tiny_png_credentials', "false") 326 | 327 | # Mark configuration as complete now 328 | keyring.set_password(LOTTIE_KEYRING_SERVICE_ID, 'lottie_animation_manager_config_complete', "true") 329 | main_menu() 330 | 331 | @click.command() 332 | def main_menu(): 333 | ''' 334 | Main Screen of the Lottie Animation Manager Command line utility. Choose from a menu of options! 335 | ''' 336 | # Clear screen 337 | click.clear() 338 | # Quick "Up top logo" 339 | click.echo(click.style("--------------------------------------------------------\n", fg='bright_green')) 340 | click.echo(click.style(f.renderText("Lottie CDN"), fg='bright_green')) 341 | click.echo(click.style("--------------------------------------------------------", fg='bright_green')) 342 | # Welcome and project description 343 | click.echo(click.style(emoji.emojize('Thanks for using Lottie Animation Manager :thumbs_up:'), fg='bright_green')) 344 | click.echo(click.style("Lottie Animation Manager makes it easy to manage, compress, and upload Lottie assets to a CDN. \n", fg='bright_green')) 345 | # Main menu with 3 options 346 | click.echo(click.style("Choose an option below to get started: ", bold=True)) 347 | click.echo(click.style("1) Create a New Animation / Upload Current Directory", fg='bright_cyan')) 348 | click.echo(click.style("2) List Hosted Animations", fg='bright_cyan')) 349 | click.echo(click.style("3) Exit Lottie Animation Manager", fg='bright_cyan')) 350 | 351 | # Ask the user what menu option they want 352 | menu_choice = click.prompt('Please enter a value between 1-3', type=int) 353 | 354 | # Option 2: Create a new animation ie. upload the current working directory 355 | if(menu_choice == 1): 356 | upload_current_lottie_directory() 357 | elif(menu_choice == 2): 358 | list_hosted_animations() 359 | elif(menu_choice == 3): 360 | click.echo(click.style(emoji.emojize("Thanks for using Lottie Animation Manager, have a nice day :sun: \n"), fg='bright_green')) 361 | click.Abort() 362 | else: 363 | click.echo(click.style("Please enter a valid menu choice number.", fg="red")) 364 | 365 | 366 | if __name__ == '__main__': 367 | initialize_configuration() --------------------------------------------------------------------------------