weave function

workspace
km0 3 years ago
parent 9a1c8ab52a
commit 9678674ee8

@ -2,6 +2,7 @@ import glob
import math import math
import mimetypes import mimetypes
import os import os
import queue
import subprocess import subprocess
import urllib import urllib
import yaml import yaml
@ -23,6 +24,7 @@ class Soup(Bureau):
prefix = "SB" prefix = "SB"
version = 0 version = 0
input_queue = [] input_queue = []
pattern = ''
def __init__(self): def __init__(self):
Bureau.__init__(self) Bureau.__init__(self)
@ -40,13 +42,14 @@ class Soup(Bureau):
self.print_small(game) self.print_small(game)
@add_command("ptrn", 'Set Pattern') @add_command("pa", 'Set Pattern')
def print_pattern(self, data): def print_pattern(self, data):
""" """
Prints a pattern composed with A and B characters. Prints a pattern composed with A and B characters.
""" """
pattern, _ = data.split(".") pattern, _ = data.split(".")
self.pattern = pattern
self.print_small(pattern) self.print_small(pattern)
@add_command('list', 'Return a list of contents') @add_command('list', 'Return a list of contents')
@ -96,6 +99,34 @@ class Soup(Bureau):
# @add_command('fx', 'execute the chosen function') # @add_command('fx', 'execute the chosen function')
# def ex_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(): def main():
sb = Soup() sb = Soup()

Loading…
Cancel
Save