Advertisement
Guest User

heh, nice

a guest
Jan 26th, 2020
364
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.97 KB | None | 0 0
  1. #!/usr/bin/env ~ath
  2.  
  3. import re
  4. import in_place
  5.  
  6.  
  7. class MavisBeacon:
  8. def __init__(self):
  9. self.quirk = {
  10. 'AA': self.apocalypseArisen,
  11. 'AT': self.adiosToreador,
  12. 'TA': self.twinArmegeddons,
  13. 'CG': self.carcinoGeneticist,
  14. 'AC': self.arsenicCatnip,
  15. 'GA': self.grimAuxiliatrix,
  16. 'GC': self.gallowsCalibrator,
  17. 'AG': self.arachnidsGrip,
  18. 'CT': self.centaursTesticle,
  19. 'TC': self.terminallyCapricious,
  20. 'CA': self.caligulousAquarium,
  21. 'CC': self.cuttlefishCuller
  22. }
  23.  
  24. self.colors = {
  25. 'AA': '#C61010',
  26. 'AT': '#914000',
  27. 'TA': '#A1A100',
  28. 'CG': '#7A7A7A',
  29. 'AC': '#618600',
  30. 'GA': '#009151',
  31. 'GC': '#008A8A',
  32. 'AG': '#0086B2',
  33. 'CT': '#3030F5',
  34. 'TC': '#7D20D9',
  35. 'CA': '#A300A3',
  36. 'CC': '#B10061'
  37. }
  38.  
  39. self.start_color = '''<span style='color:{};'>'''
  40.  
  41. def paint_text(self, color, text):
  42. tag = self.start_color.format(self.colors[color])
  43. return f'{tag}{text.rstrip()}</span>\n'
  44.  
  45. @staticmethod
  46. def apocalypseArisen(string):
  47. buf = string.lower()
  48. buf = buf.replace('o', '0')
  49. return buf
  50.  
  51. @staticmethod
  52. def adiosToreador(string):
  53. buf = string.upper()
  54. buf = buf.replace('.', ',')
  55. pat = re.compile(r', [A-Z]| I\'| I |}:O\)| \"[A-Z]')
  56. need_lowering = re.findall(pat, buf)
  57. for part in need_lowering:
  58. buf = buf.replace(part, part.lower())
  59. buf = buf.replace('TAVROS', 'tAVROS')
  60. buf = buf.replace('NITRAM', 'nITRAM')
  61. return buf
  62.  
  63. @staticmethod
  64. def twinArmegeddons(string):
  65. buf = string.replace('s', '2')
  66. buf = buf.replace('i', 'ii')
  67. buf = buf.replace(' too ', ' two ')
  68. buf = buf.replace(' to ', ' two ')
  69. return buf
  70.  
  71. @staticmethod
  72. def carcinoGeneticist(string):
  73. buf = string.upper()
  74. return buf
  75.  
  76. @staticmethod
  77. def arsenicCatnip(string):
  78. buf = string.lower()
  79. buf = buf.replace('ee', '33')
  80. buf = ':33 &lt; {}'.format(buf)
  81. buf = '<br>:33 &lt; '.join([x for x in buf.split('<br>')])
  82. return buf
  83.  
  84. @staticmethod
  85. def grimAuxiliatrix(string):
  86. buf = string.lower().capitalize()
  87. pat = re.compile(r' [a-z]')
  88. need_uppering = re.findall(pat, buf)
  89. for letter in need_uppering:
  90. buf = buf.replace(letter, letter.upper())
  91. return buf
  92.  
  93. @staticmethod
  94. def gallowsCalibrator(string):
  95. buf = buf = string.upper()
  96. buf = buf.replace('A', '4')
  97. buf = buf.replace('I', '1')
  98. buf = buf.replace('E', '3')
  99. buf = buf.replace('!', '!!')
  100. buf = buf.replace('?', '??')
  101. return buf
  102.  
  103. @staticmethod
  104. def arachnidsGrip(string):
  105. buf = string.replace('b', '8')
  106. buf = buf.replace('B', '8')
  107. buf = buf.replace('ate', '8')
  108. buf = buf.replace('ait', '8')
  109. buf = buf.replace('eight', '8')
  110. buf = buf.replace(':', '::::')
  111. buf = buf.replace(';', ':::;')
  112. buf = buf.replace('...', '........')
  113. return buf
  114.  
  115. @staticmethod
  116. def centaursTesticle(string):
  117. buf = 'D --&gt; {}'.format(string)
  118. buf = '<br>D --&gt; '.join([x for x in buf.split('<br>')])
  119. buf = buf.replace('ex', '&#37;')
  120. buf = buf.replace('x', '&#37;')
  121. buf = buf.replace('ecks', '&#37;')
  122. buf = buf.replace('ct', '&#37;')
  123. buf = buf.replace('ks', '&#37')
  124. buf = buf.replace('cs', '&#37')
  125. buf = buf.replace('strong', 'STRONG')
  126. buf = buf.replace('strength', 'STRONGNESS')
  127. buf = buf.replace('100', 'loo')
  128. buf = buf.replace('001', 'ool')
  129. return buf
  130.  
  131. @staticmethod # g for gamzee! c;
  132. def terminallyCapricious(string):
  133. buf = string.lower()
  134. gstring = ''
  135. upper_lower = [0, 1]
  136. for _ in buf:
  137. if _.isalpha():
  138. if upper_lower[0] == 0:
  139. gstring = f'{gstring}{_.upper()}'
  140. else:
  141. gstring = f'{gstring}{_.lower()}'
  142. dij = upper_lower.pop(0)
  143. upper_lower.append(dij)
  144. else:
  145. gstring = f'{gstring}{_}'
  146.  
  147. gstring = gstring.replace(':O', ':o')
  148. gstring = gstring.replace('&RpAr', '&rpar')
  149. gstring = gstring.replace('&rPaR', '&rpar')
  150. gstring = gstring.replace('&lPaR', '&lpar')
  151. gstring = gstring.replace('&LpAr', '&lpar')
  152. return gstring
  153.  
  154. @staticmethod
  155. def caligulousAquarium(string):
  156. buf = string.lower()
  157. buf = buf.replace('v', 'vv')
  158. buf = buf.replace('w', 'ww')
  159. buf = buf.replace('ing ', 'in ')
  160. buf = buf.replace(' of ', ' a ')
  161. buf = buf.replace('want to', 'wanna')
  162. buf = buf.replace('going to', 'gonna')
  163. buf = buf.replace('and ', 'an ')
  164. return buf
  165.  
  166. @staticmethod
  167. def cuttlefishCuller(string):
  168. buf = string.replace('H', '&rpar;&lpar;')
  169. # buf = string.replace('h', '&rpar;&lpar;')
  170. buf = buf.replace('E', '-E')
  171. return buf
  172.  
  173. def get_quirky(self, filename):
  174. activateTranslation = re.compile(r'\[[A-Z]{2}\]|\[\/[A-Z]{2}\]')
  175. with in_place.InPlace(filename) as f:
  176. for line in f:
  177. line_buffer = line
  178. tags = activateTranslation.findall(line_buffer)
  179. if len(tags) % 2 != 0:
  180. print('there is an odd number of tags in the line, so we '
  181. 'don\'t know how to handle this.\n'
  182. 'we\'re just gonna leave it as is.')
  183. return 0
  184.  
  185. for pair in range(0, len(tags), 2):
  186. start_tag = tags[pair]
  187. end_tag = tags[pair+1]
  188. username = start_tag.strip('[]')
  189. tag_string = line[line.index(start_tag):
  190. line.index(end_tag) + len(end_tag)]
  191. tagged_text = tag_string[tag_string.index(start_tag) +
  192. len(start_tag):
  193. tag_string.index(end_tag)]
  194. line_buffer = line_buffer.replace(tag_string,
  195. self.quirk[username]
  196. (tagged_text))
  197. line_buffer = self.paint_text(username, line_buffer)
  198.  
  199. f.write(line_buffer)
  200.  
  201.  
  202. if __name__ == '__main__':
  203. with open('AT_testfile.txt', 'r') as f:
  204. with open('AT_out', 'w') as o:
  205. for line in f:
  206. o.write(line)
  207.  
  208. mb = MavisBeacon()
  209. mb.get_quirky('AT_out')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement