當前位置: 首頁>>代碼示例>>Python>>正文


Python TableService.update_entity方法代碼示例

本文整理匯總了Python中azure.storage.TableService.update_entity方法的典型用法代碼示例。如果您正苦於以下問題:Python TableService.update_entity方法的具體用法?Python TableService.update_entity怎麽用?Python TableService.update_entity使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在azure.storage.TableService的用法示例。


在下文中一共展示了TableService.update_entity方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: TableServiceTest

# 需要導入模塊: from azure.storage import TableService [as 別名]
# 或者: from azure.storage.TableService import update_entity [as 別名]

#.........這裏部分代碼省略.........
        self._create_table_with_default_entities(self.table_name, 3)

        # Act
        resp = self.ts.query_entities(self.table_name, None, None, 2)

        # Assert
        self.assertEqual(len(resp), 2)

    def test_query_entities_with_top_and_next(self):
        # Arrange
        self._create_table_with_default_entities(self.table_name, 5)

        # Act
        resp1 = self.ts.query_entities(self.table_name, None, None, 2)
        resp2 = self.ts.query_entities(
            self.table_name, None, None, 2,
            resp1.x_ms_continuation['NextPartitionKey'],
            resp1.x_ms_continuation['NextRowKey'])
        resp3 = self.ts.query_entities(
            self.table_name, None, None, 2,
            resp2.x_ms_continuation['NextPartitionKey'],
            resp2.x_ms_continuation['NextRowKey'])

        # Assert
        self.assertEqual(len(resp1), 2)
        self.assertEqual(len(resp2), 2)
        self.assertEqual(len(resp3), 1)
        self.assertEqual(resp1[0].RowKey, '1')
        self.assertEqual(resp1[1].RowKey, '2')
        self.assertEqual(resp2[0].RowKey, '3')
        self.assertEqual(resp2[1].RowKey, '4')
        self.assertEqual(resp3[0].RowKey, '5')

    def test_update_entity(self):
        # Arrange
        self._create_table_with_default_entities(self.table_name, 1)

        # Act
        sent_entity = self._create_updated_entity_dict('MyPartition', '1')
        resp = self.ts.update_entity(
            self.table_name, 'MyPartition', '1', sent_entity)

        # Assert
        self.assertIsNotNone(resp)
        received_entity = self.ts.get_entity(
            self.table_name, 'MyPartition', '1')
        self._assert_updated_entity(received_entity)

    def test_update_entity_with_if_matches(self):
        # Arrange
        entities = self._create_table_with_default_entities(self.table_name, 1)

        # Act
        sent_entity = self._create_updated_entity_dict('MyPartition', '1')
        resp = self.ts.update_entity(
            self.table_name,
            'MyPartition', '1', sent_entity, if_match=entities[0].etag)

        # Assert
        self.assertIsNotNone(resp)
        received_entity = self.ts.get_entity(
            self.table_name, 'MyPartition', '1')
        self._assert_updated_entity(received_entity)

    def test_update_entity_with_if_doesnt_match(self):
        # Arrange
開發者ID:algaruda,項目名稱:azure-sdk-for-python,代碼行數:70,代碼來源:test_tableservice.py

示例2: getCharacteristics

# 需要導入模塊: from azure.storage import TableService [as 別名]
# 或者: from azure.storage.TableService import update_entity [as 別名]
    # process image
    colourStructure = getCharacteristics( image, region, results )

    blob_service.put_block_blob_from_bytes( blob_analysis, imgBlobName, dumps(colourStructure) )

    # {'PartitionKey': 'allPhotos', 'RowKey': 'imageName', 'thumbnail' : 'thumbnailName',
    #  'userId' : ?, 'local' : ?, 'hue' : 200, 'saturation' : 200, 'value' : 200}
    ## query for image in table to ensure existence
    currentTask = table_service.get_entity( tableName, tablePartitionKey, tableRowKey)

    
  
    ## send the quantities to table: save thumbnail ID & save image characteristics
    # currentTask.thumbnail = tnID
    currentTask.analysed = True
    table_service.update_entity( tableName, tablePartitionKey, tableRowKey, currentTask)

    # dequeue image
    queue_service.delete_message( imagesQueue, message.message_id, message.pop_receipt )



# Get the mosaic image from some queue


## Divide on quadrants and analyse each quadrant ? concurrently
## Wait until table is filled with values - no NILLs - thumbnails done
## Send request for image with given statistics
## Receive thumbnail and paste it
## REPEAT
開發者ID:macqm,項目名稱:mosaic-opencv,代碼行數:32,代碼來源:analyse.cv.py

示例3: TableService

# 需要導入模塊: from azure.storage import TableService [as 別名]
# 或者: from azure.storage.TableService import update_entity [as 別名]
from azure.storage import TableService, Entity

#Replace account_name with your account and account_key with your primary key

table_service = TableService(account_name='myaccount', account_key='myKey')

