Repository navigation
Expand file tree
/
Copy pathgenerate.py
More file actions
938 lines (832 loc) · 34.7 KB
/
Copy pathgenerate.py
File metadata and controls
938 lines (832 loc) · 34.7 KB
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
#!/usr/bin/env python3
from __future__ import annotations
import datetime as dt
import json
import os
import re
import sys
import urllib.error
import urllib.request
from pathlib import Path
USER = "dSofikitis"
ASSETS = Path("assets")
# MSC_START = dt.date(2026, 8, 10) # old
MSC_LABEL = "MSc Digital Infra and CySec · At NTNU, Trondheim, Norway"
PALETTES = {
"dark": {
"bg": "#000000",
"text": "#e0e0e0",
"dim": "#777777",
"accent": "#cc0000",
"accent_dim": "#660000",
"cyan": "#00d4aa",
"amber": "#ffab00",
"blue": "#448aff",
"panel_border": "rgba(224,224,224,0.10)",
"panel_inner": "rgba(224,224,224,0.04)",
"rule": "rgba(224,224,224,0.08)",
"bar_track": "rgba(224,224,224,0.08)",
},
"light": {
"bg": "#f0f0f0",
"text": "#1a1a1a",
"dim": "#888888",
"accent": "#cc0000",
"accent_dim": "#ffcccc",
"cyan": "#009688",
"amber": "#e65100",
"blue": "#1565c0",
"panel_border": "rgba(0,0,0,0.10)",
"panel_inner": "rgba(0,0,0,0.03)",
"rule": "rgba(0,0,0,0.08)",
"bar_track": "rgba(0,0,0,0.08)",
},
}
PANEL_RX = 10
OUTER_PAD_TOP = 32
OUTER_PAD_BOTTOM = 12
LABEL_Y = OUTER_PAD_TOP - 10
def rounded_path(x: float, y: float, w: float, h: float, r: float, corners: str) -> str:
tl = tr = bl = br = 0.0
if corners in ("top", "all"):
tl = tr = r
if corners in ("bottom", "all"):
bl = br = r
arc = lambda rad, x2, y2: f"A {rad} {rad} 0 0 1 {x2} {y2} " if rad > 0 else ""
return (
f"M {x+tl} {y} "
f"L {x+w-tr} {y} "
+ arc(tr, x + w, y + tr)
+ f"L {x+w} {y+h-br} "
+ arc(br, x + w - br, y + h)
+ f"L {x+bl} {y+h} "
+ arc(bl, x, y + h - bl)
+ f"L {x} {y+tl} "
+ arc(tl, x + tl, y)
+ "Z"
)
LANG_COLORS = {
"Python": "#3776AB",
"TypeScript": "#3178C6",
"JavaScript": "#F7DF1E",
"Go": "#00ADD8",
"Rust": "#DEA584",
"C": "#A8B9CC",
"C++": "#00599C",
"C#": "#512BD4",
"Java": "#ED8B00",
"Shell": "#89E051",
"HTML": "#E34F26",
"CSS": "#264DE4",
"Dockerfile": "#2496ED",
"Jupyter Notebook": "#DA5B0B",
"Svelte": "#FF3E00",
}
def gh_api(path: str) -> dict | list:
token = os.environ.get("GH_TOKEN") or os.environ.get("GITHUB_TOKEN")
headers = {
"Accept": "application/vnd.github+json",
"User-Agent": f"{USER}-readme",
"X-GitHub-Api-Version": "2022-11-28",
}
if token:
headers["Authorization"] = f"Bearer {token}"
req = urllib.request.Request(f"https://api.github.com/{path}", headers=headers)
with urllib.request.urlopen(req, timeout=20) as resp:
return json.loads(resp.read().decode("utf-8"))
def gh_graphql(query: str, variables: dict) -> dict:
token = os.environ.get("GH_TOKEN") or os.environ.get("GITHUB_TOKEN")
if not token:
raise RuntimeError("GraphQL requires a token")
body = json.dumps({"query": query, "variables": variables}).encode("utf-8")
req = urllib.request.Request(
"https://api.github.com/graphql",
data=body,
headers={
"Accept": "application/vnd.github+json",
"Content-Type": "application/json",
"User-Agent": f"{USER}-readme",
"Authorization": f"Bearer {token}",
},
)
with urllib.request.urlopen(req, timeout=20) as resp:
payload = json.loads(resp.read().decode("utf-8"))
if payload.get("errors"):
raise RuntimeError(f"GraphQL error: {payload['errors']}")
return payload["data"]
CONTRIB_QUERY = """
query($login: String!, $from: DateTime!, $to: DateTime!) {
user(login: $login) {
contributionsCollection(from: $from, to: $to) {
totalCommitContributions
restrictedContributionsCount
}
}
}
"""
def collect_stats() -> dict:
user = gh_api(f"users/{USER}")
repos: list[dict] = []
page = 1
while True:
chunk = gh_api(f"users/{USER}/repos?per_page=100&page={page}&type=owner&sort=pushed")
if not isinstance(chunk, list) or not chunk:
break
repos.extend(chunk)
if len(chunk) < 100:
break
page += 1
own_repos = [r for r in repos if not r.get("fork") and not r.get("private")]
stars = sum(r.get("stargazers_count", 0) for r in own_repos)
lang_bytes: dict[str, int] = {}
for r in own_repos:
if r.get("archived"):
continue
try:
data = gh_api(f"repos/{USER}/{r['name']}/languages")
except Exception:
continue
if isinstance(data, dict):
for k, v in data.items():
lang_bytes[k] = lang_bytes.get(k, 0) + int(v)
excluded_langs = {"HTML", "CSS"}
filtered_langs = {k: v for k, v in lang_bytes.items() if k not in excluded_langs}
total_lang = sum(filtered_langs.values()) or 1
top_langs = sorted(filtered_langs.items(), key=lambda kv: -kv[1])[:8]
top_langs = [(name, round(100 * b / total_lang)) for name, b in top_langs]
top_langs = [(n, p) for n, p in top_langs if p > 0][:6]
today = dt.datetime.now(dt.timezone.utc).replace(tzinfo=None)
active = sum(
1 for r in own_repos
if r.get("pushed_at")
and (today - dt.datetime.strptime(r["pushed_at"], "%Y-%m-%dT%H:%M:%SZ")).days <= 90
)
since = today - dt.timedelta(days=30)
commits_30d = 0
try:
data = gh_graphql(CONTRIB_QUERY, {
"login": USER,
"from": since.strftime("%Y-%m-%dT%H:%M:%SZ"),
"to": today.strftime("%Y-%m-%dT%H:%M:%SZ"),
})
cc = data["user"]["contributionsCollection"]
commits_30d = int(cc["totalCommitContributions"]) + int(cc["restrictedContributionsCount"])
except Exception as e:
print(f"warn: contributions query failed ({e}); falling back to commit search", file=sys.stderr)
since_iso = since.strftime("%Y-%m-%d")
try:
result = gh_api(f"search/commits?q=author:{USER}+author-date:>={since_iso}&per_page=1")
if isinstance(result, dict) and "total_count" in result:
commits_30d = int(result["total_count"])
except Exception as e2:
print(f"warn: commit search failed too ({e2}); commits/30d will read 0", file=sys.stderr)
excluded = {USER.lower(), "gh-profile"}
pushed_titles = [
r["name"] for r in own_repos
if not r.get("archived") and r["name"].lower() not in excluded
][:3]
return {
"repos_total": user.get("public_repos", len(own_repos)),
"repos_active": active,
"stars": stars,
"followers": user.get("followers", 0),
"top_langs": top_langs,
"commits_30d": commits_30d,
"now_repos": pushed_titles,
}
# def days_to_msc() -> int: # old
# today = dt.date.today()
# return max(0, (MSC_START - today).days)
def render_svg(theme: str, stats: dict, corners: str = "all") -> str:
p = PALETTES[theme]
W, H = 880, 540
days = "Ongoing...!"
today_iso = dt.date.today().isoformat()
name = "Dimitris Sofikitis"
name_hex = " ".join(f"{b:02X}" for b in name.encode("ascii"))
now_repos = stats["now_repos"] or ["aegis-rag-lab", "sentinel-stream", "zerotrust-gatekeeper"]
now_repos = (now_repos + ["—"] * 3)[:3]
top_langs = stats["top_langs"] or [("Python", 40), ("TypeScript", 22), ("Go", 14), ("Rust", 10), ("C++", 8), ("Shell", 6)]
font_stack = "'JetBrains Mono', ui-monospace, 'Cascadia Code', 'SF Mono', 'Fira Code', Menlo, Consolas, monospace"
css = f"""
.bg {{ fill: {p['bg']}; }}
.text {{ fill: {p['text']}; }}
.dim {{ fill: {p['dim']}; }}
.accent {{ fill: {p['accent']}; }}
.cyan {{ fill: {p['cyan']}; }}
.amber {{ fill: {p['amber']}; }}
.blue {{ fill: {p['blue']}; }}
.panel {{ fill: {p['panel_inner']}; stroke: {p['panel_border']}; stroke-width: 1; }}
.rule {{ stroke: {p['rule']}; stroke-width: 1; }}
.h1 {{ font-size: 28px; font-weight: 700; letter-spacing: 0.15em; }}
.role {{ font-size: 11px; letter-spacing: 0.18em; }}
.mono {{ font-size: 12px; }}
.small {{ font-size: 10px; letter-spacing: 0.06em; }}
.label {{ font-size: 9px; letter-spacing: 0.18em; font-weight: 700;
stroke: {p['bg']}; stroke-width: 6px; stroke-linejoin: round;
paint-order: stroke fill; }}
.stat {{ font-size: 22px; font-weight: 700; }}
.stat-l {{ font-size: 9px; letter-spacing: 0.12em; }}
.blink {{ animation: blink 1.05s step-end infinite; }}
@keyframes blink {{ 0%, 100% {{ opacity: 1; }} 50% {{ opacity: 0; }} }}
.fade-1 {{ opacity: 0; animation: fadein .55s ease-out .00s forwards; }}
.fade-2 {{ opacity: 0; animation: fadein .55s ease-out .15s forwards; }}
.fade-3 {{ opacity: 0; animation: fadein .55s ease-out .30s forwards; }}
.fade-4 {{ opacity: 0; animation: fadein .55s ease-out .45s forwards; }}
.fade-5 {{ opacity: 0; animation: fadein .55s ease-out .60s forwards; }}
.fade-6 {{ opacity: 0; animation: fadein .55s ease-out .75s forwards; }}
.fade-7 {{ opacity: 0; animation: fadein .55s ease-out .90s forwards; }}
.fade-8 {{ opacity: 0; animation: fadein .55s ease-out 1.05s forwards; }}
@keyframes fadein {{ from {{ opacity: 0; }} to {{ opacity: 1; }} }}
.reveal {{ clip-path: inset(0 100% 0 0); animation: reveal 1.4s cubic-bezier(.23,1,.32,1) .9s forwards; }}
@keyframes reveal {{ to {{ clip-path: inset(0 0 0 0); }} }}
"""
parts: list[str] = []
parts.append(
f'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 {W} {H}" width="{W}" height="{H}" '
f'font-family="{font_stack}" role="img" aria-label="Dimitris Sofikitis profile card">'
)
parts.append(f"<defs><style>{css}</style></defs>")
parts.append(f'<path class="bg" d="{rounded_path(0, 0, W, H, PANEL_RX, corners)}" />')
parts.append(
f'<g class="fade-1">'
f'<text x="32" y="58" class="h1 text">DIMITRIS SOFIKITIS</text>'
f'<text x="34" y="80" class="role dim">AI/ML SWE · Full-Stack Agentic AI Engineer · Based in Norway</text>'
f"</g>"
)
parts.append(
f'<g class="fade-2">'
f'<text x="32" y="112" class="mono">'
f'<tspan class="dim">> </tspan>'
f'<tspan class="text">Engineering Trust in a world of Chaos</tspan>'
f'<tspan class="accent blink">█</tspan>'
f"</text></g>"
)
parts.append(
f'<g class="fade-3">'
f'<text x="32" y="146" class="mono dim">0x0000</text>'
f'<text x="92" y="146" class="mono text" letter-spacing="1">{name_hex}</text>'
f'<text x="{W-32}" y="146" text-anchor="end" class="mono dim">{name}</text>'
f"</g>"
)
parts.append(f'<line x1="32" y1="160" x2="{W-32}" y2="160" class="rule" />')
boot_lines = [
("init engineering trust", "[ OK ]"),
("securing agentic systems", "[ OK ]"),
("breaking what shouldn't be trusted", "[ OK ]"),
]
y = 184
for i, (msg, status) in enumerate(boot_lines):
parts.append(
f'<g class="fade-{4+i}">'
f'<text x="32" y="{y}" class="mono">'
f'<tspan class="dim">[BOOT] </tspan>'
f'<tspan class="text">{msg}</tspan>'
f"</text>"
f'<text x="{W-32}" y="{y}" text-anchor="end" class="mono accent">{status}</text>'
f"</g>"
)
y += 22
panel_y = 268
panel_h = 110
gap = 16
panel_w = (W - 64 - 2 * gap) // 3
panels = [
("REPOS", [now_repos[0], now_repos[1], now_repos[2]], None, "cyan"),
("STATS", [
("commits/30d", str(stats["commits_30d"])),
("repos·active", str(stats["repos_active"])),
("stars", str(stats["stars"])),
], "kv", "amber"),
# ("NEXT", [MSC_LABEL.split(" · ")[0], MSC_LABEL.split(" · ")[1], f"In... T-{days} days"], None, "accent"), # old
("NOW", [MSC_LABEL.split(" · ")[0], MSC_LABEL.split(" · ")[1], f"{days}"], None, "accent"),
]
for idx, (label, content, kind, color) in enumerate(panels):
x = 32 + idx * (panel_w + gap)
parts.append(
f'<g class="fade-{6+min(idx,2)}">'
f'<rect x="{x}" y="{panel_y}" width="{panel_w}" height="{panel_h}" rx="10" class="panel" />'
)
label_text = f"[ {label} ]"
parts.append(
f'<text x="{x+18}" y="{panel_y+3}" class="label {color}">{label_text}</text>'
)
if kind == "kv":
for i, (k, v) in enumerate(content):
row_y = panel_y + 32 + i * 24
parts.append(
f'<text x="{x+16}" y="{row_y}" class="small dim">{k}</text>'
f'<text x="{x+panel_w-16}" y="{row_y}" text-anchor="end" class="stat text">{v}</text>'
)
else:
for i, line in enumerate(content):
row_y = panel_y + 34 + i * 22
glyph = "·"
parts.append(
f'<text x="{x+16}" y="{row_y}" class="mono dim">{glyph}</text>'
f'<text x="{x+30}" y="{row_y}" class="mono text">{line}</text>'
)
parts.append("</g>")
lang_y = 408
parts.append(
f'<g class="fade-7">'
f'<text x="32" y="{lang_y}" class="mono">'
f'<tspan class="dim">> </tspan>'
f'<tspan class="text">languages --top 6</tspan>'
f"</text></g>"
)
bar_x = 32
bar_w = W - 64
bar_h = 8
bar_top = lang_y + 16
total_pct = sum(pct for _, pct in top_langs) or 1
parts.append(f'<g class="fade-8 reveal">')
parts.append(
f'<rect x="{bar_x}" y="{bar_top}" width="{bar_w}" height="{bar_h}" rx="2" fill="{p["bar_track"]}" />'
)
cumulative = 0
for name_l, pct in top_langs:
seg_w = int(bar_w * pct / total_pct)
color = LANG_COLORS.get(name_l, p["accent"])
parts.append(
f'<rect x="{bar_x + cumulative}" y="{bar_top}" width="{seg_w}" height="{bar_h}" fill="{color}" />'
)
cumulative += seg_w
parts.append("</g>")
legend_y = bar_top + 30
cols = 3
row_h = 20
cell_w = bar_w // cols
for i, (name_l, pct) in enumerate(top_langs):
color = LANG_COLORS.get(name_l, p["accent"])
col = i % cols
row = i // cols
cx = bar_x + col * cell_w
cy = legend_y + row * row_h
parts.append(
f'<g class="fade-8">'
f'<circle cx="{cx + 4}" cy="{cy - 3}" r="3" fill="{color}" />'
f'<text x="{cx + 14}" y="{cy}" class="small text">{name_l}</text>'
f'<text x="{cx + cell_w - 4}" y="{cy}" text-anchor="end" class="small dim">{pct}%</text>'
f'</g>'
)
parts.append(
f'<g class="fade-8">'
f'<text x="32" y="{H-20}" class="small dim">> last_sync: {today_iso}</text>'
f'<text x="{W-32}" y="{H-20}" text-anchor="end" class="small dim">'
f'dimitrisofikitis.com'
f"</text>"
f"</g>"
)
parts.append("</svg>")
return "\n".join(parts) + "\n"
CONTACTS = [
("site", "dimitrisofikitis.com"),
("linkedin", "/in/dimitrisofikitis"),
("email", "d.sofikitis@icloud.com"),
("resume", "dimitrisofikitis.com/resume"),
("apps", "apps.dimitrisofikitis.com"),
]
WHOAMI = [
("mantra", "cyan", [
"I build things that need to be trusted",
"and break things that shouldn't be.",
]),
("by_day", "amber", [
"Engineering trust into (Gen)AI systems!",
"Defending from prompt-injections, hallucinations, and more.",
"Building evaluation frameworks for Agentic AI.",
]),
("by_night", "accent", [
"Reverse-engineering something I shouldn't be,",
"reading threat reports, or over-engineering a personal project.",
]),
("based_in", "blue", [
"Norway mostly. Fueled by curiosity, passion,",
"and a mild obsession with making machines behave.",
]),
]
def render_whoami_svg(theme: str, corners: str = "all") -> str:
p = PALETTES[theme]
W, H = 880, 480
font_stack = "'JetBrains Mono', ui-monospace, 'Cascadia Code', 'SF Mono', 'Fira Code', Menlo, Consolas, monospace"
css = f"""
.bg {{ fill: {p['bg']}; }}
.text {{ fill: {p['text']}; }}
.dim {{ fill: {p['dim']}; }}
.accent {{ fill: {p['accent']}; }}
.cyan {{ fill: {p['cyan']}; }}
.amber {{ fill: {p['amber']}; }}
.blue {{ fill: {p['blue']}; }}
.panel {{ fill: {p['panel_inner']}; stroke: {p['panel_border']}; stroke-width: 1; }}
.rule {{ stroke: {p['rule']}; stroke-width: 1; }}
.label {{ font-size: 9px; letter-spacing: 0.18em; font-weight: 700;
stroke: {p['bg']}; stroke-width: 6px; stroke-linejoin: round;
paint-order: stroke fill; }}
.mono {{ font-size: 13px; }}
.body {{ font-size: 13px; }}
.key {{ font-size: 13px; letter-spacing: 0.10em; font-weight: 700; }}
.small {{ font-size: 10px; letter-spacing: 0.06em; }}
.blink {{ animation: blink 1.05s step-end infinite; }}
@keyframes blink {{ 0%, 100% {{ opacity: 1; }} 50% {{ opacity: 0; }} }}
.fade-1 {{ opacity: 0; animation: fadein .55s ease-out .00s forwards; }}
.fade-2 {{ opacity: 0; animation: fadein .55s ease-out .15s forwards; }}
.fade-3 {{ opacity: 0; animation: fadein .55s ease-out .30s forwards; }}
.fade-4 {{ opacity: 0; animation: fadein .55s ease-out .45s forwards; }}
.fade-5 {{ opacity: 0; animation: fadein .55s ease-out .60s forwards; }}
.fade-6 {{ opacity: 0; animation: fadein .55s ease-out .75s forwards; }}
.fade-7 {{ opacity: 0; animation: fadein .55s ease-out .90s forwards; }}
@keyframes fadein {{ from {{ opacity: 0; }} to {{ opacity: 1; }} }}
"""
parts: list[str] = []
parts.append(
f'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 {W} {H}" width="{W}" height="{H}" '
f'font-family="{font_stack}" role="img" aria-label="Dimitris Sofikitis — whoami">'
)
parts.append(f"<defs><style>{css}</style></defs>")
parts.append(f'<path class="bg" d="{rounded_path(0, 0, W, H, PANEL_RX, corners)}" />')
panel_y = OUTER_PAD_TOP
panel_h = H - OUTER_PAD_TOP - OUTER_PAD_BOTTOM
parts.append(
f'<path d="{rounded_path(12, panel_y, W-24, panel_h, PANEL_RX, "all")}" class="panel" />'
)
parts.append(
f'<text x="30" y="{LABEL_Y}" class="label accent">[ whoami ]</text>'
)
parts.append(
f'<g class="fade-1">'
f'<text x="32" y="64" class="mono">'
f'<tspan class="dim">$ </tspan>'
f'<tspan class="text">whoami --verbose</tspan>'
f'<tspan class="accent blink">█</tspan>'
f'</text>'
f'</g>'
)
parts.append(f'<line x1="32" y1="80" x2="{W-32}" y2="80" class="rule" />')
y = 108
section_gap = 20
line_h = 22
for i, (key, color, lines) in enumerate(WHOAMI):
parts.append(
f'<g class="fade-{2+i}">'
f'<text x="32" y="{y}" class="mono">'
f'<tspan class="dim">> </tspan>'
f'<tspan class="key {color}">{key}</tspan>'
f'</text>'
)
for j, ln in enumerate(lines):
row_y = y + (j + 1) * line_h
safe = ln.replace("&", "&").replace("<", "<").replace(">", ">")
parts.append(
f'<text x="56" y="{row_y}" class="body text">{safe}</text>'
)
parts.append("</g>")
y += line_h * (len(lines) + 1) + section_gap
parts.append("</svg>")
return "\n".join(parts) + "\n"
def render_elsewhere_svg(theme: str, corners: str = "all") -> str:
p = PALETTES[theme]
W, H = 880, 270
today_iso = dt.date.today().isoformat()
font_stack = "'JetBrains Mono', ui-monospace, 'Cascadia Code', 'SF Mono', 'Fira Code', Menlo, Consolas, monospace"
css = f"""
.bg {{ fill: {p['bg']}; }}
.text {{ fill: {p['text']}; }}
.dim {{ fill: {p['dim']}; }}
.accent {{ fill: {p['accent']}; }}
.cyan {{ fill: {p['cyan']}; }}
.amber {{ fill: {p['amber']}; }}
.panel {{ fill: {p['panel_inner']}; stroke: {p['panel_border']}; stroke-width: 1; }}
.rule {{ stroke: {p['rule']}; stroke-width: 1; }}
.label {{ font-size: 9px; letter-spacing: 0.18em; font-weight: 700;
stroke: {p['bg']}; stroke-width: 6px; stroke-linejoin: round;
paint-order: stroke fill; }}
.mono {{ font-size: 13px; }}
.small {{ font-size: 10px; letter-spacing: 0.06em; }}
.key {{ font-size: 13px; letter-spacing: 0.10em; font-weight: 700; }}
.blink {{ animation: blink 1.05s step-end infinite; }}
@keyframes blink {{ 0%, 100% {{ opacity: 1; }} 50% {{ opacity: 0; }} }}
.fade-1 {{ opacity: 0; animation: fadein .55s ease-out .00s forwards; }}
.fade-2 {{ opacity: 0; animation: fadein .55s ease-out .15s forwards; }}
.fade-3 {{ opacity: 0; animation: fadein .55s ease-out .30s forwards; }}
.fade-4 {{ opacity: 0; animation: fadein .55s ease-out .45s forwards; }}
.fade-5 {{ opacity: 0; animation: fadein .55s ease-out .60s forwards; }}
.fade-6 {{ opacity: 0; animation: fadein .55s ease-out .75s forwards; }}
@keyframes fadein {{ from {{ opacity: 0; }} to {{ opacity: 1; }} }}
"""
parts: list[str] = []
parts.append(
f'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 {W} {H}" width="{W}" height="{H}" '
f'font-family="{font_stack}" role="img" aria-label="Dimitris Sofikitis contact endpoints">'
)
parts.append(f"<defs><style>{css}</style></defs>")
parts.append(f'<path class="bg" d="{rounded_path(0, 0, W, H, PANEL_RX, corners)}" />')
panel_y = OUTER_PAD_TOP
panel_h = H - OUTER_PAD_TOP - OUTER_PAD_BOTTOM
parts.append(
f'<path d="{rounded_path(12, panel_y, W-24, panel_h, PANEL_RX, "all")}" class="panel" />'
)
parts.append(
f'<text x="30" y="{LABEL_Y}" class="label cyan">[ elsewhere ]</text>'
)
parts.append(
f'<g class="fade-1">'
f'<text x="32" y="64" class="mono">'
f'<tspan class="dim">$ </tspan>'
f'<tspan class="text">cat ~/contacts++</tspan>'
f'<tspan class="accent blink">█</tspan>'
f'</text>'
f'</g>'
)
parts.append(f'<line x1="32" y1="80" x2="{W-32}" y2="80" class="rule" />')
key_col_x = 122
val_col_x = 272
y0 = 108
row_h = 24
for i, (key, val) in enumerate(CONTACTS):
y = y0 + i * row_h
parts.append(
f'<g class="fade-{2+i}">'
f'<text x="32" y="{y}" class="mono dim">0x0{i}</text>'
f'<text x="{key_col_x}" y="{y}" class="key amber">{key}</text>'
f'<text x="{key_col_x + 80}" y="{y}" class="mono dim">▸</text>'
f'<text x="{val_col_x}" y="{y}" class="mono text">{val}</text>'
f'</g>'
)
eof_y = y0 + len(CONTACTS) * row_h + 18
parts.append(
f'<g class="fade-6">'
f'<text x="32" y="{eof_y}" class="small dim">EOF · last_sync: {today_iso}</text>'
f'</g>'
)
parts.append("</svg>")
return "\n".join(parts) + "\n"
STACK_ROWS: list[tuple[str, str, list[str]]] = [
("langs", "amber", ["python", "ts", "js", "go", "rust", "c", "cpp", "cs", "java", "bash"]),
("web · api", "cyan", ["fastapi", "flask", "nodejs", "react", "nextjs", "svelte", "tailwind", "html", "css", "postman"]),
("data · cloud", "blue", ["postgres", "mysql", "redis", "mongodb", "aws", "azure", "gcp", "docker", "kubernetes", "terraform"]),
]
def _fetch_skillicons_row(icons: list[str]) -> tuple[str, float, float] | None:
url = f"https://skillicons.dev/icons?i={','.join(icons)}&perline={len(icons)}"
try:
req = urllib.request.Request(url, headers={"User-Agent": f"{USER}-readme"})
with urllib.request.urlopen(req, timeout=20) as r:
raw = r.read().decode("utf-8")
except Exception as e:
print(f"warn: skillicons fetch failed for {icons!r} ({e})", file=sys.stderr)
return None
m = re.search(r"<svg([^>]*)>(.*)</svg>", raw, re.DOTALL)
if not m:
return None
attrs, inner = m.group(1), m.group(2)
vb = re.search(r'viewBox\s*=\s*"([^"]+)"', attrs)
if vb:
nums = vb.group(1).split()
return inner, float(nums[2]), float(nums[3])
wm = re.search(r'width\s*=\s*"([^"]+)"', attrs)
hm = re.search(r'height\s*=\s*"([^"]+)"', attrs)
return inner, float(wm.group(1)) if wm else 588.0, float(hm.group(1)) if hm else 48.0
def render_stack_svg(theme: str, corners: str = "all") -> str | None:
p = PALETTES[theme]
today_iso = dt.date.today().isoformat()
font_stack = "'JetBrains Mono', ui-monospace, 'Cascadia Code', 'SF Mono', 'Fira Code', Menlo, Consolas, monospace"
rows: list[tuple[str, str, str, float, float]] = []
for label, color, icons in STACK_ROWS:
fetched = _fetch_skillicons_row(icons)
if fetched is None:
return None
inner, w, h = fetched
rows.append((label, color, inner, w, h))
W = 880
usable_w = W - 64
src_w = rows[0][3]
src_h = rows[0][4]
scale = usable_w / src_w
icon_block_h = src_h * scale
header_h = 22
after_header = 8
after_icons = 28
content_start = OUTER_PAD_TOP + 32 + 16 + 22
rows_h = sum(header_h + after_header + icon_block_h + after_icons for _ in rows)
rows_h -= after_icons
bottom_pad = 36
H = int(content_start + rows_h + bottom_pad + OUTER_PAD_BOTTOM)
css = f"""
.bg {{ fill: {p['bg']}; }}
.text {{ fill: {p['text']}; }}
.dim {{ fill: {p['dim']}; }}
.accent {{ fill: {p['accent']}; }}
.cyan {{ fill: {p['cyan']}; }}
.amber {{ fill: {p['amber']}; }}
.blue {{ fill: {p['blue']}; }}
.panel {{ fill: {p['panel_inner']}; stroke: {p['panel_border']}; stroke-width: 1; }}
.rule {{ stroke: {p['rule']}; stroke-width: 1; }}
.label {{ font-size: 9px; letter-spacing: 0.18em; font-weight: 700;
stroke: {p['bg']}; stroke-width: 6px; stroke-linejoin: round;
paint-order: stroke fill; }}
.mono {{ font-size: 13px; }}
.small {{ font-size: 10px; letter-spacing: 0.06em; }}
.key {{ font-size: 13px; letter-spacing: 0.10em; font-weight: 700; }}
.blink {{ animation: blink 1.05s step-end infinite; }}
@keyframes blink {{ 0%, 100% {{ opacity: 1; }} 50% {{ opacity: 0; }} }}
.fade-1 {{ opacity: 0; animation: fadein .55s ease-out .00s forwards; }}
.fade-2 {{ opacity: 0; animation: fadein .55s ease-out .20s forwards; }}
.fade-3 {{ opacity: 0; animation: fadein .55s ease-out .40s forwards; }}
.fade-4 {{ opacity: 0; animation: fadein .55s ease-out .60s forwards; }}
@keyframes fadein {{ from {{ opacity: 0; }} to {{ opacity: 1; }} }}
"""
parts: list[str] = []
parts.append(
f'<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" '
f'viewBox="0 0 {W} {H}" width="{W}" height="{H}" '
f'font-family="{font_stack}" role="img" aria-label="Tech stack">'
)
parts.append(f"<defs><style>{css}</style></defs>")
parts.append(f'<path class="bg" d="{rounded_path(0, 0, W, H, PANEL_RX, corners)}" />')
panel_y = OUTER_PAD_TOP
panel_h = H - OUTER_PAD_TOP - OUTER_PAD_BOTTOM
parts.append(
f'<path d="{rounded_path(12, panel_y, W-24, panel_h, PANEL_RX, "all")}" class="panel" />'
)
parts.append(f'<text x="30" y="{LABEL_Y}" class="label amber">[ stack ]</text>')
parts.append(
f'<g class="fade-1">'
f'<text x="32" y="64" class="mono">'
f'<tspan class="dim">$ </tspan>'
f'<tspan class="text">ls /usr/local/bin</tspan>'
f'<tspan class="accent blink">█</tspan>'
f'</text>'
f'</g>'
)
parts.append(f'<line x1="32" y1="80" x2="{W-32}" y2="80" class="rule" />')
y = content_start
for i, (label, color, inner, w, h) in enumerate(rows):
parts.append(
f'<g class="fade-{2+i}">'
f'<text x="32" y="{y}" class="mono">'
f'<tspan class="dim">> </tspan>'
f'<tspan class="key {color}">{label}</tspan>'
f'</text>'
)
icon_y = y + after_header
parts.append(
f'<g transform="translate(32 {icon_y}) scale({scale:.4f})">{inner}</g>'
)
parts.append("</g>")
y += header_h + after_header + icon_block_h + after_icons
parts.append(
f'<g class="fade-4">'
f'<text x="32" y="{H-22}" class="small dim">EOF · last_sync: {today_iso}</text>'
f'</g>'
)
parts.append("</svg>")
return "\n".join(parts) + "\n"
def fetch_activity_svg(theme: str, corners: str = "all") -> str | None:
p = PALETTES[theme]
bg = p["bg"].lstrip("#")
text = p["text"].lstrip("#")
line = p["accent"].lstrip("#")
point = p["amber"].lstrip("#")
url = (
"https://github-readme-activity-graph.vercel.app/graph"
f"?username={USER}"
f"&bg_color={bg}"
f"&color={text}"
f"&line={line}"
f"&point={point}"
"&area=true"
"&hide_border=true"
"&custom_title=contribution+signal"
)
try:
req = urllib.request.Request(url, headers={"User-Agent": f"{USER}-readme"})
with urllib.request.urlopen(req, timeout=30) as r:
raw = r.read().decode("utf-8")
except Exception as e:
print(f"warn: activity graph fetch failed for {theme} ({e})", file=sys.stderr)
return None
m = re.search(r"<svg([^>]*)>(.*)</svg>", raw, re.DOTALL)
if not m:
print(f"warn: activity graph SVG didn't parse for {theme}", file=sys.stderr)
return None
attrs, inner = m.group(1), m.group(2)
vb = re.search(r'viewBox\s*=\s*"([^"]+)"', attrs)
if vb:
nums = vb.group(1).split()
w, h = float(nums[2]), float(nums[3])
else:
wm = re.search(r'width\s*=\s*"([^"]+)"', attrs)
hm = re.search(r'height\s*=\s*"([^"]+)"', attrs)
w = float(wm.group(1)) if wm else 800.0
h = float(hm.group(1)) if hm else 240.0
rx = PANEL_RX * (w / 880)
clip_d = rounded_path(0, 0, w, h, rx, corners)
return (
f'<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" '
f'viewBox="0 0 {w:g} {h:g}" width="{w:g}" height="{h:g}">'
f'<defs><clipPath id="rounded-frame">'
f'<path d="{clip_d}" />'
f'</clipPath></defs>'
f'<g clip-path="url(#rounded-frame)">{inner}</g>'
f'</svg>\n'
)
def combine_svgs(srcs: list[Path], dst: Path) -> bool:
sections: list[tuple[str, float, float]] = []
cumulative_y = 0.0
max_w = 0.0
missing = [s for s in srcs if not s.exists()]
if missing:
print(f"warn: combine skipped, missing {missing}", file=sys.stderr)
return False
for i, src in enumerate(srcs):
content = src.read_text(encoding="utf-8")
m_vb = re.search(r'<svg[^>]*viewBox\s*=\s*"([^"]+)"', content)
if not m_vb:
print(f"warn: no viewBox on {src}; skipping combine", file=sys.stderr)
return False
nums = m_vb.group(1).split()
w, h = float(nums[2]), float(nums[3])
max_w = max(max_w, w)
m_inner = re.search(r"<svg[^>]*>(.*)</svg>", content, re.DOTALL)
if not m_inner:
return False
inner = m_inner.group(1)
suffix = f"-s{i}"
inner = re.sub(r'\bid="([^"]+)"', lambda m: f'id="{m.group(1)}{suffix}"', inner)
inner = re.sub(r"url\(#([^)]+)\)", lambda m: f"url(#{m.group(1)}{suffix})", inner)
inner = re.sub(
r'\b(xlink:)?href="#([^"]+)"',
lambda m: f'{m.group(1) or ""}href="#{m.group(2)}{suffix}"',
inner,
)
sections.append((inner, h, cumulative_y))
cumulative_y += h
H = cumulative_y
font_stack = "'JetBrains Mono', ui-monospace, 'Cascadia Code', 'SF Mono', 'Fira Code', Menlo, Consolas, monospace"
parts = [
f'<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" '
f'viewBox="0 0 {max_w:g} {H:g}" width="{max_w:g}" height="{H:g}" '
f'font-family="{font_stack}">'
]
for inner, _h, y in sections:
parts.append(f'<g transform="translate(0 {y:g})">{inner}</g>')
parts.append("</svg>")
dst.write_text("\n".join(parts) + "\n", encoding="utf-8")
return True
def main() -> int:
try:
stats = collect_stats()
except (urllib.error.URLError, urllib.error.HTTPError) as e:
print(f"warn: GitHub API failed ({e}); falling back to defaults", file=sys.stderr)
stats = {
"repos_total": 0, "repos_active": 0, "stars": 0, "followers": 0,
"top_langs": [], "commits_30d": 0,
"now_repos": ["aegis-rag-lab", "sentinel-stream", "zerotrust-gatekeeper"],
}
ASSETS.mkdir(exist_ok=True)
POSITIONS = {
"card": "all",
"whoami": "top",
"stack": "middle",
"elsewhere": "bottom",
"activity": "all",
}
for theme in ("dark", "light"):
card = ASSETS / f"card-{theme}.svg"
card.write_text(render_svg(theme, stats, corners=POSITIONS["card"]), encoding="utf-8")
print(f"wrote {card} ({card.stat().st_size:,} bytes)")
whoami = ASSETS / f"whoami-{theme}.svg"
whoami.write_text(render_whoami_svg(theme, corners=POSITIONS["whoami"]), encoding="utf-8")
print(f"wrote {whoami} ({whoami.stat().st_size:,} bytes)")
stack_path = ASSETS / f"stack-{theme}.svg"
stack = render_stack_svg(theme, corners=POSITIONS["stack"])
if stack is not None:
stack_path.write_text(stack, encoding="utf-8")
print(f"wrote {stack_path} ({stack_path.stat().st_size:,} bytes)")
elif stack_path.exists():
print(f"kept existing {stack_path}")
else:
print(f"skipped {stack_path} (fetch failed, no prior file)")
activity_path = ASSETS / f"activity-{theme}.svg"
activity = fetch_activity_svg(theme, corners=POSITIONS["activity"])
if activity is not None:
activity_path.write_text(activity, encoding="utf-8")
print(f"wrote {activity_path} ({activity_path.stat().st_size:,} bytes)")
elif activity_path.exists():
print(f"kept existing {activity_path}")
else:
print(f"skipped {activity_path} (fetch failed, no prior file)")
elsewhere = ASSETS / f"elsewhere-{theme}.svg"
elsewhere.write_text(render_elsewhere_svg(theme, corners=POSITIONS["elsewhere"]), encoding="utf-8")
print(f"wrote {elsewhere} ({elsewhere.stat().st_size:,} bytes)")
chain_path = ASSETS / f"chain-{theme}.svg"
chain_srcs = [
ASSETS / f"whoami-{theme}.svg",
ASSETS / f"stack-{theme}.svg",
ASSETS / f"elsewhere-{theme}.svg",
]
if combine_svgs(chain_srcs, chain_path):
print(f"wrote {chain_path} ({chain_path.stat().st_size:,} bytes)")
return 0
if __name__ == "__main__":
raise SystemExit(main())