Skip to content

Instantly share code, notes, and snippets.

View benoit74's full-sized avatar

benoit74

  • Switzerland
View GitHub Profile
@benoit74
benoit74 / list_gutenberg_languages.sh
Created October 27, 2026 13:49
List Gutenberg languages from ZF config
#!/usr/bin/env bash
BASE="https://api.farm.openzim.org/v2"
LIMIT=100
for EP in recipes schedules; do
SKIP=0; out=""
while :; do
page=$(curl -s "$BASE/$EP?name=gutenberg&limit=$LIMIT&skip=$SKIP")
if ! jq -e '.items' >/dev/null 2>&1 <<<"$page"; then
echo "[$EP] unexpected response:" >&2
#!/usr/bin/env python3
"""List media entries in a single local ZIM file.
Prints a summary of media counts grouped by mimetype on the console,
and writes the full list of media entries (path, mimetype, size) to
a CSV file.
Usage:
./zim_media_list_local.py <path-to-zim> [--output FILE]
"""
@benoit74
benoit74 / ory_import.py
Created December 23, 2025 09:20
Import new identities with password to Ory
#!/usr/bin/env python3
"""
Script to import users into Ory from a CSV file with password hash transformation.
"""
import csv
import sys
import requests
from typing import Tuple
from pathlib import Path
@benoit74
benoit74 / zimls.py
Created October 28, 2024 08:17
Zimls v2, computing aggregated path segment sizes and sorting display by path aggregated size
# !/usr/bin/env python3
import argparse
import logging
import sys
from typing import NamedTuple
from pydantic import BaseModel
import humanfriendly
@benoit74
benoit74 / gist:353a203270003acc23471b3d8fb1a92c
Created May 16, 2024 13:23
Test Python and lxml HTML parsers
CONTENTS = [
(
"content1",
"<html><head><title>Test</title></head><body><h1>Parse me!</h1></body></html>",
),
(
"content2",
"""<img width="200" src="image.png?param1=value1&aparam2=value2" />""",
),
(
@benoit74
benoit74 / add_pyright_ignore.py
Created February 6, 2024 15:32
Add pyright ignore statements for every diagnosis encountered
import subprocess
import re
import json
def run_pyright():
# Run Pyright and capture the output
result = subprocess.run(["pyright", "--outputjson"], capture_output=True, text=True)
return result.stdout
@benoit74
benoit74 / list_warc_content.py
Created November 16, 2023 07:21
List requests present in WARC files
import glob
from warcio import ArchiveIterator
for warc in glob.glob("output/.tmph919m5n3/collections/crawl-*/archive/*.warc.gz"):
with open(warc, "rb") as fh:
for record in ArchiveIterator(fh):
if record.rec_type == "request":
print(record.rec_headers.get_header('WARC-Target-URI'))
print("DONE")
@benoit74
benoit74 / Explanation.md
Last active January 1, 2024 11:28
Observe Browsertrix Crawler web traffic

One might need to get a better grasp at what Browsertrix is performing in terms of trafic and where it is being blocked.

You might use the following docker compose stack to run:

  • a mitmweb web proxy to intercept all Browsertrix traffic and dump them on file
  • a screencasting Browsertrix crawler to get a grasp on crawler behavior

If you open http://localhost:9037, you will see Browsertrix screencasting of the browser.

mitmdump are placed in the output/mitmdump folder, with one file per minute.

@benoit74
benoit74 / deprecated-pods.py
Last active September 5, 2023 08:59
k8s: Find daemonsets with pod to delete for update, and print the corresponding node names
import json
import subprocess
nodes_str = subprocess.check_output(
["kubectl", "get", "nodes", "-o", "json"]
)
nodes = json.loads(nodes_str)
node_data = {}
for node in nodes.get("items"):
@benoit74
benoit74 / settings.json
Created April 27, 2023 06:50
Visual Studio Code settings for Python with black, isort and flake8
{
"[python]": {
"editor.defaultFormatter": "ms-python.black-formatter",
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.organizeImports": true
},
},
"isort.args": [
"--profile",