Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2026-08-31 08:19:05

0001 #!/usr/bin/env python3
0002 # -*- coding: utf-8 -*-
0003 """
0004 Created on February 13 13:51 2025
0005 Created in PyCharm
0006 Created as sphenix_pp_qa/print_spindb_info_for_latex
0007 
0008 @author: Dylan Neff, dn277127
0009 """
0010 
0011 import subprocess
0012 
0013 def main():
0014     # Database connection details
0015     dbname = "spinDB"
0016     table_name = "spin"
0017 
0018     # SQL query to get column names and data types
0019     query = f"""
0020     SELECT column_name, data_type
0021     FROM information_schema.columns
0022     WHERE table_name = '{table_name}'
0023     ORDER BY ordinal_position;
0024     """
0025 
0026     # Run the psql command using subprocess and capture the output
0027     command = f"psql -d {dbname} -c \"{query}\" -t -A"
0028     result = subprocess.run(command, shell=True, capture_output=True, text=True)
0029 
0030     # Split the output into lines
0031     lines = result.stdout.strip().split("\n")
0032 
0033     # Start LaTeX table code using longtable for page splitting
0034     latex_code = """\\begin{longtable}{|l|l|l|}
0035 \\caption{Table structure of '""" + table_name + """'} \\\\
0036 \\label{tab:spindb_cols} \\\\
0037 \\hline
0038 Column Name & Data Type & Notes \\\\ \\hline
0039 \\endfirsthead
0040 \\hline
0041 Column Name & Data Type & Notes \\\\ \\hline
0042 \\endhead
0043 """
0044 
0045     # Process each line of the result
0046     for line in lines:
0047         line = line.strip().split("|")
0048         if len(line) != 2:
0049             print(f"Skipping line: {line}")
0050             continue
0051         column_name, data_type = line  # Output columns are separated by '|'
0052         column_name = column_name.strip().replace('_', '\\_')
0053         data_type = data_type.strip()
0054         latex_code += f"{column_name} & {data_type} & \\\\ \\hline\n"
0055 
0056     latex_code += "\\end{longtable}"
0057 
0058     # Print the LaTeX code
0059     print(latex_code)
0060     print('donzo')
0061 
0062 if __name__ == '__main__':
0063     main()