44 lines
1.3 KiB
Python
44 lines
1.3 KiB
Python
# -*- coding: utf-8 -*-
|
|
"""显示台区分类映射数据"""
|
|
|
|
import os
|
|
from pathlib import Path
|
|
from dotenv import load_dotenv
|
|
import psycopg2
|
|
|
|
def main():
|
|
load_dotenv(Path(__file__).parent.parent / ".env")
|
|
dsn = os.getenv("PG_DSN")
|
|
conn = psycopg2.connect(dsn)
|
|
|
|
print("cfg_area_category 数据内容:")
|
|
print("=" * 90)
|
|
print(f"{'source_area_name':<15} {'category_code':<15} {'category_name':<12} {'match_type':<10} {'priority':<8}")
|
|
print("-" * 90)
|
|
|
|
with conn.cursor() as cur:
|
|
cur.execute("""
|
|
SELECT source_area_name, category_code, category_name, match_type, match_priority
|
|
FROM billiards_dws.cfg_area_category
|
|
ORDER BY match_priority, category_code, source_area_name
|
|
""")
|
|
for row in cur.fetchall():
|
|
print(f"{row[0]:<15} {row[1]:<15} {row[2]:<12} {row[3]:<10} {row[4]:<8}")
|
|
|
|
print("=" * 90)
|
|
print("\n分类汇总:")
|
|
with conn.cursor() as cur:
|
|
cur.execute("""
|
|
SELECT category_code, category_name, COUNT(*) as cnt
|
|
FROM billiards_dws.cfg_area_category
|
|
GROUP BY category_code, category_name
|
|
ORDER BY category_code
|
|
""")
|
|
for row in cur.fetchall():
|
|
print(f" {row[0]:<15} {row[1]:<12} {row[2]} 条规则")
|
|
|
|
conn.close()
|
|
|
|
if __name__ == "__main__":
|
|
main()
|