|
| 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)) |
0 commit comments