瀏覽代碼

Add CSV generator tool

Jonas Wielicki 1 年之前
父節點
當前提交
d8ed29765f
共有 1 個文件被更改,包括 54 次插入0 次删除
  1. 54
    0
      tools/xeplist-to-csv.py

+ 54
- 0
tools/xeplist-to-csv.py 查看文件

@@ -0,0 +1,54 @@
1
+#!/usr/bin/python3
2
+import csv
3
+import sys
4
+
5
+import xml.etree.ElementTree as etree
6
+
7
+from xeplib import load_xepinfos
8
+
9
+
10
+def main():
11
+    import argparse
12
+
13
+    parser = argparse.ArgumentParser()
14
+
15
+    parser.add_argument(
16
+        "-l", "--xeplist",
17
+        type=argparse.FileType("rb"),
18
+        default=None,
19
+        help="XEP list to use (defaults to ./build/xeplist.xml)"
20
+    )
21
+
22
+    parser.add_argument(
23
+        "-d", "--dialect",
24
+        default="unix",
25
+    )
26
+
27
+    parser.add_argument(
28
+        "outfile",
29
+    )
30
+
31
+    args = parser.parse_args()
32
+
33
+    if args.xeplist is None:
34
+        args.xeplist = open("./build/xeplist.xml", "rb")
35
+
36
+    with args.xeplist as f:
37
+        tree = etree.parse(f)
38
+
39
+    accepted, _ = load_xepinfos(tree)
40
+
41
+    with open(args.outfile, "w") as f:
42
+        writer = csv.writer(f, args.dialect)
43
+        for number, info in sorted(accepted.items()):
44
+            writer.writerow([
45
+                number,
46
+                info["title"],
47
+                info["status"].value,
48
+                info["last_revision"]["date"].date(),
49
+                info["last_revision"]["version"],
50
+            ])
51
+
52
+
53
+if __name__ == "__main__":
54
+    main()

Loading…
取消
儲存