table_service.create_table('tasktable')

# Updating an entity to table in multiple ways

task1 = {'description' : 'schedule doctor appointment', 'priority' : 300}
table_service.update_entity('tasktable', 'toDoTasks', '1', task1)

task2 = {'PartitionKey': 'toDoTasks', 'RowKey': '2', 'description' : 'Pay bills', 'priority' : 200}
table_service.insert_or_replace_entity('tasktable', task2)


開發者ID:sasmishi,項目名稱:mySamples,代碼行數:17,代碼來源:update.py

示例4: TableServiceTest

# 需要導入模塊: from azure.storage import TableService [as 別名]
# 或者: from azure.storage.TableService import update_entity [as 別名]

#.........這裏部分代碼省略.........
        self.assertFalse(hasattr(resp[0], "birthday"))
        self.assertFalse(hasattr(resp[0], "married"))
        self.assertFalse(hasattr(resp[0], "deceased"))

    def test_query_entities_with_top(self):
        # Arrange
        self._create_table_with_default_entities(self.table_name, 3)

        # Act
        resp = self.tc.query_entities(self.table_name, None, None, 2)

        # Assert
        self.assertEquals(len(resp), 2)

    def test_query_entities_with_top_and_next(self):
        # Arrange
        self._create_table_with_default_entities(self.table_name, 5)

        # Act
        resp1 = self.tc.query_entities(self.table_name, None, None, 2)
        resp2 = self.tc.query_entities(self.table_name, None, None, 2, resp1.x_ms_continuation['NextPartitionKey'], resp1.x_ms_continuation['NextRowKey'])
        resp3 = self.tc.query_entities(self.table_name, None, None, 2, resp2.x_ms_continuation['NextPartitionKey'], resp2.x_ms_continuation['NextRowKey'])

        # Assert
        self.assertEquals(len(resp1), 2)
        self.assertEquals(len(resp2), 2)
        self.assertEquals(len(resp3), 1)
        self.assertEquals(resp1[0].RowKey, '1')
        self.assertEquals(resp1[1].RowKey, '2')
        self.assertEquals(resp2[0].RowKey, '3')
        self.assertEquals(resp2[1].RowKey, '4')
        self.assertEquals(resp3[0].RowKey, '5')

    def test_update_entity(self):
        # Arrange
        self._create_table_with_default_entities(self.table_name, 1)

        # Act
        sent_entity = self._create_updated_entity_dict('MyPartition','1')
        resp = self.tc.update_entity(self.table_name, 'MyPartition', '1', sent_entity)

        # Assert
        self.assertIsNotNone(resp)
        received_entity = self.tc.get_entity(self.table_name, 'MyPartition', '1')
        self._assert_updated_entity(received_entity)

    def test_update_entity_with_if_matches(self):
        # Arrange
        entities = self._create_table_with_default_entities(self.table_name, 1)

        # Act
        sent_entity = self._create_updated_entity_dict('MyPartition','1')
        resp = self.tc.update_entity(self.table_name, 'MyPartition', '1', sent_entity, if_match=entities[0].etag)

        # Assert
        self.assertIsNotNone(resp)
        received_entity = self.tc.get_entity(self.table_name, 'MyPartition', '1')
        self._assert_updated_entity(received_entity)

    def test_update_entity_with_if_doesnt_match(self):
        # Arrange
        entities = self._create_table_with_default_entities(self.table_name, 1)

        # Act
        sent_entity = self._create_updated_entity_dict('MyPartition','1')
        with self.assertRaises(WindowsAzureError):
開發者ID:Bunkerbewohner,項目名稱:azure-sdk-for-python,代碼行數:70,代碼來源:test_tableservice.py

示例5: Repository

