-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexport_opencode_tokens.py
More file actions
31 lines (22 loc) · 932 Bytes
/
export_opencode_tokens.py
File metadata and controls
31 lines (22 loc) · 932 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import sys
from pathlib import Path
from opencode_token_app.data_loader import load_usage_from_db
from opencode_token_app.exporter import export_usage_csvs
from opencode_token_app.pricing import price_loaded_usage
def parse_args(argv):
if len(argv) < 2:
print("用法:python export_opencode_tokens.py <opencode.db路径> [输出目录]")
raise SystemExit(1)
db_path = Path(argv[1]).expanduser().resolve()
if not db_path.exists():
print(f"数据库不存在:{db_path}")
raise SystemExit(1)
out_dir = Path(argv[2]).expanduser().resolve() if len(argv) >= 3 else db_path.parent / "token_export"
return db_path, out_dir
def main():
db_path, out_dir = parse_args(sys.argv)
datasets = load_usage_from_db(db_path)
datasets = price_loaded_usage(datasets, entry_path=Path(sys.argv[0]))
export_usage_csvs(out_dir, datasets)
if __name__ == "__main__":
main()