Skip to content

Instantly share code, notes, and snippets.

@lemon24
lemon24 / mutagen-mp4-tags.py
Last active December 2, 2025 00:23
using mutagen to update MP4 tags
import shutil
import mutagen
shutil.copy('original.mp4', 'new.mp4')
# mutagen.File knows how to open any file (works with both MP4 and MP4):
#
# https://mutagen.readthedocs.io/en/latest/user/gettingstarted.html
# https://mutagen.readthedocs.io/en/latest/api/base.html#mutagen.File
@lemon24
lemon24 / entry-word-counts.py
Created March 23, 2020 14:41
entries by summary/content word count order of magnitude; for https://github.com/lemon24/reader/issues/122
>>> import math, collections
>>> from reader import *
>>>
>>> reader = make_reader('db.sqlite')
>>>
>>> def word_count_magnitude(text):
... if not text:
... return 0
... return int(math.log10(len(text.split())))
...
@lemon24
lemon24 / fts5-search-syntax-errors.py
Last active March 20, 2020 12:31
brute force what kind of syntax errors FTS5 raises; for https://github.com/lemon24/reader/issues/122
import string
import random
from reader import make_reader, SearchError
reader = make_reader("db.sqlite")
def queries():
for i in range(256):
>>> from reader import make_reader
>>>
>>> reader = make_reader('db.sqlite')
>>> reader.add_feed('http://www.hellointernet.fm/podcast?format=rss')
>>> reader.update_feeds()
>>>
>>> entries = list(reader.get_entries(feed='http://www.hellointernet.fm/podcast?format=rss'))
>>> [e.title for e in entries]
['H.I. #108: Project Cyclops', 'H.I. #107: One Year of Weird', ...]
>>>
@lemon24
lemon24 / seach-shadow-table.py
Created March 14, 2020 19:46
reader full text search prototype #3; shadow table, with timing; https://github.com/lemon24/reader/issues/122
import timeit
import shutil
import textwrap
import functools
import bs4
# reader 0.18
from reader import make_reader
@lemon24
lemon24 / search-trigger-update-time.py
Last active March 13, 2020 12:04
reader full text search prototype #2; more detailed, timing triggers; https://github.com/lemon24/reader/issues/122
import timeit
import shutil
import textwrap
import functools
import bs4
# reader 0.18
from reader import make_reader
@lemon24
lemon24 / sqlite-fts5-highlight-group-by.sql
Last active November 8, 2023 04:34
SQLite FTS5: "unable to use function highlight in the requested context"; https://github.com/lemon24/reader/issues/122
-- fts5
CREATE VIRTUAL TABLE entries USING fts5(
id UNINDEXED,
content
);
INSERT INTO entries
VALUES
('one', 'one'),
import textwrap
import collections
class BaseQuery:
indent = ' '
separators = collections.defaultdict(
lambda: ',',
WHERE=' AND',
CREATE TABLE entries (
id TEXT NOT NULL,
feed TEXT NOT NULL,
title TEXT,
summary TEXT,
content TEXT,
PRIMARY KEY (id, feed)
);
@lemon24
lemon24 / process_multiplexer.py
Last active December 12, 2024 04:30
process_multiplexer.py (from threads to Curio)
"""
Read commands from stdin, run them in parallel, and send the output to stdout.
Command output looks like:
<command_id> <pid> (stdout|stderr) <original_line>
When a command exits, a single line containing the status is output:
<command_id> <pid> exited <status_code>