From 9678674ee8239a539f406a0cfbd8a25f36049ff2 Mon Sep 17 00:00:00 2001 From: Francesco Luzzana Date: Wed, 6 Apr 2022 18:53:57 +0200 Subject: [PATCH] weave function --- screenless/bureau/soup/soup.py | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/screenless/bureau/soup/soup.py b/screenless/bureau/soup/soup.py index 7f6abe3..c59baa8 100644 --- a/screenless/bureau/soup/soup.py +++ b/screenless/bureau/soup/soup.py @@ -2,6 +2,7 @@ import glob import math import mimetypes import os +import queue import subprocess import urllib import yaml @@ -23,6 +24,7 @@ class Soup(Bureau): prefix = "SB" version = 0 input_queue = [] + pattern = '' def __init__(self): Bureau.__init__(self) @@ -40,13 +42,14 @@ class Soup(Bureau): self.print_small(game) - @add_command("ptrn", 'Set Pattern') + @add_command("pa", 'Set Pattern') def print_pattern(self, data): """ Prints a pattern composed with A and B characters. """ pattern, _ = data.split(".") + self.pattern = pattern self.print_small(pattern) @add_command('list', 'Return a list of contents') @@ -96,6 +99,34 @@ class Soup(Bureau): # @add_command('fx', 'execute the chosen function') # def ex_function + @add_command('wv', 'veawe 2 texts') + def weave(self): + + result = '' + + with open(os.path.join(self.mdir, 'contents', self.input_queue[0] + '.txt'), 'r') as f: + list_a = f.read().split(' ') + + with open(os.path.join(self.mdir, 'contents', self.input_queue[1] + '.txt'), 'r') as f: + list_b = f.read().split(' ') + + text_a_cursor = 0 + text_b_cursor = 0 + + length = len(list_a) + len(list_b) + + repeated_pattern = (self.pattern * (length // len(self.pattern)) + ) + (length % self.pattern) + + for choice in repeated_pattern: + if choice == 'A': + result += list_a[text_a_cursor] + text_a_cursor += 1 + if choice == 'B': + result += list_b[text_b_cursor] + text_b_cursor += 1 + self.print_small(result) + def main(): sb = Soup()