Download vcf.py from kjbytes/not_sure: direct link, hf CLI and curl.
- Browser
- Download file 1.17 kB
-
https://huggingface.co/spaces/kjbytes/not_sure/resolve/main/vcf.py
- Command line
-
hf download hf://spaces/kjbytes/not_sure/vcf.py
-
curl -L -o vcf.py https://huggingface.co/spaces/kjbytes/not_sure/resolve/main/vcf.py
1.17 kB
| import os | |
| import re | |
| VCF_DIR = "vcf" | |
| os.makedirs(VCF_DIR, exist_ok=True) | |
| def _safe_name(name): | |
| # ponytail: keep filenames filesystem-safe; fall back to "contact" | |
| name = (name or "contact").strip().replace(" ", "_") | |
| return re.sub(r"[^A-Za-z0-9_.-]", "", name) or "contact" | |
| def generate_vcf(data): | |
| filename = os.path.join(VCF_DIR, f"{_safe_name(data.get('name'))}.vcf") | |
| card = f"""BEGIN:VCARD | |
| VERSION:3.0 | |
| FN:{data.get('name', '')} | |
| ORG:{data.get('company', '')} | |
| TITLE:{data.get('designation', '')} | |
| TEL:{data.get('phone', '')} | |
| EMAIL:{data.get('email', '')} | |
| URL:{data.get('website', '')} | |
| ADR:{data.get('address', '')} | |
| END:VCARD | |
| """ | |
| with open(filename, "w") as f: | |
| f.write(card) | |
| return filename | |
| if __name__ == "__main__": | |
| # ponytail: one runnable check — the filename-safety path is the only real logic | |
| sample = {"name": "John Doe / CEO", "email": "j@abc.com"} | |
| path = generate_vcf(sample) | |
| assert os.path.basename(path) == "John_Doe__CEO.vcf", path | |
| assert "FN:John Doe / CEO" in open(path).read() | |
| assert _safe_name("") == "contact" | |
| assert _safe_name("../etc/passwd") == "..etcpasswd" | |
| print("ok", path) | |