Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env ~ath
- import re
- import in_place
- class MavisBeacon:
- def __init__(self):
- self.quirk = {
- 'AA': self.apocalypseArisen,
- 'AT': self.adiosToreador,
- 'TA': self.twinArmegeddons,
- 'CG': self.carcinoGeneticist,
- 'AC': self.arsenicCatnip,
- 'GA': self.grimAuxiliatrix,
- 'GC': self.gallowsCalibrator,
- 'AG': self.arachnidsGrip,
- 'CT': self.centaursTesticle,
- 'TC': self.terminallyCapricious,
- 'CA': self.caligulousAquarium,
- 'CC': self.cuttlefishCuller
- }
- self.colors = {
- 'AA': '#C61010',
- 'AT': '#914000',
- 'TA': '#A1A100',
- 'CG': '#7A7A7A',
- 'AC': '#618600',
- 'GA': '#009151',
- 'GC': '#008A8A',
- 'AG': '#0086B2',
- 'CT': '#3030F5',
- 'TC': '#7D20D9',
- 'CA': '#A300A3',
- 'CC': '#B10061'
- }
- self.start_color = '''<span style='color:{};'>'''
- def paint_text(self, color, text):
- tag = self.start_color.format(self.colors[color])
- return f'{tag}{text.rstrip()}</span>\n'
- @staticmethod
- def apocalypseArisen(string):
- buf = string.lower()
- buf = buf.replace('o', '0')
- return buf
- @staticmethod
- def adiosToreador(string):
- buf = string.upper()
- buf = buf.replace('.', ',')
- pat = re.compile(r', [A-Z]| I\'| I |}:O\)| \"[A-Z]')
- need_lowering = re.findall(pat, buf)
- for part in need_lowering:
- buf = buf.replace(part, part.lower())
- buf = buf.replace('TAVROS', 'tAVROS')
- buf = buf.replace('NITRAM', 'nITRAM')
- return buf
- @staticmethod
- def twinArmegeddons(string):
- buf = string.replace('s', '2')
- buf = buf.replace('i', 'ii')
- buf = buf.replace(' too ', ' two ')
- buf = buf.replace(' to ', ' two ')
- return buf
- @staticmethod
- def carcinoGeneticist(string):
- buf = string.upper()
- return buf
- @staticmethod
- def arsenicCatnip(string):
- buf = string.lower()
- buf = buf.replace('ee', '33')
- buf = ':33 < {}'.format(buf)
- buf = '<br>:33 < '.join([x for x in buf.split('<br>')])
- return buf
- @staticmethod
- def grimAuxiliatrix(string):
- buf = string.lower().capitalize()
- pat = re.compile(r' [a-z]')
- need_uppering = re.findall(pat, buf)
- for letter in need_uppering:
- buf = buf.replace(letter, letter.upper())
- return buf
- @staticmethod
- def gallowsCalibrator(string):
- buf = buf = string.upper()
- buf = buf.replace('A', '4')
- buf = buf.replace('I', '1')
- buf = buf.replace('E', '3')
- buf = buf.replace('!', '!!')
- buf = buf.replace('?', '??')
- return buf
- @staticmethod
- def arachnidsGrip(string):
- buf = string.replace('b', '8')
- buf = buf.replace('B', '8')
- buf = buf.replace('ate', '8')
- buf = buf.replace('ait', '8')
- buf = buf.replace('eight', '8')
- buf = buf.replace(':', '::::')
- buf = buf.replace(';', ':::;')
- buf = buf.replace('...', '........')
- return buf
- @staticmethod
- def centaursTesticle(string):
- buf = 'D --> {}'.format(string)
- buf = '<br>D --> '.join([x for x in buf.split('<br>')])
- buf = buf.replace('ex', '%')
- buf = buf.replace('x', '%')
- buf = buf.replace('ecks', '%')
- buf = buf.replace('ct', '%')
- buf = buf.replace('ks', '%')
- buf = buf.replace('cs', '%')
- buf = buf.replace('strong', 'STRONG')
- buf = buf.replace('strength', 'STRONGNESS')
- buf = buf.replace('100', 'loo')
- buf = buf.replace('001', 'ool')
- return buf
- @staticmethod # g for gamzee! c;
- def terminallyCapricious(string):
- buf = string.lower()
- gstring = ''
- upper_lower = [0, 1]
- for _ in buf:
- if _.isalpha():
- if upper_lower[0] == 0:
- gstring = f'{gstring}{_.upper()}'
- else:
- gstring = f'{gstring}{_.lower()}'
- dij = upper_lower.pop(0)
- upper_lower.append(dij)
- else:
- gstring = f'{gstring}{_}'
- gstring = gstring.replace(':O', ':o')
- gstring = gstring.replace('&RpAr', '&rpar')
- gstring = gstring.replace('&rPaR', '&rpar')
- gstring = gstring.replace('&lPaR', '&lpar')
- gstring = gstring.replace('&LpAr', '&lpar')
- return gstring
- @staticmethod
- def caligulousAquarium(string):
- buf = string.lower()
- buf = buf.replace('v', 'vv')
- buf = buf.replace('w', 'ww')
- buf = buf.replace('ing ', 'in ')
- buf = buf.replace(' of ', ' a ')
- buf = buf.replace('want to', 'wanna')
- buf = buf.replace('going to', 'gonna')
- buf = buf.replace('and ', 'an ')
- return buf
- @staticmethod
- def cuttlefishCuller(string):
- buf = string.replace('H', ')(')
- # buf = string.replace('h', ')(')
- buf = buf.replace('E', '-E')
- return buf
- def get_quirky(self, filename):
- activateTranslation = re.compile(r'\[[A-Z]{2}\]|\[\/[A-Z]{2}\]')
- with in_place.InPlace(filename) as f:
- for line in f:
- line_buffer = line
- tags = activateTranslation.findall(line_buffer)
- if len(tags) % 2 != 0:
- print('there is an odd number of tags in the line, so we '
- 'don\'t know how to handle this.\n'
- 'we\'re just gonna leave it as is.')
- return 0
- for pair in range(0, len(tags), 2):
- start_tag = tags[pair]
- end_tag = tags[pair+1]
- username = start_tag.strip('[]')
- tag_string = line[line.index(start_tag):
- line.index(end_tag) + len(end_tag)]
- tagged_text = tag_string[tag_string.index(start_tag) +
- len(start_tag):
- tag_string.index(end_tag)]
- line_buffer = line_buffer.replace(tag_string,
- self.quirk[username]
- (tagged_text))
- line_buffer = self.paint_text(username, line_buffer)
- f.write(line_buffer)
- if __name__ == '__main__':
- with open('AT_testfile.txt', 'r') as f:
- with open('AT_out', 'w') as o:
- for line in f:
- o.write(line)
- mb = MavisBeacon()
- mb.get_quirky('AT_out')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement