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


Python TableService.insert_or_replace_entity方法代碼示例

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


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

示例1: TableService

# 需要導入模塊: from azure.storage import TableService [as 別名]
# 或者: from azure.storage.TableService import insert_or_replace_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

示例2: TableServiceTest

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

#.........這裏部分代碼省略.........

        # Assert

    def test_insert_or_merge_entity_with_existing_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.insert_or_merge_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_merged_entity(received_entity)

    def test_insert_or_merge_entity_with_non_existing_entity(self):
        # Arrange
        self._create_table(self.table_name)

        # Act
        sent_entity = self._create_updated_entity_dict('MyPartition', '1')
        resp = self.ts.insert_or_merge_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_insert_or_replace_entity_with_existing_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.insert_or_replace_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_insert_or_replace_entity_with_non_existing_entity(self):
        # Arrange
        self._create_table(self.table_name)

        # Act
        sent_entity = self._create_updated_entity_dict('MyPartition', '1')
        resp = self.ts.insert_or_replace_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_merge_entity(self):
        # Arrange
        self._create_table_with_default_entities(self.table_name, 1)
開發者ID:algaruda,項目名稱:azure-sdk-for-python,代碼行數:70,代碼來源:test_tableservice.py

示例3: TableServiceTest

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

#.........這裏部分代碼省略.........
        # Act
        sent_entity = self._create_updated_entity_dict('MyPartition','1')
        with self.assertRaises(WindowsAzureError):
            self.tc.update_entity(self.table_name, 'MyPartition', '1', sent_entity, if_match=u'W/"datetime\'2012-06-15T22%3A51%3A44.9662825Z\'"')

        # Assert

    def test_insert_or_merge_entity_with_existing_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.insert_or_merge_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_merged_entity(received_entity)

    def test_insert_or_merge_entity_with_non_existing_entity(self):
        # Arrange
        self._create_table(self.table_name)

        # Act
        sent_entity = self._create_updated_entity_dict('MyPartition','1')
        resp = self.tc.insert_or_merge_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_insert_or_replace_entity_with_existing_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.insert_or_replace_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_insert_or_replace_entity_with_non_existing_entity(self):
        # Arrange
        self._create_table(self.table_name)

        # Act
        sent_entity = self._create_updated_entity_dict('MyPartition','1')
        resp = self.tc.insert_or_replace_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_merge_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.merge_entity(self.table_name, 'MyPartition', '1', sent_entity)
開發者ID:Bunkerbewohner,項目名稱:azure-sdk-for-python,代碼行數:70,代碼來源:test_tableservice.py

示例4: get_input_type

# 需要導入模塊: from azure.storage import TableService [as 別名]
# 或者: from azure.storage.TableService import insert_or_replace_entity [as 別名]
while True: 
    x = get_input_type()
    print x
    if x == 'n':
        print 'In 5 seconds start neutral'
        print 'send 2000 points of data to ML set marked neutral'
        time.sleep(5.0)
        print 'START'
        time.sleep(0.5)
        for tableSlot in TableSlotNeutral:
            for abcd in periods:
                time.sleep(0.1)
                record.update({abcd+'X': analog_read(0), abcd+'Y': analog_read(1), abcd+'Z': analog_read(2)})
            print record
            table_service.insert_or_replace_entity(getMLTableName(), 'NEUTRAL', tableSlot, record)

    elif x == 's':
        print 'In 5 seconds start shaking'
        print 'send 2000 points of data to ML set marked shaking'
        time.sleep(5.0)
        print 'START'
        time.sleep(0.5)
        for tableSlot in TableSlotShaking:
            for abcd in periods:
                time.sleep(0.1)
                record.update({abcd+'X': analog_read(0), abcd+'Y': analog_read(1), abcd+'Z': analog_read(2)})
            print record
            table_service.insert_or_replace_entity(getMLTableName(), 'SHAKING', tableSlot, record)

    
