From 1606e2727aed688a738e7b65d7580408f3e50650 Mon Sep 17 00:00:00 2001 From: Mike Lynch Date: Sun, 2 Nov 2025 11:11:09 +1100 Subject: [PATCH] Now filters emojo by tag and adds more blanks --- README.md | 3 ++ emoji_shortcodes.txt => emojos.txt | 56 +++++++++++++------------- grawlix.py | 63 +++++++++++++++++++++++------- 3 files changed, 79 insertions(+), 43 deletions(-) create mode 100644 README.md rename emoji_shortcodes.txt => emojos.txt (52%) diff --git a/README.md b/README.md new file mode 100644 index 0000000..79d6b74 --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +# grawlix + +A bot for posting grids of emojis to GoToSocial or Mastodon diff --git a/emoji_shortcodes.txt b/emojos.txt similarity index 52% rename from emoji_shortcodes.txt rename to emojos.txt index 04dc6b7..53d7236 100644 --- a/emoji_shortcodes.txt +++ b/emojos.txt @@ -1,4 +1,4 @@ -:grawlix_null: blank +:grawlix_null: mono blank :grawlix_angle: colour yellow :grawlix_ball1: colour green :grawlix_ball2: colour blue @@ -6,51 +6,51 @@ :grawlix_bullseye: colour :grawlix_bun: colour yellow :grawlix_claw: colour red -:grawlix_cloud: -:grawlix_crosses: texture -:grawlix_crumple: texture +:grawlix_cloud: mono +:grawlix_crosses: mono texture +:grawlix_crumple: mono texture :grawlix_drop: colour purple -:grawlix_dust1: texture -:grawlix_dust2: texture +:grawlix_dust1: mono texture +:grawlix_dust2: mono texture :grawlix_feather: colour green :grawlix_flower: colour blue :grawlix_fruit: colour green :grawlix_fungus: colour yellow -:grawlix_fur: texture +:grawlix_fur: mono texture :grawlix_gadget: colour red :grawlix_globule: colour pink -:grawlix_glyph1: glyph -:grawlix_glyph10: glyph -:grawlix_glyph2: glyph -:grawlix_glyph3: glyph -:grawlix_glyph4: glyph -:grawlix_glyph5: glyph -:grawlix_glyph6: glyph -:grawlix_glyph7: glyph -:grawlix_glyph8: glyph -:grawlix_glyph9: glyph -:grawlix_growth: -:grawlix_hatch: texture +:grawlix_glyph1: mono glyph +:grawlix_glyph10: mono glyph +:grawlix_glyph2: mono glyph +:grawlix_glyph3: mono glyph +:grawlix_glyph4: mono glyph +:grawlix_glyph5: mono glyph +:grawlix_glyph6: mono glyph +:grawlix_glyph7: mono glyph +:grawlix_glyph8: mono glyph +:grawlix_glyph9: mono glyph +:grawlix_growth: mono +:grawlix_hatch: mono texture :grawlix_helm: colour red :grawlix_horizon: colour pink -:grawlix_joint: texture -:grawlix_knothole: texture +:grawlix_joint: mono texture +:grawlix_knothole: mono texture :grawlix_link: colour trans :grawlix_lump: colour yellow :grawlix_mountain: colour blue -:grawlix_orbit: +:grawlix_orbit: mono :grawlix_popup: colour yellow :grawlix_rects: colour trans :grawlix_rough: colour texture pink :grawlix_scales: colour texture red -:grawlix_scrawl: texture +:grawlix_scrawl: mono texture :grawlix_scribble: colour texture green :grawlix_shatter: colour texture :grawlix_signal: colour :grawlix_slump: colour texture green -:grawlix_spark1: -:grawlix_spark2: -:grawlix_sprout: -:grawlix_strata: texture -:grawlix_vertical: texture +:grawlix_spark1: mono +:grawlix_spark2: mono +:grawlix_sprout: mono +:grawlix_strata: mono texture +:grawlix_vertical: mono texture :grawlix_wreck: texture colour blue diff --git a/grawlix.py b/grawlix.py index 7b16361..75c47a3 100755 --- a/grawlix.py +++ b/grawlix.py @@ -1,25 +1,55 @@ import random import sys from botclient.botclient import Bot - -GRAWLIX = [ - "angle", "ball1", "ball2", "brick", "bullseye", "bun", "claw", "cloud", - "crosses", "crumple", "drop", "dust1", "dust2", "feather", "flower", "fruit", - "fungus", "fur", "gadget", "globule", "glyph1", "glyph10", "glyph2", "glyph3", - "glyph4", "glyph5", "glyph6", "glyph7", "glyph8", "glyph9", "growth", "hatch", - "helm", "horizon", "joint", "knothole", "link", "lump", "mountain", "null", - "orbit", "popup", "rects", "rough", "scales", "scrawl", "scribble", "shatter", - "signal", "slump", "spark1", "spark2", "sprout", "strata", "vertical", "wreck", -] +from collections import defaultdict GRID_TYPES = [ "latin_square", "concentric", "sator", "random", "vertical", "horizontal" ] +BLANK_P = { + 0: 3, + 1: 2, + 2: 2, + 3: 1, + 4: 1, + 5: 1, + 6: 0, + 7: 0, + 8: 0, + 9: 0, +} class Grawlix(Bot): def __init__(self): super().__init__() self.ap.add_argument('-a', '--all', action='store_true', help="Dump a random grid of emojos") + self.ap.add_argument('-t', '--test', action='store_true', help="Dump emojo list") + + def load_emojos(self): + self.emojos = [] + self.groups = defaultdict(set) + with open(self.cf["emojos"], "r") as efh: + for line in efh: + parts = line.split() + self.emojos.append(parts[0]) + for tag in parts[1:]: + self.groups[tag].add(parts[0]) + self.tags = [ t for t in self.groups.keys() if not t == "blank" ] + + + def make_glyphset(self, n): + blanks_r = random.randrange(10) + blanks_n = BLANK_P[blanks_r] + emojos_n = n - blanks_n + if "groups" in self.cf and random.randrange(2) == 0: + tag = random.choice(self.cf["groups"]) + glyphset = random.sample(list(self.groups[tag]), emojos_n) + else: + glyphset = random.sample(self.emojos, emojos_n) + blank = list(self.groups["blank"])[0] + glyphset += ( [ blank ] * blanks_n ) + random.shuffle(glyphset) + return glyphset def latin_square(self): return [ @@ -82,10 +112,6 @@ class Grawlix(Bot): def grid_glyphs(self, grid): return max([max(row) for row in grid]) + 1 - def make_glyphset(self, n): - names = random.sample(GRAWLIX, n) - return [ f":grawlix_{name}:" for name in names ] - def render_row(self, row, glyphs): return " ".join([glyphs[c] for c in row]) @@ -93,12 +119,14 @@ class Grawlix(Bot): grid = self.make_grid() n = self.grid_glyphs(grid) glyphs = self.make_glyphset(n) + if self.args.dry_run: + print(glyphs) rows = [ self.render_row(r, glyphs) for r in grid ] return "\n".join(rows) def header(self): for r in range(20): - names = [ random.choice(GRAWLIX) for c in range(100) ] + names = [ random.choice(self.emojos) for c in range(100) ] files = [ f' ' for n in names ] print(''.join(files)) print('
') @@ -108,9 +136,14 @@ class Grawlix(Bot): if __name__ == '__main__': g = Grawlix() g.configure() + g.load_emojos() if g.args.all: g.header() sys.exit(1) + if g.args.test: + print(g.tags) + print(g.cf) + sys.exit(1) post = g.render() g.wait() g.post(post) -- 2.47.3