Spaces:
Sleeping

File size: 1,860 Bytes
1527bac
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/usr/bin/env python3
"""
Prepare a LinkedIn connections XLSX for upload.

The Curium master workbook is ~25 MB and contains 16 sheets (data, pivot
tables, message templates, etc.). HF Spaces' edge proxy can silently drop
the websocket frame for a file that large, so the in-app "Upload
Connections" widget appears to do nothing.

This script:
  1. Reads the XLSX
  2. Auto-picks the right data sheet (preferring "New Data" with the
     movement-tracking columns) using the same logic as the in-app loader
  3. Writes a clean CSV next to the original (~3-5 MB)

After running, upload the resulting CSV in the app — it will sail through.

Usage:
    venv/bin/python scripts/prep_connections.py <path-to-xlsx>

Example:
    venv/bin/python scripts/prep_connections.py \\
      "/Users/pierslyon/Downloads/LinkedIn Connection Data - April 2026 Update.xlsx"
"""

import sys
from pathlib import Path

REPO_ROOT = Path(__file__).resolve().parent.parent
sys.path.insert(0, str(REPO_ROOT))

from network_loader import convert_xlsx_to_csv


def main():
    if len(sys.argv) != 2:
        print(__doc__)
        sys.exit(1)

    src = Path(sys.argv[1]).expanduser().resolve()
    if not src.exists():
        print(f"ERROR: file not found: {src}")
        sys.exit(2)
    if src.suffix.lower() != ".xlsx":
        print(f"ERROR: expected .xlsx, got {src.suffix}")
        sys.exit(2)

    print(f"Reading: {src}")
    print(f"Size:    {src.stat().st_size / 1024 / 1024:.1f} MB")

    out_path = convert_xlsx_to_csv(str(src))
    out = Path(out_path)
    out_size_mb = out.stat().st_size / 1024 / 1024

    print(f"\nWrote: {out}")
    print(f"Size:  {out_size_mb:.1f} MB")
    print()
    print("Next: open the app, go to the sidebar Network section, and")
    print("      upload this CSV in the Upload Connections widget.")


if __name__ == "__main__":
    main()