Completed
Push — master ( 2903d8...494eca )
by Chris
01:15
created

get_remote_assets()   B

Complexity

Conditions 5

Size

Total Lines 22

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 5
c 1
b 0
f 0
dl 0
loc 22
rs 8.3411
1
"""Utilities for dealing with static assets -- downloading, etc..."""
2
3
import os
4
5
import requests
6
import click
7
8
from settings import CHARTS_CONFIG
9
10
11
@click.command()
12
@click.option('--js',
13
              default=True,
14
              help='Download JS assets?')
15
@click.option('--css',
16
              default=True,
17
              help='Download CSS assets?')
18
def get_remote_assets(css, js):
19
    """Download all static assets for the library to local source."""
20
    print('Downloading remote assets: JS? {} / CSS? {}'.format(css, js))
21
    for family, config in CHARTS_CONFIG.items():
22
        if js and config['js_url'] is not None:
23
            for url in config['js_url']:
24
                file = url.split('/')[-1]
25
                print(file)
26
                host = url.replace(file, '')
27
                print('Downloading: {file} from {host}'.format(
28
                    file=file, host=host))
29
                path = 'flask_jsondash/static/js/vendor/{file}'.format(
30
                    file=file)
31
                os.system('curl -XGET {url} > {path}'.format(
32
                    url=url, path=path))
33
        # if js:
34
35
36
if __name__ == '__main__':
37
    get_remote_assets()
38