開發者ID:timmyreilly,項目名稱:HuggableCloudOffsite,代碼行數:30,代碼來源:MLTrainingSet.py

示例5: generateX

# 需要導入模塊: from azure.storage import TableService [as 別名]
# 或者: from azure.storage.TableService import insert_or_replace_entity [as 別名]
queue_service.create_queue('acceldata')

i = 0

TableSlotList = (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42,43,44,45,46,47,48,49,50)

periods = ('a', 'b', 'c', 'd')

#table_service.insert_or_replace_entity(accel2, accel, tableSlot, periodSlot)

record = {}

#records = {'aX': generateX(),'aY': generateY(),'aZ': generateZ(),'bX': generateX(),'bY': generateY(),'bZ': generateZ(), 'cX': generateX(),'cY': generateY(),'cZ': generateZ(),'cX': generateX(),'cY': generateY(),'cZ': generateZ() }

def analog_read(channel):
	r = spi.xfer2([1, (8 + channel) << 4, 0])
	adc_out = ((r[1]&3) << 8) + r[2]
	return adc_out

while True: 
    for tableSlot in TableSlotList:
        for abcd in periods:
            time.sleep(0.1) 
            record.update({abcd+'X': analog_read(0), abcd+'Y': analog_read(1), abcd+'Z': analog_read(2)})
        print record
	
        table_service.insert_or_replace_entity('accel4', 'slot', tableSlot, record)
	queue_service.put_message('acceldata', unicode(record))

開發者ID:timmyreilly,項目名稱:raspberryHug,代碼行數:30,代碼來源:SendCloudData.py

示例6: analog_read

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

TableSlotList = (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20)

periods = ("a", "b", "c", "d")

# table_service.insert_or_replace_entity(accel2, accel, tableSlot, periodSlot)

record = {}


def analog_read(channel):
    if channel == 0:
        return generateRandom("x")
    if channel == 1:
        return generateRandom("y")
    if channel == 2:
        return generateRandom("z")


while True:
    for tableSlot in TableSlotList:
        for abcd in periods:
            time.sleep(0.1)
            record.update({abcd + "X": analog_read(0), abcd + "Y": analog_read(1), abcd + "Z": analog_read(2)})
        print record

        table_service.insert_or_replace_entity(getTableName(), "slot", tableSlot, record)
        queue_service.put_message(getQueueName(), record)
開發者ID:timmyreilly,項目名稱:HuggableCloudOffsite,代碼行數:31,代碼來源:SendCloudDataCopy.py

示例7: generateX

# 需要導入模塊: from azure.storage import TableService [as 別名]
# 或者: from azure.storage.TableService import insert_or_replace_entity [as 別名]
#table_service.insert_or_replace_entity(accel2, accel, tableSlot, periodSlot)

record = {}

#records = {'aX': generateX(),'aY': generateY(),'aZ': generateZ(),'bX': generateX(),'bY': generateY(),'bZ': generateZ(), 'cX': generateX(),'cY': generateY(),'cZ': generateZ(),'cX': generateX(),'cY': generateY(),'cZ': generateZ() }


while True: 

    for tableSlot in TableSlotList:
        for abcd in periods:
            time.sleep(0.1) 
            record.update({abcd+'Z': generateX(), abcd+'Y': generateY(), abcd+'Z': generateZ()})
        print record
        table_service.insert_or_replace_entity(getTableName(), 'slot', tableSlot, record)

while True: 

    for tableSlot in TableSlotList:
        for abcd in periods:
            time.sleep(0.1) 
            print tableSlot
            print abcd
            print record 
            xValue = generateX()
            yValue = generateY()
            zValue = generateZ()
            record.update({abcd+'Z': xValue, abcd+'Y': yValue, abcd+'Z': zValue})
        table_service.insert_or_replace_entity(getTableName(), 'slot', tableSlot, record)
    
開發者ID:timmyreilly,項目名稱:HuggableCloudOffsite,代碼行數:31,代碼來源:azurestoragesampler.py

示例8: get_input_type

