Ejemplo n.º 1
0
def push(state, slug, obj):
    k = Key(bucket)
    k.key = '%s/%s.jsonp' % (state, slug)
    data = json.dumps(obj)
    jsonp = '%s(%s)' % (slug, data) 
    compressed = utils.gzip_data(jsonp)

    k.set_contents_from_string(compressed, headers={ 'Content-encoding': 'gzip', 'Content-Type': 'application/javascript' }, policy='public-read')
Ejemplo n.º 2
0
def push(state, slug, obj):
    k = Key(bucket)
    k.key = '%s/%s.jsonp' % (state, slug)
    data = json.dumps(obj)
    jsonp = '%s(%s)' % (slug, data) 
    compressed = utils.gzip_data(jsonp)

    k.set_contents_from_string(compressed, headers={ 'Content-encoding': 'gzip', 'Content-Type': 'application/javascript' }, policy='public-read')
Ejemplo n.º 3
0
def update_state_list(environment, state, clear=False, remove=False):
    c = S3Connection()
    bucket = c.get_bucket(config.S3_BUCKETS[environment])

    k = Key(bucket)
    k.key = 'states.jsonp'

    try:
        data = k.get_contents_as_string()

        # No existing file
        if not data:
            raise S3ResponseError()

        # Strip off jsonp wrapper
        contents = utils.gunzip_data(data)
        data = contents[7:-1]

        states = json.loads(data)
    except S3ResponseError:
        states = []
    if remove:
        states.remove(state)
        print 'Removed %s from list of available states' % state
    elif clear:
        states = [state]
        print 'Reset list of available states and added %s' % state
    else:
        if state not in states:
            states.append(state)

            print '%s added to available state list' % state
        else:
            print '%s is already available' % state

    states.sort()
    jsonp = 'states(%s)' % json.dumps(states)
    compressed = utils.gzip_data(jsonp)

    k.set_contents_from_string(compressed,
                               headers={
                                   'Content-encoding': 'gzip',
                                   'Content-Type': 'application/json'
                               },
                               policy='public-read')
Ejemplo n.º 4
0
def update_state_list(environment, state, clear=False, remove=False):
    c = S3Connection()
    bucket = c.get_bucket(config.S3_BUCKETS[environment])

    k = Key(bucket)
    k.key = 'states.jsonp'

    try:
        data = k.get_contents_as_string()

        # No existing file 
        if not data:
            raise S3ResponseError()
        
        # Strip off jsonp wrapper
        contents = utils.gunzip_data(data)
        data = contents[7:-1]

        states = json.loads(data)
    except S3ResponseError:
        states = []
    if remove:
        states.remove(state)
        print 'Removed %s from list of available states' % state
    elif clear:
        states = [state]
        print 'Reset list of available states and added %s' % state
    else:
        if state not in states:
            states.append(state)

            print '%s added to available state list' % state
        else:
            print '%s is already available' % state
    
    states.sort()
    jsonp = 'states(%s)' % json.dumps(states)
    compressed = utils.gzip_data(jsonp)

    k.set_contents_from_string(compressed, headers={ 'Content-encoding': 'gzip', 'Content-Type': 'application/json' }, policy='public-read')
Ejemplo n.º 5
0
ENVIRONMENT = sys.argv[1]

collection = utils.get_label_collection()

row_count = 0
deployed = 0

c = S3Connection()
bucket = c.get_bucket(config.S3_BUCKETS[ENVIRONMENT])

for dataset in collection.find():
    row_count += 1

    del dataset['_id']

    print dataset['dataset']

    k = Key(bucket)
    k.key = '%s_labels.jsonp' % dataset['dataset']
    jsonp = 'labels_%s(%s)' % (dataset['dataset'], json.dumps(dataset))
    compressed = utils.gzip_data(jsonp)

    k.set_contents_from_string(compressed, headers={ 'Content-encoding': 'gzip', 'Content-Type': 'application/json' }, policy='public-read')

    deployed += 1

print 'deploy_labels:'
print ' Row count: %i' % row_count
print ' Deployed: %i' % deployed

Ejemplo n.º 6
0
row_count = 0
deployed = 0

c = S3Connection()
bucket = c.get_bucket(config.S3_BUCKETS[ENVIRONMENT])

for geography in collection.find():
    row_count += 1

    del geography['_id']

    k = Key(bucket)
    k.key = '%s/%s.jsonp' % (geography['metadata']['STATE'],
                             geography['geoid'])
    jsonp = 'geoid_%s(%s)' % (geography['geoid'], json.dumps(geography))
    compressed = utils.gzip_data(jsonp)

    k.set_contents_from_string(compressed,
                               headers={
                                   'Content-encoding': 'gzip',
                                   'Content-Type': 'application/javascript'
                               },
                               policy=policy)

    if row_count % 100 == 0:
        print ' Deployed %i...' % row_count

    deployed += 1

print '  Row count: %i' % row_count
print '  Deployed: %i' % deployed