-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAzureStorage.py
42 lines (31 loc) · 1.14 KB
/
AzureStorage.py
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
import AzureStorageClient
from azure.storage import CloudStorageAccount
# Reference:
# - https://github.com/Azure-Samples/storage-python-getting-started/tree/master/AzureStoragePythonGettingStarted
# - https://azure.microsoft.com/en-us/documentation/articles/storage-python-how-to-use-table-storage/
account=None
table_service = None
table_name = None
def Init(name,key):
global account, table_service
account = CloudStorageAccount(name,key)
print("storage account created")
table_service = account.create_table_service()
print("table service created")
def EnsureTable(table):
global table_service, table_name
table_name = table
if (table_service.exists(table_name)):
print("table exists %s" % table_name)
else:
table_service.create_table(table_name)
print("table created %s" % table_name)
def Update(pkey, rkey, entity):
global table_service, table_name
if (table_name == None):
print("please init table_name")
entity['PartitionKey']=pkey
entity['RowKey']=rkey
table_service.insert_or_replace_entity(table_name, entity)
def Query(filter_str):
return table_service.query_entities(table_name, filter=filter_str)