本文整理匯總了Python中azure.storage.TableService.insert_entity方法的典型用法代碼示例。如果您正苦於以下問題:Python TableService.insert_entity方法的具體用法?Python TableService.insert_entity怎麽用?Python TableService.insert_entity使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類azure.storage.TableService
的用法示例。
在下文中一共展示了TableService.insert_entity方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: home
# 需要導入模塊: from azure.storage import TableService [as 別名]
# 或者: from azure.storage.TableService import insert_entity [as 別名]
def home():
"""Renders the home page."""
form = MessageForm(request.form)
if request.method == 'POST' and form.validate():
#Save to db
table_service = TableService(account_name=config.ACC_NAME,
account_key=config.ACC_KEY)
message = {'PartitionKey': 'message',
'RowKey': form.name.data + datetime.datetime.now().isoformat(),
'name' : form.name.data,
'email': form.email.data,
'date' : str(datetime.datetime.now())}
if form.message_body.data:
message["message"] = form.message_body.data
table_service.insert_entity('landingmessages', message)
return render_template(
'index.html',
hiden_block='#wright-us',
form=form,
)
return render_template(
'index.html',
hiden_block='#got-ur-message',
form=form,
)
示例2: friend_email_add
# 需要導入模塊: from azure.storage import TableService [as 別名]
# 或者: from azure.storage.TableService import insert_entity [as 別名]
def friend_email_add(mine,friend):
#SEE if my tuple is there .. is not then create and add else simple merge
print("\n\n\n\n\ running addin table ")
table_service = TableService(account_name='*****', account_key='******')
try:
task = table_service.get_entity('friendlisttable', 'friend', mine)
count=task.count
print(count)
field="friend"+str(count+1)
data={field:friend,'count':(count+1)}
table_service.insert_or_merge_entity('friendlisttable','friend',mine,data)
print("value 1 inserted via merge")
except Exception as e:
print(e)
print("your account was not there")
data= {'PartitionKey':'friend','RowKey':mine,'count':1,'friend1':friend}
table_service.insert_entity('friendlisttable', data)
print("value 1 added via create")
try:
task = table_service.get_entity('friendlisttable', 'friend', friend)
count=task.count
print(count)
field="friend"+str(count+1)
data={field:mine,'count':(count+1)}
table_service.insert_or_merge_entity('friendlisttable','friend',friend,data)
print("value 2 inserted via merge")
except Exception as e:
print(e)
print("your account was not there")
data= {'PartitionKey':'friend','RowKey':friend,'count':1,'friend1':mine}
table_service.insert_entity('friendlisttable', data)
print("value 2 added via create")
print("added al \n\n\n ")
示例3: __init__
# 需要導入模塊: from azure.storage import TableService [as 別名]
# 或者: from azure.storage.TableService import insert_entity [as 別名]
class AzureDataServices:
_partition = 'presence'
def __init__(self, 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
"""
t = time.strftime("%Y-%m-%d %H:%M:%S", time.gmtime())
task.PartitionKey = self._partition
task.RowKey = t
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
示例4: __init__
# 需要導入模塊: from azure.storage import TableService [as 別名]
# 或者: from azure.storage.TableService import insert_entity [as 別名]
class CustomerTable:
def __init__(self):
self.table_service = TableService(account_name='portalvhdspbrd34f2fnbl',account_key='y48JkXg+VcHQRCgsylJf4xV4Fd0AuJNkQKSwGhAR+BppHnFhkI+UHPOS/oYaTo0rqFCGQkEBW+thNFZNB9W8yg==')
def insert(self,ID,Name,Country,City):
task = {'PartitionKey': 'Customer',
'RowKey': ID,
'Name' : Name ,
'Country' : Country,
'City' : City}
try:
self.table_service.insert_entity('Customer', task)
except:
print"azure.WindowsAzureConflictError: Customer Conflict"
def listAll(self):
tasks = self.table_service.query_entities('Customer', "PartitionKey eq 'Customer'")
i=0
for task in tasks:
i=i+1
print("Name: %s, Country: %s, City: %s") %(task.Name,task.Country,task.City)
print("Total Customer: %s") %(i)
示例5: TableServiceTest
# 需要導入模塊: from azure.storage import TableService [as 別名]
# 或者: from azure.storage.TableService import insert_entity [as 別名]
class TableServiceTest(AzureTestCase):
def setUp(self):
self.ts = TableService(credentials.getStorageServicesName(),
credentials.getStorageServicesKey())
set_service_options(self.ts)
self.table_name = getUniqueName('uttable')
self.additional_table_names = []
def tearDown(self):
self.cleanup()
return super(TableServiceTest, self).tearDown()
def cleanup(self):
try:
self.ts.delete_table(self.table_name)
except:
pass
for name in self.additional_table_names:
try:
self.ts.delete_table(name)
except:
pass
#--Helpers-----------------------------------------------------------------
def _create_table(self, table_name):
'''
Creates a table with the specified name.
'''
self.ts.create_table(table_name, True)
def _create_table_with_default_entities(self, table_name, entity_count):
'''
Creates a table with the specified name and adds entities with the
default set of values. PartitionKey is set to 'MyPartition' and RowKey
is set to a unique counter value starting at 1 (as a string).
'''
entities = []
self._create_table(table_name)
for i in range(1, entity_count + 1):
entities.append(self.ts.insert_entity(
table_name,
self._create_default_entity_dict('MyPartition', str(i))))
return entities
def _create_default_entity_class(self, partition, row):
'''
Creates a class-based entity with fixed values, using all
of the supported data types.
'''
entity = Entity()
entity.PartitionKey = partition
entity.RowKey = row
entity.age = 39
entity.sex = 'male'
entity.married = True
entity.deceased = False
entity.optional = None
entity.ratio = 3.1
entity.large = 9333111000
entity.Birthday = datetime(1973, 10, 4)
entity.birthday = datetime(1970, 10, 4)
entity.binary = None
entity.other = EntityProperty('Edm.Int64', 20)
entity.clsid = EntityProperty(
'Edm.Guid', 'c9da6455-213d-42c9-9a79-3e9149a57833')
return entity
def _create_default_entity_dict(self, partition, row):
'''
Creates a dictionary-based entity with fixed values, using all
of the supported data types.
'''
return {'PartitionKey': partition,
'RowKey': row,
'age': 39,
'sex': 'male',
'married': True,
'deceased': False,
'optional': None,
'ratio': 3.1,
'large': 9333111000,
'Birthday': datetime(1973, 10, 4),
'birthday': datetime(1970, 10, 4),
'other': EntityProperty('Edm.Int64', 20),
'clsid': EntityProperty(
'Edm.Guid',
'c9da6455-213d-42c9-9a79-3e9149a57833')}
def _create_updated_entity_dict(self, partition, row):
'''
Creates a dictionary-based entity with fixed values, with a
different set of values than the default entity. It
adds fields, changes field values, changes field types,
and removes fields when compared to the default entity.
'''
return {'PartitionKey': partition,
'RowKey': row,
#.........這裏部分代碼省略.........
示例6: __init__
# 需要導入模塊: from azure.storage import TableService [as 別名]
# 或者: from azure.storage.TableService import insert_entity [as 別名]
class OrderTable:
def __init__(self):
self.table_service = TableService(account_name='portalvhdspbrd34f2fnbl',
account_key='y48JkXg+VcHQRCgsylJf4xV4Fd0AuJNkQKSwGhAR+BppHnFhkI+UHPOS/oYaTo0rqFCGQkEBW+thNFZNB9W8yg==')
def insert(self,ID,CustomerID,ProductID,Datetime,TotalPrice):
task = {'PartitionKey': 'Order',
'RowKey': ID,
'CustomerID' : CustomerID,
'ProductID' : ProductID,
'Datetime' : Datetime,
'TotalPrice' : TotalPrice}
try:
self.table_service.insert_entity('Order', task)
except:
print"azure.WindowsAzureConflictError: Order Conflict"
def listAll(self):
task1 = self.table_service.query_entities('Order', None, None, 1000)
task2 = self.table_service.query_entities('Order', None, None, 1000,
task1.x_ms_continuation['NextPartitionKey'],
task1.x_ms_continuation['NextRowKey'])
task3 = self.table_service.query_entities('Order', None, None, 1000,
task2.x_ms_continuation['NextPartitionKey'],
task2.x_ms_continuation['NextRowKey'])
task4 = self.table_service.query_entities('Order', None, None, 1000,
task3.x_ms_continuation['NextPartitionKey'],
task3.x_ms_continuation['NextRowKey'])
'''
task5 = self.table_service.query_entities('Order', None, None, 1000,
task4.x_ms_continuation['NextPartitionKey'],
task4.x_ms_continuation['NextRowKey'])
task6 = self.table_service.query_entities('Order', None, None, 1000,
task5.x_ms_continuation['NextPartitionKey'],
task5.x_ms_continuation['NextRowKey'])
task7 = self.table_service.query_entities('Order', None, None, 1000,
task6.x_ms_continuation['NextPartitionKey'],
task6.x_ms_continuation['NextRowKey'])
task8 = self.table_service.query_entities('Order', None, None, 1000,
task7.x_ms_continuation['NextPartitionKey'],
task7.x_ms_continuation['NextRowKey'])
task9 = self.table_service.query_entities('Order', None, None, 1000,
task8.x_ms_continuation['NextPartitionKey'],
task8.x_ms_continuation['NextRowKey'])
task10 = self.table_service.query_entities('Order', None, None, 1000,
task9.x_ms_continuation['NextPartitionKey'],
task9.x_ms_continuation['NextRowKey'])
'''
i=0
for task in task1:
i=i+1
'''
print("ID: %s, CustomerID: %s, ProductID: %s, Datetime: %s, TotalPrice: %s") %(task.RowKey,
task.CustomerID,task.ProductID,task.Datetime,task.TotalPrice)
'''
print(task.TotalPrice)
for task in task2:
i=i+1
print(task.TotalPrice)
print("Total Order: %s") %(i)
def TableInfo(self):
info=self.table_service.query_tables()
for i in info:
print(i.name)
示例7: TableServiceTest
# 需要導入模塊: from azure.storage import TableService [as 別名]
# 或者: from azure.storage.TableService import insert_entity [as 別名]
class TableServiceTest(AzureTestCase):
def setUp(self):
self.tc = TableService(account_name=credentials.getStorageServicesName(),
account_key=credentials.getStorageServicesKey())
proxy_host = credentials.getProxyHost()
proxy_port = credentials.getProxyPort()
if proxy_host:
self.tc.set_proxy(proxy_host, proxy_port)
__uid = getUniqueTestRunID()
table_base_name = u'testtable%s' % (__uid)
self.table_name = getUniqueNameBasedOnCurrentTime(table_base_name)
self.additional_table_names = []
def tearDown(self):
self.cleanup()
return super(TableServiceTest, self).tearDown()
def cleanup(self):
try:
self.tc.delete_table(self.table_name)
except: pass
for name in self.additional_table_names:
try:
self.tc.delete_table(name)
except: pass
#--Helpers-----------------------------------------------------------------
def _create_table(self, table_name):
'''
Creates a table with the specified name.
'''
self.tc.create_table(table_name, True)
def _create_table_with_default_entities(self, table_name, entity_count):
'''
Creates a table with the specified name and adds entities with the
default set of values. PartitionKey is set to 'MyPartition' and RowKey
is set to a unique counter value starting at 1 (as a string).
'''
entities = []
self._create_table(table_name)
for i in range(1, entity_count + 1):
entities.append(self.tc.insert_entity(table_name, self._create_default_entity_dict('MyPartition', str(i))))
return entities
def _create_default_entity_class(self, partition, row):
'''
Creates a class-based entity with fixed values, using all
of the supported data types.
'''
# TODO: Edm.Binary and null
entity = Entity()
entity.PartitionKey = partition
entity.RowKey = row
entity.age = 39
entity.sex = 'male'
entity.married = True
entity.deceased = False
entity.optional = None
entity.ratio = 3.1
entity.large = 9333111000
entity.Birthday = datetime(1973,10,04)
entity.birthday = datetime(1970,10,04)
entity.binary = None
entity.other = EntityProperty('Edm.Int64', 20)
entity.clsid = EntityProperty('Edm.Guid', 'c9da6455-213d-42c9-9a79-3e9149a57833')
return entity
def _create_default_entity_dict(self, partition, row):
'''
Creates a dictionary-based entity with fixed values, using all
of the supported data types.
'''
# TODO: Edm.Binary and null
return {'PartitionKey':partition,
'RowKey':row,
'age':39,
'sex':'male',
'married':True,
'deceased':False,
'optional':None,
'ratio':3.1,
'large':9333111000,
'Birthday':datetime(1973,10,04),
'birthday':datetime(1970,10,04),
'binary':EntityProperty('Edm.Binary', None),
'other':EntityProperty('Edm.Int64', 20),
'clsid':EntityProperty('Edm.Guid', 'c9da6455-213d-42c9-9a79-3e9149a57833')}
def _create_updated_entity_dict(self, partition, row):
'''
Creates a dictionary-based entity with fixed values, with a
different set of values than the default entity. It
adds fields, changes field values, changes field types,
and removes fields when compared to the default entity.
'''
#.........這裏部分代碼省略.........
示例8: TableService
# 需要導入模塊: from azure.storage import TableService [as 別名]
# 或者: from azure.storage.TableService import insert_entity [as 別名]
#!/usr/bin/env python
from azure.storage import TableService
from datetime import datetime
ts = TableService(account_name='freedu', account_key='P0WNSyFp2Fs32lTY52bN3DFFq/wPQcaBGbnC7xMOcS4U2zsXJoASgVUqux0TEtVgqn8Wfl6jxXpkGfy5ZaWCzQ==')
try:
ts.create_table('tasktable')
ts.insert_entity(
'tasktable',
{
'PartitionKey' : 'tasksSeattle',
'RowKey': '1',
'Description': 'Take out the trash',
'DueDate': datetime(2011, 12, 14, 12)
}
)
except Exception,ex:
print ex
print 'create table done.'
entity = ts.get_entity('tasktable', 'tasksSeattle', '1')
print 'get_entity done.'
print entity
示例9: Repository
# 需要導入模塊: from azure.storage import TableService [as 別名]
# 或者: from azure.storage.TableService import insert_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
示例10: __init__
# 需要導入模塊: from azure.storage import TableService [as 別名]
# 或者: from azure.storage.TableService import insert_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
示例11: TableService
# 需要導入模塊: from azure.storage import TableService [as 別名]
# 或者: from azure.storage.TableService import insert_entity [as 別名]
from azure.storage import TableService, Entity
table_service = TableService(account_name='upmsample', account_key='5YC/6x9KL56rtaAUAZMgGsREDvvPHYJIMqH3z1c9IgQLy0qMP+Awr+7j51Tfzniczj//6jn7lvYQutD/mHm6dw==')
table_service.create_table('table1')
task = {'PartitionKey': 'ledswitch', 'RowKey': '1', 'state' :1}
table_service.insert_entity('table1', task)
示例12: values
# 需要導入模塊: from azure.storage import TableService [as 別名]
# 或者: from azure.storage.TableService import insert_entity [as 別名]
#Comment out azure SQL part as we decide to use Table Storage
#cursor.execute('INSERT INTO [dbo].[Stores] \
# ([store_name],[start_date],[end_date],[description],[description_cn]) \
# values (?,?,?,?,?)', \
# store_name,start_date,end_date,description,description_cn)
#cnxn.commit()
#Insert data to Table Storage
task = Entity()
task.PartitionKey = 'Outlets'
task.RowKey = store_name
task.StartDate = start_date
task.EndDate = end_date
task.Description = description
task.Description_CN = description_cn
table_service.insert_entity('Outlets', task)
print(store_name)
print(start_date)
print(end_date)
print(description)
print(description_cn)
elif len(date_string.split(" ")) == 6:
start_date_string = date_string.split(" ")[0] + ' ' + \
date_string.split(" ")[1] + ' ' + date_string.split(" ")[-1]
end_date_string = date_string.split(" ")[3] + ' ' + \
date_string.split(" ")[4] + ' ' + date_string.split(" ")[-1]
start_date = datetime.strptime(start_date_string, '%b %d %Y')
end_date = datetime.strptime(end_date_string, '%b %d %Y')