def inc_label(label): db.update_item(TableName=vars.get('stats_table'), Key={vars.get('stats_key'): { 'S': label }}, UpdateExpression='ADD #count :count', ExpressionAttributeNames={'#count': 'count'}, ExpressionAttributeValues={ ':count': { 'N': '1', }, })
def handle(self, **options): """ Locked command handler to avoid running this command more than once simultaneously. """ try: targets = Subscription.objects.filter(campaign='firefox-home-instructions', active=True).order_by('id') start = int(vars.get('sync_unsubscribe_index', 0)) log.info(start) end = start + limit targets = targets[start:end] count = targets.count() log.info("Found %d targets" % count) unsub_count = 0 for target in targets: if subscription_has_account(target): target.active = False target.save() unsub_count += 1 log.info("Unsubscribed %d" % unsub_count) if count < limit: vars.set('sync_unsubscribe_index', 0) else: vars.set('sync_unsubscribe_index', start + (count - unsub_count)) except Exception, e: raise CommandError(e)
import boto3 import vars import uuid s3 = boto3.client('s3') bucket = vars.get("image_bucket") def upload(img) -> {}: key = "{}.{}".format(str(uuid.uuid4()), 'jpg') s3.upload_file(Filename=img, Bucket=bucket, Key=key) return dict(S3Object={'Bucket': bucket, 'Name': key}) def delete(key): s3.delete_object(Bucket=bucket, Key=key)
def insert_trend(confidence): table.put_item( Item={ vars.get('trend_key'): str(datetime.datetime.now()), 'confidence': decimal.Decimal(confidence) })
import boto3 import vars import datetime import decimal db_client = boto3.client('dynamodb') db_resource = boto3.resource('dynamodb') table = db_resource.Table(vars.get('trend_table')) def inc_label(label): db_client.update_item(TableName=vars.get('stats_table'), Key={vars.get('stats_key'): { 'S': label }}, UpdateExpression='ADD #count :count', ExpressionAttributeNames={'#count': 'count'}, ExpressionAttributeValues={ ':count': { 'N': '1', }, }) def inc(labels): if labels: for label in labels: inc_label(label) def insert_trend(confidence):