Created
July 3, 2024 23:01
-
-
Save ober/5d914b84bb2d94612038c03d42f9051d to your computer and use it in GitHub Desktop.
Not working.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/gosh | |
;; Ensure to make this script executable or run it with Gauche by `gosh script.scm` | |
(use gauche.uvector) ; For bytevector operations | |
(use gauche.io) ; General I/O operations | |
(use srfi-19) ; Time and date library, only if needed | |
(use text.json) ; JSON parsing | |
(use file.util) ; File utilities for directory walking | |
(use rfc.zlib) ; For gzip compression/decompression | |
(define (read-json-gzip file-path) | |
(call-with-input-file file-path | |
(lambda (in) | |
(let* ((gzip-port (zlib-inflate-port in)) | |
(json-string (port->string gzip-port))) | |
(json-string->object json-string))) | |
:binary #t)) | |
;; Function to check if a file has a .json.gz extension | |
(define (json-gz-file? file-name) | |
(string-match ".*\\.json\\.gz$" file-name)) | |
;; Function to walk a directory tree and return list of files matching json.gz | |
(define (walk-directory dir) | |
(let loop ((entries (directory-files dir)) | |
(results '())) | |
(for-each | |
(lambda (entry) | |
(let ((full-path (string-append dir "/" entry))) | |
(cond | |
((and (file-exists? full-path) | |
(not (member entry '("." "..")))) | |
(if (file-directory? full-path) | |
(set! results (append results (walk-directory full-path))) | |
(if (json-gz-file? entry) | |
(set! results (cons full-path results)))))))) | |
entries) | |
results)) | |
;; Example usage | |
(define (ct dir) | |
(let ((files (walk-directory dir))) | |
(for-each | |
(lambda (file) | |
(let ((json (read-json-gzip file))) | |
(for-each | |
(lambda (record) | |
(let ((request-id (gethash "requestID" record)) | |
(event-name (gethash "eventName" record)) | |
(user-identity (gethash "userIdentity" record))) | |
(print (format "~a: ~a ~a\n" request-id event-name user-identity)))) | |
(cdr (assoc "Records" json))))) | |
files))) | |
(ct "/home/user/bench2") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment