diff options
| author | Paul Buetow <paul@buetow.org> | 2026-02-07 23:46:42 +0200 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2026-02-07 23:46:42 +0200 |
| commit | f408ae894e4e10bbf4358c7c07bb9618ef1353e4 (patch) | |
| tree | 0722f09473a58f1b9027e271cd6bd0e96e7a390d /scripts/randomnote.rb | |
| parent | bf56ef64278a90acab9116311e649e762d39cd34 (diff) | |
rename
Diffstat (limited to 'scripts/randomnote.rb')
| -rw-r--r-- | scripts/randomnote.rb | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/scripts/randomnote.rb b/scripts/randomnote.rb new file mode 100644 index 0000000..b0c1b49 --- /dev/null +++ b/scripts/randomnote.rb @@ -0,0 +1,30 @@ +#!/usr/bin/env ruby + +NOTES_DIR = "#{ENV['HOME']}/git/foo.zone-content/gemtext/notes" +BOOK_PATH = "#{ENV['HOME']}/Buecher/Diverse/Search-Inside-Yourself.txt" +MIN_PERCENTAGE = 80 +MIN_LENGTH = 10 + +class String + CLEAN_PATTERN = [ + /\d\d\d-\d\d-\d\d/, /[^A-Za-z0-9!.;,?'" @]/, + /http.?:\/\/\S+/, /\S+\.gmi/, /^\./, /^\d/, + ] + def clean + CLEAN_PATTERN.each {|p| gsub! p, '' } + gsub(/\s+/, ' ').strip + end + def letter_percentage?(threshold) = threshold <= (100 * count("A-Za-z")) / length +end + +begin + srand Random.new_seed + puts File.read((Dir["#{NOTES_DIR}/*.gmi"] + [BOOK_PATH]).shuffle.sample) + .split("\n") + .map(&:clean) + .select{ |l| l.length >= MIN_LENGTH } + .reject{ |l| l.match?(/(Published at|EMail your comments)/) } + .reject{ |l| l.match?(/'|book notes/) } + .select{ |l| l.letter_percentage?(MIN_PERCENTAGE) } + .shuffle.sample +end |