# 需要導入模塊: from azure.storage import TableService [as 別名]
# 或者: from azure.storage.TableService import update_entity [as 別名]
class Repository(object):
    """Azure Table Storage repository."""
    def __init__(self, settings):
        """Initializes the repository with the specified settings dict.
        Required settings are:
         - STORAGE_NAME
         - STORAGE_KEY
         - STORAGE_TABLE_POLL
         - STORAGE_TABLE_CHOICE
        """
        self.name = 'Azure Table Storage'
        self.storage_name = settings['STORAGE_NAME']
        self.storage_key = settings['STORAGE_KEY']
        self.poll_table = settings['STORAGE_TABLE_POLL']
        self.choice_table = settings['STORAGE_TABLE_CHOICE']

        self.svc = TableService(self.storage_name, self.storage_key)
        self.svc.create_table(self.poll_table)
        self.svc.create_table(self.choice_table)

    def get_polls(self):
        """Returns all the polls from the repository."""
        poll_entities = self.svc.query_entities(self.poll_table)
        polls = [_poll_from_entity(entity) for entity in poll_entities]
        return polls

    def get_poll(self, poll_key):
        """Returns a poll from the repository."""
        try:
            partition, row = _key_to_partition_and_row(poll_key)
            poll_entity = self.svc.get_entity(self.poll_table, partition, row)
            choice_entities = self.svc.query_entities(
                self.choice_table,
                "PollPartitionKey eq '{0}' and PollRowKey eq '{1}'" \
                    .format(partition, row)
            )

            poll = _poll_from_entity(poll_entity)
            poll.choices = [_choice_from_entity(choice_entity)
                            for choice_entity in choice_entities]
            return poll
        except WindowsAzureMissingResourceError:
            raise PollNotFound()

    def increment_vote(self, poll_key, choice_key):
        """Increment the choice vote count for the specified poll."""
        try:
            partition, row = _key_to_partition_and_row(choice_key)
            entity = self.svc.get_entity(self.choice_table, partition, row)
            entity.Votes += 1
            self.svc.update_entity(self.choice_table, partition, row, entity)
        except WindowsAzureMissingResourceError:
            raise PollNotFound()

    def add_sample_polls(self):
        """Adds a set of polls from data stored in a samples.json file."""
        poll_partition = '2014'
        poll_row = 0
        choice_partition = '2014'
        choice_row = 0

        for sample_poll in _load_samples_json():
            poll_entity = {
                'PartitionKey': poll_partition,
                'RowKey': str(poll_row),
                'Text': sample_poll['text'],
            }
            self.svc.insert_entity(self.poll_table, poll_entity)

            for sample_choice in sample_poll['choices']:
                choice_entity = {
                    'PartitionKey': choice_partition,
                    'RowKey': str(choice_row),
                    'Text': sample_choice,
                    'Votes': 0,
                    'PollPartitionKey': poll_partition,
                    'PollRowKey': str(poll_row),
                }
                self.svc.insert_entity(self.choice_table, choice_entity)
                choice_row += 1

            poll_row += 1
開發者ID:CloudeXpert,項目名稱:PTVS,代碼行數:84,代碼來源:azuretablestorage.py

示例6: __init__

# 需要導入模塊: from azure.storage import TableService [as 別名]
# 或者: from azure.storage.TableService import update_entity [as 別名]
class AzureDataServices:
    _partition = 'presence'

    def __init__(self, table):

        if os.environ.get("raspberry") is None:
            table += 'Test'

        print table
        self._partition = table
        with open('azure.txt') as f:
            lines = f.readlines()
        acc = lines[0].strip()
        key = lines[1].strip()
        self._table_service = TableService(account_name=acc, account_key=key)
    
    def create_table(self):
        """
        Creates azure storage table
        """
        self._table_service.create_table(self._partition)

    def insert_data(self, task):
        """
        Insert the object to azure
        """
        self.insert_data_with_key(task, None)

    def insert_data_with_key(self, task, row_key):
        """
        Insert the object to azure
        """
        task.PartitionKey = self._partition

        if row_key:
            t = row_key
        else:
            t = time.strftime("%Y-%m-%d %H:%M:%S", time.gmtime())
            
        task.RowKey = t
        self._table_service.insert_entity(self._partition, task)

    def update_or_insert(self, task, row_key):
        """
        Update or insert the object to azure
        """
        task.PartitionKey = self._partition
        task.RowKey = row_key

        try:
            self._table_service.update_entity(self._partition, self._partition,row_key, task)
        except azure.WindowsAzureMissingResourceError:
            self._table_service.insert_entity(self._partition, task)

    def insert_presence(self, p):
        """
        Uploads value to azure table storage
        """
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.gmtime())
        task = Entity()
        task.PartitionKey = self._partition
        task.RowKey = t

        task.users_arrived = ','.join(map(str, p.users_arrived)) 
        task.users_left = ','.join(map(str, p.users_left)) 

        self._table_service.insert_entity(self._partition, task)

    def get_presence(self):
        tasks = self._table_service.query_entities(self._partition, "PartitionKey eq 'presence'")
        return tasks
開發者ID:acsehi,項目名稱:HomeAutomatization,代碼行數:73,代碼來源:AzureDataServices.py

示例7: TableService

# 需要導入模塊: from azure.storage import TableService [as 別名]
# 或者: from azure.storage.TableService import update_entity [as 別名]
from azure.storage import TableService, Entity

table_service = TableService(account_name='upmsample', account_key='5YC/6x9KL56rtaAUAZMgGsREDvvPHYJIMqH3z1c9IgQLy0qMP+Awr+7j51Tfzniczj//6jn7lvYQutD/mHm6dw==')

while True:
	x = raw_input("Enter 1 or 0: ");
	task = {'PartitionKey': 'ledswitch', 'RowKey': '1', 'state' :int(x)}
	table_service.update_entity('table1', 'ledswitch', '1', task)

開發者ID:sasmita,項目名稱:myExperiments,代碼行數:10,代碼來源:ledupdate.py


注:本文中的azure.storage.TableService.update_entity方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。