def handle(self, *args, **options): conn = ConnectionBorg() conn.set_credentials(aws_access_key_id=settings.DYNAMODB_SESSIONS_AWS_ACCESS_KEY_ID, aws_secret_access_key=settings.DYNAMODB_SESSIONS_AWS_SECRET_ACCESS_KEY,) try: conn.create_table(Contributor, 10, 10, wait_for_active=False) self.stdout.write("Contributor table created") except DynamoDBResponseError, er: print(er)
def test_borgness(self): aws_access_key_id = "foo" aws_secret_access_key = "bar" borg1 = ConnectionBorg() borg2 = ConnectionBorg() borg1.set_credentials(aws_access_key_id, aws_secret_access_key) self.assertEqual(borg1._aws_access_key_id, aws_access_key_id) self.assertEqual(borg1._aws_secret_access_key, aws_secret_access_key) self.assertEqual(borg2._aws_access_key_id, aws_access_key_id) self.assertEqual(borg2._aws_secret_access_key, aws_secret_access_key)
def test_set_credentials(self, m_boto): # Make sure internal state is set and shared m_get_table = m_boto.connect_dynamodb.return_value.get_table aws_access_key_id = "foo" aws_secret_access_key = "bar" table_name = "foo" borg1 = ConnectionBorg() borg2 = ConnectionBorg() borg1.set_credentials(aws_access_key_id, aws_secret_access_key) self.assertIs(borg1._aws_access_key_id ,aws_access_key_id) self.assertIs(borg2._aws_access_key_id ,aws_access_key_id) self.assertIs(borg1._aws_secret_access_key ,aws_secret_access_key) self.assertIs(borg2._aws_secret_access_key ,aws_secret_access_key)
import sys, re from dynamodb_mapper.model import ConnectionBorg from boto.dynamodb.exceptions import DynamoDBKeyNotFoundError import settings from digram import Digram cb = ConnectionBorg() cb.set_region('eu-west-1') cb.set_credentials(settings.aws_access_key_id, settings.aws_secret_access_key) for line in open(sys.argv[1], 'r'): # find words ws = filter(lambda match: match != '', re.findall(r"$| ([a-zA-Z-']+)", line.encode('utf-8'))) # turn into lower case words ws = map(lambda word: word.lower(), ws) # digrams please digrams = reduce(lambda dis, w: dis + [(dis[-1][1], w)], ws, [('','')])[2:] print "found digrams: " + str(digrams) for di in digrams: try: d_rec = Digram.get(di[0], di[1]) except DynamoDBKeyNotFoundError: d_rec = Digram() d_rec.w1 = di[0] d_rec.w2 = di[1]