# 需要導入模塊: from azure.storage import TableService [as 別名]
# 或者: from azure.storage.TableService import insert_or_replace_entity [as 別名]
while True:
    x = get_input_type()
    print x
    if x == "n":
        print "In 5 seconds start neutral"
        print "send 1000 points of data to ML set marked neutral"
        time.sleep(5.0)
        print "START"
        time.sleep(0.5)
        for tableSlot in TableSlotNeutral:
            for abcd in periods:
                time.sleep(0.25)
                record.update({abcd + "X": a_r(0), abcd + "Y": a_r(1), abcd + "Z": a_r(2)})
            print record
            print tableSlot
            table_service.insert_or_replace_entity(getMLTableName(), "NEUTRAL", tableSlot, record)
    elif x == "s":
        print "In 5 seconds start shaking"
        print "send 1000 points of data to ML set marked shaking"
        time.sleep(5.0)
        print "START"
        time.sleep(0.5)
        for tableSlot in TableSlotShaking:
            for abcd in periods:
                time.sleep(0.25)
                record.update({abcd + "X": a_r(0), abcd + "Y": a_r(1), abcd + "Z": a_r(2)})
            print record
            print tableSlot
            table_service.insert_or_replace_entity(getMLTableName(), "SHAKING", tableSlot, record)
    elif x == "sp":
        print "In 5 seconds start spinning"
開發者ID:timmyreilly,項目名稱:HuggableCloudOffsite,代碼行數:33,代碼來源:raspberryTrain.py

示例9: AzureGaugeDatastore

# 需要導入模塊: from azure.storage import TableService [as 別名]
# 或者: from azure.storage.TableService import insert_or_replace_entity [as 別名]
class AzureGaugeDatastore(GaugeDatastore):
    """Stores gauge data in Azure Table storage. Utilizes table storage
    as follows:

    PartitionKey: gauge name
    RowKey: date key (e.g. day string)
    data: stored data for date key
    Timestamp: last time data updated

    Replaces existing rows (PK+RK) with upsert queries. Has a limitation of
    returning max 1000 rows in a query. This suffices for now.
    """

    table_service = None
    table_name = None

    def __init__(self, account_name, account_key, table_name):
        self.table_name = table_name
        self.table_service = TableService(account_name, account_key)

    def save_data(self, gauge_name, date_key, data):
        """Saves data to the table row of date_key (replaces if exists)
        """

        entity = {'PartitionKey': gauge_name, 'RowKey': date_key, 'data': data}
        self.table_service.insert_or_replace_entity(self.table_name,
                                                    gauge_name, date_key,
                                                    entity)

    def get_gauge_data(self, gauge_name, min_date_key=None, max_date_key=None):
        """Retrieves all gauge data, returns unsorted.

        If min_date_key is specified, returns records with
        date_key >= min_date_key

        If max_date_key is specified, returns records with
        date_key < max_date_key

        IMPORTANT NOTE: Azure Table REST API returns first (oldest) 1000 rows
        in API call. Unless we add RowKey>min_date_key filter, after 1000
        rows (e.g. after 1000 days of recording) no fresh results will be
        returned.
        """

        query = "PartitionKey eq '{0}'".format(gauge_name)

        if min_date_key:
            query = "{0} and RowKey ge '{1}'".format(query, min_date_key)

        if max_date_key:
            query = "{0} and RowKey lt '{1}'".format(query, max_date_key)

        rows = self.table_service.query_entities(self.table_name, filter=query)
        if rows:
            return [make_record(record.RowKey, record.data) for record in rows]

    def get_data(self, gauge_name, date_key):
        """Retrieves gauge data for a specific date key (e.g. day)
        """

        rec = self.table_service.get_entity(self.table_name, gauge_name,
                                            date_key)
        if not rec:
            return None
        return helpers.make_record(rec.RowKey, rec.data)
開發者ID:ahmetalpbalkan,項目名稱:simplegauges,代碼行數:67,代碼來源:azuretable.py


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