Skip to content

Commit 85eae22

Browse files
author
OD1995
committed
Uploading txt to blob storage test
1 parent e263f1e commit 85eae22

6 files changed

Lines changed: 100 additions & 0 deletions

File tree

HttpTrigger7/__init__.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import logging
2+
import pyodbc
3+
import pandas as pd
4+
import azure.functions as func
5+
6+
7+
def main(req: func.HttpRequest) -> func.HttpResponse:
8+
logging.info("getAzureBlobVideos started")
9+
## Get information used to create connection string
10+
username = 'matt.shepherd'
11+
# password = os.getenv("sqlPassword")
12+
password = "4rsenal!PG01"
13+
driver = '{ODBC Driver 17 for SQL Server}'
14+
# server = os.getenv("sqlServer")
15+
server = "fse-inf-live-uk.database.windows.net"
16+
database = 'AzureCognitive'
17+
table = 'AzureBlobVideos'
18+
## Create connection string
19+
connectionString = f'DRIVER={driver};SERVER={server};PORT=1433;DATABASE={database};UID={username};PWD={password}'
20+
logging.info(f'Connection string created: {connectionString}')
21+
## Create SQL query to use
22+
sqlQuery = f"SELECT * FROM {table}"
23+
with pyodbc.connect(connectionString) as conn:
24+
## Get SQL table in pandas DataFrame
25+
df = pd.read_sql(sql=sqlQuery,
26+
con=conn)
27+
logging.info(f"Dataframe with shape {df.shape} received")
28+
## Dict - VideoName : (Sport,Event)
29+
dfDict = {vn : (s,e)
30+
for vn,s,e in zip(df.VideoName,
31+
df.Sport,
32+
df.Event)}
33+
34+
return func.HttpResponse(str(dfDict))

HttpTrigger7/function.json

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"scriptFile": "__init__.py",
3+
"bindings": [
4+
{
5+
"authLevel": "anonymous",
6+
"type": "httpTrigger",
7+
"direction": "in",
8+
"name": "req",
9+
"methods": [
10+
"get",
11+
"post"
12+
]
13+
},
14+
{
15+
"type": "http",
16+
"direction": "out",
17+
"name": "$return"
18+
}
19+
]
20+
}

HttpTrigger7/sample.dat

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"name": "Azure"
3+
}

HttpTrigger8/__init__.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import logging
2+
from azure.storage.blob import BlockBlobService
3+
4+
import azure.functions as func
5+
6+
7+
def main(req: func.HttpRequest) -> func.HttpResponse:
8+
## Create BlockBlobService
9+
connectionStringOutput = "DefaultEndpointsProtocol=https;AccountName=fsevideos;AccountKey=xfYncTDRCowSrISbdsSknM05jqOrJXc4Oavq7BQ56yR7uQ7MCeL5aXmBsbsE+SZ+++xGt2oy6FvrEdpryc+vwQ==;EndpointSuffix=core.windows.net"
10+
block_blob_service = BlockBlobService(connection_string=connectionStringOutput)
11+
logging.info(f'BlockBlobService created for account "{block_blob_service.account_name}"')
12+
## Create some text to upload to the blob storage account
13+
s = "some test letters"
14+
logging.info(f"About to create txt file containing '{s}'")
15+
## Create blob
16+
block_blob_service.create_blob_from_text(container_name="us-office",
17+
blob_name=s,
18+
text="test.txt")
19+
logging.info("Blob created")
20+
return func.HttpResponse(str(s))

HttpTrigger8/function.json

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"scriptFile": "__init__.py",
3+
"bindings": [
4+
{
5+
"authLevel": "anonymous",
6+
"type": "httpTrigger",
7+
"direction": "in",
8+
"name": "req",
9+
"methods": [
10+
"get",
11+
"post"
12+
]
13+
},
14+
{
15+
"type": "http",
16+
"direction": "out",
17+
"name": "$return"
18+
}
19+
]
20+
}

HttpTrigger8/sample.dat

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"name": "Azure"
3+
}

0 commit comments

Comments
 (0)