Extract data from SQL Server: https://h3xagn.com
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# retrieve tag metadata | |
query = """ | |
set nocount on; | |
print 'TagID,TagName,Description,ChangeTimestamp,SourceUniqueTagID,Maximum,Minimum,EngUnits'; | |
select [TagID],[TagName],REPLACE([Description], ',', '') AS [Description],[ChangeTimestamp],[SourceUniqueTagID],[Maximum],[Minimum],[EngUnits] | |
from TagManager_Tags; | |
""" | |
sqlcmd = f'sqlcmd -S {server} -d ProcessDataDB -U {username} -P {password} -Q "{query}" -s "," -h -1 -W -o "./data/{site}_metadata.csv"' | |
logger.info("-- Getting tag metadata...") | |
os.system(sqlcmd) | |
# read metadata and compress it | |
df = pd.read_csv(f"./data/{site}_metadata.csv") | |
df.to_csv(f"./data/{site}_metadata.csv.gz", compression="gzip", index=False) | |
logger.info(f"Done.\n") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment