#!/usr/bin/env python3 # -*- coding: utf-8 -*- import re, sys, os, html D = os.path.join(os.path.dirname(os.path.abspath(__file__)), "drf_말소등기전세권설정등기말소청구") def clean(x): x = re.sub(r'', '', x) x = re.sub(r'<[^>]+>', ' ', x) return re.sub(r'[ \t]+', ' ', html.unescape(x)).strip() def load(name): return open(os.path.join(D, name + ".xml"), encoding="utf-8", errors="replace").read() def basic(s): m = re.search(r'<기본정보>(.*?)', s, re.S) b = m.group(1) if m else s[:3000] out = {} for t in ['법령명_한글', '법령명한글', '시행일자', '공포일자', '공포번호', '법종구분']: mm = re.search(r'<%s[^>]*>(?:)?' % (t, t), b, re.S) if mm: out[t] = clean(mm.group(1)) return out def arts(s, wanted, maxlen=1100): res = [] for blk in re.findall(r'<조문단위[^>]*>.*?', s, re.S): no = re.search(r'<조문번호>(\d+)', blk) gi = re.search(r'<조문가지번호>(\d+)', blk) if not no: continue n = no.group(1) if gi: n = n + "-" + gi.group(1) if n not in wanted: continue eff = re.search(r'<조문시행일자>(\d+)', blk) yn = re.search(r'<조문여부>([^<]*)', blk) res.append((n, eff.group(1) if eff else '?', (yn.group(1) if yn else ''), clean(blk)[:maxlen])) return res def show(law, wanted, maxlen=1100): s = load(law) print("\n############ %s %s" % (law, basic(s))) for n, eff, yn, txt in arts(s, wanted, maxlen): print("--- 제%s조 [조문시행일자=%s] %s" % (n, eff, yn)) print(txt) if __name__ == "__main__": which = sys.argv[1] if which == "민법": show("L_민법", {"108", "214", "303", "306", "307", "311", "312", "313", "314", "317", "342", "370", "371", "404"}, 900) elif which == "부등법": show("L_부동산등기법", {"3", "23", "29", "52", "57"}, 2000) elif which == "집행": show("L_민사집행법", {"88", "91", "263"}, 1200) elif which == "소송": show("L_민사소송법", {"98", "102", "213", "251"}, 800) elif which == "소촉": show("L_소송촉진법", {"3"}, 1500) elif which == "회생": show("L_채무자회생법", {"59", "118", "347"}, 1500) elif which == "령": s = load("L_특례이율령") print(basic(s)) print(clean(s)[:4000])