extract-sqlite 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,12 @@
1
+ Metadata-Version: 2.3
2
+ Name: extract-sqlite
3
+ Version: 0.1.0
4
+ Summary: Add your description here
5
+ Author: 6vi7ms
6
+ Author-email: 6vi7ms <6vi7ms@gmail.com>
7
+ Requires-Dist: click>=8.5.1
8
+ Requires-Dist: openpyxl>=3.1.5
9
+ Requires-Dist: pandas>=3.1.1
10
+ Requires-Python: >=3.13
11
+ Description-Content-Type: text/markdown
12
+
File without changes
@@ -0,0 +1,22 @@
1
+ [project]
2
+ name = "extract-sqlite"
3
+ version = "0.1.0"
4
+ description = "Add your description here"
5
+ readme = "README.md"
6
+ requires-python = ">=3.13"
7
+ dependencies = [
8
+ "click>=8.5.1",
9
+ "openpyxl>=3.1.5",
10
+ "pandas>=3.1.1",
11
+ ]
12
+
13
+ [[project.authors]]
14
+ name = "6vi7ms"
15
+ email = "6vi7ms@gmail.com"
16
+
17
+ [project.scripts]
18
+ extract-sqlite = "extract_sqlite.main:main"
19
+
20
+ [build-system]
21
+ requires = ["uv_build>=0.12.18,<0.13.0"]
22
+ build-backend = "uv_build"
@@ -0,0 +1,21 @@
1
+ [project]
2
+ name = "extract-sqlite"
3
+ version = "0.1.0"
4
+ description = "Add your description here"
5
+ readme = "README.md"
6
+ authors = [
7
+ { name = "6vi7ms", email = "6vi7ms@gmail.com" }
8
+ ]
9
+ requires-python = ">=3.13"
10
+ dependencies = [
11
+ "click>=8.5.1",
12
+ "openpyxl>=3.1.5",
13
+ "pandas>=3.1.1",
14
+ ]
15
+
16
+ [project.scripts]
17
+ extract-sqlite = "extract_sqlite.main:main"
18
+
19
+ [build-system]
20
+ requires = ["uv_build>=0.12.18,<0.13.0"]
21
+ build-backend = "uv_build"
@@ -0,0 +1,2 @@
1
+ def main() -> None:
2
+ print("Hello from extract-sqlite!")
@@ -0,0 +1,41 @@
1
+ import sqlite3
2
+
3
+ import click
4
+ import pandas as pd
5
+
6
+
7
+ @click.command()
8
+ @click.option("--db", "-d", required=True, type=click.Path(exists=True), help="เส้นทางไปยังไฟล์ SQLite database")
9
+ @click.option("--output", "-o", default="output.xlsx", help="ชื่อไฟล์ Excel ที่ต้องการส่งออก (ค่าเริ่มต้น: output.xlsx)")
10
+ def main(db, output):
11
+ """ส่งออกข้อมูลทุกตารางจาก SQLite database ไปเป็นไฟล์ Excel โดยแยกตามชื่อ Sheet"""
12
+ click.echo(f"กำลังเชื่อมต่อกับฐานข้อมูล: {db}")
13
+ conn = sqlite3.connect(db)
14
+
15
+ try:
16
+ tables_query = "SELECT name FROM sqlite_master WHERE type='table' AND name NOT LIKE 'sqlite_%';"
17
+ tables = pd.read_sql(tables_query, conn)["name"].tolist()
18
+
19
+ if not tables:
20
+ click.echo("ไม่พบตารางข้อมูลในฐานข้อมูลนี้", err=True)
21
+ return
22
+
23
+ click.echo(f"พบตารางทั้งหมด: {', '.join(tables)}")
24
+
25
+ with pd.ExcelWriter(output, engine="openpyxl") as writer:
26
+ for table in tables:
27
+ df = pd.read_sql(f"SELECT * FROM [{table}]", conn)
28
+ sheet_name = table[:31] # Excel จำกัดชื่อ Sheet ที่ 31 ตัวอักษร
29
+ df.to_excel(writer, sheet_name=sheet_name, index=False)
30
+ click.echo(f" - ส่งออกตาราง '{table}' -> Sheet '{sheet_name}' ({len(df)} แถว)")
31
+
32
+ click.echo(f"\nส่งออกข้อมูลสำเร็จ! บันทึกไฟล์ที่: {output} 🎉")
33
+
34
+ except Exception as e:
35
+ click.echo(f"เกิดข้อผิดพลาด: {e}", err=True)
36
+ finally:
37
+ conn.close()
38
+
39
+
40
+ if __name__ == "__main__":
41
+ main()