Skip to content

Commit c9f10ce

Browse files
committed
Generate full metadata export
1 parent 5c1874f commit c9f10ce

File tree

3 files changed

+83
-1
lines changed

3 files changed

+83
-1
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,5 @@ _site/
1111
*.tgz
1212
tmp*
1313
work-in-progress/
14-
www/_data/nextprev.yaml
14+
www/_data/nextprev.yaml
15+
www/util/fulldata.json

bin/build.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ echo "INFO: build starting at $(date -u +%Y-%m-%dT%H:%M:%SZ)"
1414

1515
echo "DEBUG: uname=$(uname -a)"
1616

17+
export PYTHON_UNBUFFERED=1
18+
1719

1820
echo "INFO: generating ar21's with a white background"
1921
python3 bin/gen_bgwhite.py
@@ -24,6 +26,9 @@ python3 -m pip install python-frontmatter
2426
echo "INFO: updating frontmatter"
2527
python3 bin/frontmatter_update.py --directory=www/logos
2628

29+
echo "INFO: generated full metadata export"
30+
python3 bin/gen_fulldata.py
31+
2732
echo "INFO: updating tags"
2833
python3 bin/fm2tag.py --directory=www/logos --tagfile=www/_data/tags.yaml
2934

bin/gen_fulldata.py

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
#!/usr/bin/env -S uv run --script
2+
# /// script
3+
# dependencies = ["argparse", "python-frontmatter"]
4+
# ///
5+
#
6+
# copy from archive into proper directories
7+
#
8+
9+
import argparse
10+
import datetime
11+
import json
12+
import frontmatter
13+
import os
14+
import pathlib
15+
import re
16+
import sys
17+
import time
18+
19+
default_path = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "www"))
20+
21+
parser = argparse.ArgumentParser()
22+
parser.add_argument("-q", "--quiet", help="hide status messages", default=True, dest='verbose', action="store_false")
23+
parser.add_argument("-d", "--directory", help="directory to search", default=default_path, dest='directory')
24+
parser.add_argument("-f", "--filenames", help="only print failing filenames", default=False, dest='filenames', action="store_true")
25+
parser.add_argument("-v", "--verbose", help="verbose output", default=False, dest='debug', action="store_true")
26+
27+
args = parser.parse_args()
28+
29+
if args.verbose:
30+
sys.stdout.write("INFO: full data generation starting at %s\n" % datetime.datetime.fromtimestamp(time.time()).strftime('%Y-%m-%d %H:%M:%S'))
31+
32+
found_files = list(pathlib.Path(os.path.join(args.directory, "logos")).glob('**/index.md'))
33+
found_files.sort() # only so debug output is consistent
34+
35+
idxCount = 0
36+
errCount = 0
37+
38+
fulldata = []
39+
40+
for indexfn in found_files:
41+
idxCount += 1
42+
if args.debug:
43+
sys.stdout.write("DEBUG: checking %s\n" % (indexfn))
44+
45+
indexmd = frontmatter.load(indexfn)
46+
47+
if 'logohandle' not in indexmd:
48+
sys.stdout.write("ERROR: %s: missing logohandle\n" % indexfn)
49+
errCount += 1
50+
continue
51+
52+
if 'noindex' in indexmd:
53+
if args.verbose:
54+
sys.stdout.write("INFO: %s: noindex found, skipping\n" % indexfn)
55+
continue
56+
57+
fulldata.append(indexmd.metadata)
58+
59+
retVal = {
60+
"success": True,
61+
"lastmod": datetime.datetime.fromtimestamp(time.time()).strftime('%Y-%m-%d %H:%M:%S'),
62+
"count": len(fulldata),
63+
"sites": fulldata
64+
}
65+
66+
fulldatafn = os.path.join(args.directory, "util", "fulldata.json")
67+
f = open(fulldatafn, 'w')
68+
f.write(json.dumps(retVal, indent=2))
69+
f.close()
70+
71+
if args.verbose:
72+
sys.stdout.write("INFO: files checked: %5d\n" % idxCount)
73+
sys.stdout.write("INFO: errors : %5d\n" % errCount)
74+
sys.stdout.write("INFO: full data generation complete at %s\n" % datetime.datetime.fromtimestamp(time.time()).strftime('%Y-%m-%d %H:%M:%S'))
75+
76+
sys.exit(errCount)

0 commit comments

Comments
 (0)