Skip to content

Instantly share code, notes, and snippets.

Created August 21, 2022 12:15
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Extract data from SQL Server:
# 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"'"-- Getting tag metadata...")
# 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)"Done.\n")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment