Skip to content

Instantly share code, notes, and snippets.

@horvatha
Last active August 6, 2022 13:08
Show Gist options
  • Save horvatha/81b4f0c611ee5d189c42b23d76840adf to your computer and use it in GitHub Desktop.
Save horvatha/81b4f0c611ee5d189c42b23d76840adf to your computer and use it in GitHub Desktop.
A földhivatal fájljából adatok kinyerése
Ebből indulva https://pastebin.com/raw/nPbzGFmu
az eredmény:
Szakasz: Tulajdonosi adatok
{'Tul.hányad': '1/2', 'Szerz.jogcím': 'adásvétel', 'Név': 'Gipsz Csaba', 'Anyja neve': 'Próba Katalin', 'Jogállás': 'tulajdonos', 'Cím': '4965 MINTA, Kölcsey utca 105'}
{'Tul.hányad': '1/2', 'Szerz.jogcím': 'adásvétel', 'Név': 'Gipsz Csabáné', 'Szül.név': 'Gipsz Éva', 'Anyja neve': 'Minta Borbála', 'Jogállás': 'tulajdonos', 'Cím': '4965 MINTA, Kölcsey utca 105'}
Szakasz: Jogok-tények jogosultjai
{'Jog-tény neve': 'Önálló szöveges bejegyzés', 'Szöveg': 'Lakcímváltozás átvezetése.'}
{'Jog-tény neve': 'Jelzálogjog', 'Név': 'MAGYAR ÁLLAM', 'Cím': '-,'}
{'Jog-tény neve': 'Elidegenítési és terhelési tilalom', 'Név': 'MAGYAR ÁLLAM', 'Cím': '-,', 'Utalások': 'III/14'}
{'Jog-tény neve': 'Jelzálogjog', 'Név': 'MAGYAR ÁLLAM', 'Cím': '-,', 'Szöveg': '2. zálogjogi ranghely - 5 évre -'}
{'Jog-tény neve': 'Elidegenítési és terhelési tilalom', 'Név': 'MAGYAR ÁLLAM', 'Cím': '-,', 'Utalások': 'III/16'}
import re
import string
from typing import Callable
def get_sections(text_lines: list[str], get_start_ends: Callable = None) -> list[str]:
if get_start_ends is None:
get_start_ends = get_section_start_ends
start_ends = get_start_ends(text_lines)
return [text_lines[start:end+1] for start, end in start_ends]
def get_subsections(section: list[str]) -> list[str]:
return get_sections(section, get_start_ends=get_subsection_start_ends)
def get_data(subsection: list[str]) -> dict:
result = {}
for line in subsection[1:]:
sline = line.strip()
if sline:
split = line.split(":")
if len(split) == 2:
key, value = split
result[key.strip()] = value.strip()
return result
def get_subsection_start_ends(text_lines: list[str]) -> list[tuple[int, int]]:
starts = [i for i, line in enumerate(text_lines) if re.match(r"\s+Sorszám:", line)]
start_ends = [(i, j-1) for i, j in zip([None] + starts, starts + [len(text_lines)])][1:]
return start_ends
def get_section_start_ends(text_lines: list[str]) -> list[tuple[int, int]]:
starts = [i for i, line in enumerate(text_lines) if re.match(" [A-Z]", line)]
last_start = starts[-1]
finish_bar_index = next(filter(lambda x: x[0] > last_start and re.match(r"\s+____", x[1]), enumerate(text_lines)))[0]
start_ends = [(i, j-1) for i, j in zip([None] + starts, starts + [finish_bar_index])][1:]
return start_ends
def main():
text_lines = open("foldhiv.txt").read().splitlines()
sections = get_sections(text_lines)
for section in sections:
print(f"Szakasz: {section[0].strip()}")
for sorszamozott in get_subsections(section):
print(get_data(sorszamozott))
if __name__ == '__main__':
main()
from parse_foldhiv import get_section_start_ends, get_sections, get_subsection_start_ends, get_subsections
text_lines = """
Tulajdonosi adatok
Sorszám: 9 Bejegyzõ határozat: 150089/4/2020.03.03
Tul.hányad: 1/2
Szerz.jogcím: adásvétel
Név: Gipsz Csaba
Szül.idõ: 1979.12.30 Szül.hely: Fehérgyarmat
Anyja neve: Próba Katalin
Jogállás: tulajdonos
Cím: 4965 MINTA, Kölcsey utca 105
Sorszám: 10 Bejegyzõ határozat: 150089/4/2020.03.03
Tul.hányad: 1/2
Szerz.jogcím: adásvétel
Név: Gipsz Csabáné
Szül.név: Gipsz Éva
Szül.idõ: 1978.07.13 Szül.hely: Fehérgyarmat
Anyja neve: Minta Borbála
Jogállás: tulajdonos
Cím: 4965 MINTA, Kölcsey utca 105
Jogok-tények jogosultjai
Sorszám: 5 Bejegyzõ határozat: 38712/2005.12.20
Jog-tény neve: Önálló szöveges bejegyzés
Szöveg: Lakcímváltozás átvezetése.
Sorszám: 14 Bejegyzõ határozat: 154041/2/2021.05.14
Jog-tény neve: Jelzálogjog
erejéig
Név: MAGYAR ÁLLAM
Cím: -,
Szöveg: 1. zálogjogi ranghely - CSOK - Képviseli: SZ-SZ-B. MEGYEI KORMÁNYHIVATAL
CSALÁDTÁMOGATÁSI ÉS TÁRSADALOMBIZTOSÍTÁSI FÕOSZTÁLY EGÉSZSÉBIZTOSÍTÁSI
NYILVÁNTARTÁSI ÉS LAKÁSTÁMOGATÁSI OSZTÁLY (4400 Nyíregyháza, Vörösmarty tér
7.)
_________
""".splitlines()
def test_get_section_start_ends():
assert get_section_start_ends(text_lines) == [(1, 20), (21, 35)]
def test_get_subsection_start_ends():
subsec1, *others = get_sections(text_lines)
assert get_subsection_start_ends(subsec1) == [(1, 9), (10, 19)]
def test_get_sections():
sections = get_sections(text_lines)
assert len(sections) == 2
sec1, sec2 = sections
assert sec1[0] == ' Tulajdonosi adatok'
assert sec1[-2] == ' Cím: 4965 MINTA, Kölcsey utca 105'
assert sec2[0] == ' Jogok-tények jogosultjai'
assert sec2[-2] == ' 7.)'
def test_get_subsections():
sections = get_sections(text_lines)
subsecs = get_subsections(sections[0])
assert len(subsecs) == 2
subsec1, subsec2 = subsecs
assert subsec1[0] == ' Sorszám: 9 Bejegyzõ határozat: 150089/4/2020.03.03'
assert subsec1[-2] == ' Cím: 4965 MINTA, Kölcsey utca 105'
assert subsec2[0] == ' Sorszám: 10 Bejegyzõ határozat: 150089/4/2020.03.03'
assert subsec2[-2] == ' Cím: 4965 MINTA, Kölcsey utca 105'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment