Created
May 21, 2014 19:08
-
-
Save Slater-Victoroff/9590bde6e32481ce872f to your computer and use it in GitHub Desktop.
Boto Decorator Skeleton
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
from boto.s3.connection import S3Connection, OrdinaryCallingFormat | |
from boto.s3.key import Key | |
class BotoSave(object): | |
def __init__(self, bucket, filename=None): | |
""" | |
serialization_callback should be a function that returns a string | |
""" | |
credential_dict = credentials(filename) | |
conn = S3Connection( | |
credential_dict['AWSAccessKeyId'], | |
credential_dict['AWSSecretKey'], | |
calling_format=OrdinaryCallingFormat() | |
) | |
self.save_bucket = conn.get_bucket(bucket) | |
def __call__(self, f): | |
def data_output(*args, **kwargs): | |
data_atom = f(*args, **kwargs) | |
new_key = Key(self.save_bucket) | |
new_key.key = find_key(data_atom) | |
new_key.set_contents_from_string(json.dumps(data_atom)) | |
return data_output |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment