marketmute: final merge — VIES-fullföljd + encoding-fix -> marketmute_targets_final.jsonl
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Slutmerge: targets_v3 + ALL VIES-data + encoding-fix -> marketmute_targets_final.jsonl"""
|
||||
import json
|
||||
|
||||
def fix_enc(t):
|
||||
"""Fixa mangled encoding (latin-1 läst som utf-8) -> korrekt svensk text."""
|
||||
if not t or "Ã" not in t:
|
||||
return t
|
||||
try:
|
||||
return t.encode("latin-1").decode("utf-8")
|
||||
except Exception:
|
||||
return t
|
||||
|
||||
# 1. Samla ALL VIES-data (båda filerna)
|
||||
vies = {}
|
||||
for path in ("/data/0pt/output/vies_targets.jsonl", "/data/0pt/output/vies_extra.jsonl"):
|
||||
try:
|
||||
for line in open(path):
|
||||
r = json.loads(line)
|
||||
vies[r["orgnr_fmt"]] = r
|
||||
except FileNotFoundError:
|
||||
pass
|
||||
print(f"[VIES] {len(vies):,} kontrollerade totalt")
|
||||
|
||||
# 2. Merge targets
|
||||
n = 0; with_vies = 0
|
||||
with open("/data/0pt/output/marketmute_targets_final.jsonl", "w") as out:
|
||||
for line in open("/data/0pt/output/marketmute_targets_v3.jsonl"):
|
||||
t = json.loads(line)
|
||||
org = t["orgnr"]
|
||||
# encoding-fix på textfält
|
||||
t["namn"] = fix_enc(t.get("namn"))
|
||||
t["verksamhet"] = fix_enc(t.get("verksamhet"))
|
||||
for p in t.get("kontaktpersoner", []):
|
||||
p["namn"] = fix_enc(p.get("namn"))
|
||||
# VIES-merge
|
||||
v = vies.get(org)
|
||||
if v and v.get("moms_valid") is not None:
|
||||
t["moms_valid"] = v["moms_valid"]
|
||||
t["momsnr"] = v.get("momsnr")
|
||||
if v.get("moms_namn"):
|
||||
t["moms_namn"] = fix_enc(v["moms_namn"])
|
||||
with_vies += 1
|
||||
else:
|
||||
t["moms_valid"] = None
|
||||
t["momsnr"] = f"SE{org.replace('-','')}01"
|
||||
out.write(json.dumps(t, ensure_ascii=False) + "\n")
|
||||
n += 1
|
||||
print(f"[KLAR] {n:,} targets -> marketmute_targets_final.jsonl ({with_vies:,} med moms-status)")
|
||||
Reference in New Issue
Block a user