#!/usr/bin/env python3 import json, os from datetime import datetime, timezone from pathlib import Path from common import request,store,state_file ROOT=Path(__file__).resolve().parents[1] URL='https://errata.almalinux.org/{major}/errata.full.json' def check(payload): # Source can be a JSON object or an array; reject HTML/errors. value=json.loads(payload) if not isinstance(value,(dict,list)) or not value: raise ValueError('Unexpected empty AlmaLinux errata response') return value def main(): for major in (8,9,10): dest=ROOT/f'data/almalinux/{major}/errata.full.json' state=ROOT/f'state/{major}.json' meta=json.loads(state.read_text()) if state.exists() else {} headers={} if dest.exists(): if meta.get('etag'): headers['If-None-Match']=meta['etag'] if meta.get('last_modified'): headers['If-Modified-Since']=meta['last_modified'] status,raw,h=request(URL.format(major=major),headers) if status==304: print(f'AlmaLinux {major}: unchanged (HTTP 304)'); continue check(raw) changed=store(dest,raw) state_file(state,{ 'source':URL.format(major=major), 'etag':h.get('ETag',meta.get('etag','')), 'last_modified':h.get('Last-Modified',meta.get('last_modified','')), 'last_success_utc':datetime.now(timezone.utc).isoformat(), 'sha256':__import__('hashlib').sha256(raw).hexdigest(), }) print(f'AlmaLinux {major}: {len(raw)} bytes, changed={changed}') if __name__=='__main__': main()