Beispiel #1
0
class testFormatter(unittest.TestCase):
    def setUp(self):
        self.sut = Formatter()

    def test_returns_zero_seconds(self):
        result = self.sut.Format(datetime.timedelta(seconds = 0))

        self.assertEquals("0 seconds", result)

    def test_returns_one_second(self):
        result = self.sut.Format(datetime.timedelta(seconds = 1))

        self.assertEquals("1 second", result)

    def test_returns_many_seconds(self):
        result = self.sut.Format(datetime.timedelta(seconds = 25))

        self.assertEquals("25 seconds", result)

    def test_returns_one_minute(self):
        result = self.sut.Format(datetime.timedelta(minutes = 1))

        self.assertEquals("1 minute", result)

    def test_returns_many_minutes(self):
        result = self.sut.Format(datetime.timedelta(minutes = 15))

        self.assertEquals("15 minutes", result)
Beispiel #2
0
 def __init__(self, **kwargs):
     Formatter.__init__(self,
                        dataStart='<table>\n',
                        dataEnd='</table>\n',
                        listItemStart='   <tr>',
                        listItemEnd='</tr>\n',
                        **kwargs)
Beispiel #3
0
def test_one(pair):
    # print('pair: ' + pair)
    table = create_table()
    indicators = BotIndicators()
    data = load_data(pair)  # Historical data for given currency

    position_entered = False  # Used to track when to enter/exit trade
    entry_price = 0.0
    entry_date = 0
    exit_date = 0
    purse = 0.0  # Amount gained/lossed from trading
    close_prices = []
    table_row = []
    period_count = 0

    for tick in data:
        # tick - OHLCV
        current_price = float(tick[2])
        close_prices.append(current_price)

        golden_cross_entry = TradingStrategies.golden_cross(
            close_prices, indicators)

        if not position_entered:
            if (golden_cross_entry):
                position_entered = True
                entry_price = current_price
                entry_date = TimeConversions.milliseconds_to_date(tick[0])
                current_price_formatted = Formatter.money_format(current_price)
                table_row = [entry_date, current_price_formatted]
                # print('entry_date: {} current_price: {}'.format(entry_date, money_format(current_price)))
        else:
            if not golden_cross_entry:
                position_entered = False
                exit_date = TimeConversions.milliseconds_to_date(tick[0])
                length_of_trade = TradeUtilityFunctions.get_length_of_trade(
                    period_count)
                net_of_trade = TradeUtilityFunctions.calculate_net_of_trade(
                    entry_price, current_price)
                net_usd = net_of_trade[0]
                purse += net_usd
                percentage = net_of_trade[1]

                # print('net_usd: {} percentage: {}'.format(net_usd, percentage))

                table_row.extend(
                    (exit_date, Formatter.money_format(current_price),
                     length_of_trade, Formatter.money_format(net_usd),
                     Formatter.percentage_format(percentage)))

                table.add_row(table_row)

                period_count = 0

        if position_entered:
            period_count += 1

    print(table)
    print('Net Profit: {}'.format(Formatter.money_format(purse)))
def test_Formatter_reverse():
    formatter = Formatter(mock_account.history)
    formatter.reverse()
    assert formatter.partial_history == [
        ['14/01/2012', '', 500, 2500],
        ['13/01/2012', 2000, '', 3000],
        ['10/01/2012', 1000, '', 1000]
    ]
def test_Formatter_format_integer():
    formatter = Formatter(mock_account.history)
    formatter.format_integer()
    assert formatter.partial_history == [
        ['10/01/2012', '1000.00', '', '1000.00'],
        ['13/01/2012', '2000.00', '', '3000.00'],
        ['14/01/2012', '', '500.00', '2500.00']
    ]
Beispiel #6
0
 def __init__(self, **kwargs):
     Formatter.__init__(self,
                        listStart='[\n',
                        listEnd='\n]\n',
                        listItemStart='   { ',
                        listItemEnd=' }',
                        listItemSep=',\n',
                        fieldSep=', ',
                        **kwargs)
Beispiel #7
0
    def go():
        f = Formatter()
        the_url = 'http://pokemondb.net/pokedex/'
        the_is = InitialScraper()
        the_is.do_scrape(the_url)

        the_list = f.add_url(the_is.names, the_url)

        the_ds = DetailScraper()
        the_dex = the_ds.do_scrape(the_list)
        print(the_dex)
        for element in the_dex:
            print(element.get_name())
def test_Formatter_to_string():
    formatter = Formatter(mock_account.string)
    formatter.reverse()
    formatter.format_integer()
    formatter.to_string()
    answer = "date || credit || debit || balance\n10/01/2012 || 1000.00 ||  || 1000.00"
    assert formatter.processed_history == answer
    def Parse(self, data, meta):
        try:
            data_type, istance, prog_name = meta
            f = Formatter()
            
            if data_type == "o":
                self.dicted = f.dictionarize(data, self.tags)
                
                try:
                    data = str(self.dicted["subject:"]) + str(self.dicted["body:"])#error if not exist one of the two?
                except:
                    try:
                        data = self.dicted["subject:"]
                    except:
                        try:
                            data = self.dicted["body:"]

                        except:
                            raise

            elif data_type == "i":
                #if self.dicted exist
                
                splitted = data.split("\n", 1)

                
                self.dicted["subject:"] = splitted[0]
                    
                if len(splitted) != 1:
                    self.dicted["body:"] = splitted[1]
                    
                else:
                    self.dicted["body:"] = ""

                

                return (self.dicted["from:"] + "\n" + #to
                        self.dicted["subject:"] + "\n" + #sub
                        self.dicted["body:"] + "\n" + #body
                        "None" #attach
                        )
                #f.delinefy(data) -> f.linefy("to:self.dicted["from:"] sub:line1 body:lines", " ")
                
            
            return data
        
        except:
            raise
Beispiel #10
0
    def show(self):
        '''
		Method to show current SAN Storage Multipath LUNs.
		It uses detect method to parse results and Formatter class to output it.
		'''
        self.detect()
        return Formatter().show(self)
Beispiel #11
0
    def __init__(self, host, port, idx, dct):
        print "creating feeder with conf host =" + host + "\n port=" + port + "\n index=" + idx + "\n docType=" + dct
        self.index = idx
        self.docType = dct
        self.host = host
        self.port = port

        self.eDao = ElasticDao(self.host, self.port)
        self.analyzer = Analyzer()
        self.formatter = Formatter()
        self.database_dir = "/Applications/XAMPP/htdocs/music_search/data_mp3_files/" + self.docType
        try:
            shutil.rmtree(self.database_dir)
        except:
            pass
        os.makedirs(self.database_dir)
Beispiel #12
0
 def __init__(self):
     '''
     Start input choice.
     '''
     self.mPrinter = Printer()
     self.mFormatter = Formatter()
     inputType = self.chooseInputType()
     if(inputType is None):
         print("Invalid input type.")
         return
     if(inputType == self.TYPE_TEXT):
         print("Text input type selected.")
         #Handle text type input.
         self.chooseTextInput()
         return
     if(inputType == self.TYPE_ASCII):
         print("Ascii art input type selected.")
         #TODO: Handle ascii art type input.
         return
     if(inputType == self.TYPE_IMAGE):
         print("Image input type selected.")
         #TODO: Handle image type input.
         return
     if(inputType == self.TYPE_STREAM):
         print("Stream input type selected.")
         #TODO: Hande stream type input.
         return
     print("Unknown input type.")
     return
Beispiel #13
0
    def show(self):
        '''
		Method to show current LVM Volume Groups.
		It uses detect method to parse results and Formatter class to output it.
		'''
        self.detect()
        return Formatter().show(self)
Beispiel #14
0
	def show(self):
		'''
		Method to show current File Systems.
		It uses detect method to parse results and Formatter class to output it.
		'''
		self.detect()
		return Formatter().show(self)
Beispiel #15
0
    def Parse(self, data, meta):
        try:
            data_type, istance, prog_name = meta
            f = Formatter()

            if data_type == "o":
                self.dicted = f.dictionarize(data, self.tags)

                try:
                    data = self.dicted["msg:"]

                except:
                    raise

            elif data_type == "i":
                data_list = f.listfy(data, "\n")
                if data_list[-1] == str() and data_list != list():
                    data_list.pop()

                data = str()
                for d in data_list:
                    if d != str() or d != " ":
                        data += (
                            self.dicted["from:"] + "\n" +  #to:
                            d + "\n")  #msg:
                        try:
                            print "to: " + str(self.dicted["from:"])
                            print "msg: " + str(d)
                            self.tg_client.sender.send_msg(
                                unicode(self.dicted["from:"].replace(" ", ""),
                                        "utf-8"), unicode(d, "utf-8"))
                        except:
                            try:
                                info = sys.exc_info()
                                print info
                            except:
                                continue

                data = data[:-1]
                #data = str(data_list)#for debugging purpose

            return data

        except:
            raise
Beispiel #16
0
    def __init__(self, in_file, out_file):

        self.tm = Text_manipulator()
        self.f = Formatter()
        self.i = Importer()

        self.tm.silent = True

        self.out_file = out_file
        self.in_file = in_file

        self.links = dict()

        self.links["mail_client.py"] = "bash"
        #self.links["bash"] = "mail_client.py"

        self.links["tg_client.py"] = "bash"
        self.links["bash"] = "tg_client.py"
Beispiel #17
0
class Feeder:
    index = "music_search"
    docType = "mp3_v7"
    host = "localhost"
    port = "9200"

    def __init__(self, host, port, idx, dct):
        print "creating feeder with conf host =" + host + "\n port=" + port + "\n index=" + idx + "\n docType=" + dct
        self.index = idx
        self.docType = dct
        self.host = host
        self.port = port

        self.eDao = ElasticDao(self.host, self.port)
        self.analyzer = Analyzer()
        self.formatter = Formatter()
        self.database_dir = "/Applications/XAMPP/htdocs/music_search/data_mp3_files/" + self.docType
        try:
            shutil.rmtree(self.database_dir)
        except:
            pass
        os.makedirs(self.database_dir)

    def feed(self, start_dir):
        print "Started feeding from source dir=" + start_dir
        count = 0
        mp3Count = 0
        failCount = 0
        for root, dirs, files in os.walk(start_dir):
            for name in files:
                if (name.endswith('.mp3')):
                    try:
                        src_filepath = os.path.join(root, name)
                        dest_filepath = os.path.join(self.database_dir, name)
                        shutil.copyfile(src_filepath, dest_filepath)
                        tmp_block = self.analyzer.analyze(dest_filepath)
                        tmp_block = self.formatter.format(tmp_block)
                        tmp_block['source'] = urllib.pathname2url(
                            "/music_search/data_mp3_files/" + self.docType +
                            "/" + name)
                        self.eDao.put(self.index, self.docType, tmp_block)
                        mp3Count += 1
                    except Exception, e:
                        failCount += 1
                        print "ERR : " + os.path.join(root, name)
                        print e
            count += 1
            if (count % 1000 == 0):
                print "INFO : total files scaned= " + str(
                    count) + "\t mp3= " + str(mp3Count) + "\t failed= " + str(
                        failCount) + " \n"
        print "INFO : total files scaned= " + str(count) + "\t mp3= " + str(
            mp3Count) + "\t failed= " + str(failCount) + " \n"
 def show_pixel_values(self, title):
     """
     This function is able to show a one-color-channel image and display the pixel value of the pixel below the
     mouse cursor.
     :param title: The title of the image.
     :return: -
     """
     fig, ax = plt.subplots()
     im = ax.imshow(self.input_image, interpolation='none')
     ax.format_coord = Formatter(
         im
     )  # Uses the custom class Formatter for pixel values (not from me).
     fig.suptitle(title)
     plt.show()
Beispiel #19
0
   def __init__(self, host):
      Cmd.__init__(self)

      self.host = host
      self.formatter = Formatter.GetByType('simple')
      self.progressBar = None

      self.SetupTaskManager()
      self.SetPrompt()
      self.SetupFormatters()
      self.SetupReadline()
      self.ReadRcFile()

      for opName, op in operations.opsDict.items():
         setattr(self, 'do_%s' % opName, self.GetFunc(opName, op))
         setattr(self, 'help_%s' % opName, self.GetHelpFunc(opName, op))
Beispiel #20
0
    def Parse(self, data, meta):
        try:
            data_type, istance, prog_name = meta
            f = Formatter()

            if data_type == "o":
                #data = f.delinefy(data)
                pass

            if data_type == "i":
                pass

            return data

        except:
            raise
Beispiel #21
0
    def create(self):
        '''
		Method to create /etc/multipath.conf aliases and wwids based on interactive user input.
		It puts a suffix for multiple LUNs.
		'''
        rootvg = Root()
        usrsap = UsrSap()
        data = Data()
        log = Log()
        shared = Shared()
        new_luns = Lun()
        final_luns = Lun()
        purposes = [rootvg, usrsap, data, log, shared]
        str_multipaths = ''

        self.show()

        for purpose in purposes:

            if purpose == rootvg:
                title = purpose.name
            else:
                title = purpose.fs_mount_point

            print 'Type current LUN \033[1mINDEXES\033[0m to be used for %s (comma-separated):' % (
                title),
            pvs = re.findall('\d+', raw_input())
            pv_amount = len(pvs)

            if not pvs:
                continue

            print 'Type Physical Volume name \033[1mPREFIX\033[0m for %s:' % (
                title),
            pv_prefix = raw_input()

            pv_count = 1
            for pv in pvs:

                if purpose in (rootvg, usrsap) and pv_amount == 1:
                    pv_new_name = pv_prefix
                else:
                    pv_suffix = str(pv_count)
                    pv_new_name = pv_prefix + pv_suffix
                pv_count += 1

                for lun in self.get():

                    if lun.index == pv:
                        lun.name = pv_new_name
                        new_luns.add(
                            Lun(index=str(lun.index),
                                size=lun.size,
                                wwid=lun.wwid,
                                vendor=lun.vendor,
                                product=lun.product,
                                name=lun.name))
                        str_multipaths += '\tmultipath {\n\t\twwid %s\n\t\talias %s\n\t}\n' % (
                            lun.wwid, lun.name)

            Formatter().show(new_luns)

        self.create_multipath_conf(str_multipaths)

        final_luns.show()
Beispiel #22
0
 def get(self, name): #Método que traz uma piada aleatória a partir deste array
   genericList = Joke.populateList(self.__fileName__) 
   index = randint(0,len(genericList)) - 1
   return Formatter.replaceByName(genericList[index],name)
Beispiel #23
0
import yaml
from yaml import load, load_all
from Formatter import Formatter

pretty = Formatter()

stream = open('sample.yaml', 'r')

data = load_all(stream, Loader=yaml.FullLoader)

#print(pretty(data))

for doc in data:
    print("New Document:")
    if type(doc) is list:
        print(pretty(doc))
        #print(doc)
    else:
        print(pretty(doc))
        #for key, value in doc.items():
        #    print(key + ": " + str(value))
Beispiel #24
0
  # System Utility Initialization...
  proc_service    = Procs()
  mem_service     = MemInfo()
  log_service     = Meow()
  network_service = Network()

  log_service.thread_up()

  with open(record_path, "r") as handle:
    for line in handle:
      if line.strip() == "":
        continue
      p, r = line.strip().split(", ")
      pre_status[p] = True if r == "T" else False

  f = Formatter()

  # Set Up Apk
  pp = pprint.PrettyPrinter(indent=4)
  samples_info = {}
  for sample_path in list_dir(sample_path):
    print sample_path
    sample = get_sample_structure(sample_path)
    # pp.pprint(sample)
    run_status = test_can_run(sample, proc_service, test=False)

    continue

    # vendors == ["baidu", "bangcle", ...]
    vendors = [k for k in sample.keys()
               if not k.startswith("tamper_") and not k in sigs]
Beispiel #25
0
class Processor():
    def __init__(self, in_file, out_file):

        self.tm = Text_manipulator()
        self.f = Formatter()
        self.i = Importer()

        self.tm.silent = True

        self.out_file = out_file
        self.in_file = in_file

        self.links = dict()

        self.links["mail_client.py"] = "bash"
        #self.links["bash"] = "mail_client.py"

        self.links["tg_client.py"] = "bash"
        self.links["bash"] = "tg_client.py"

    def simple_spawn(
        self, f, arg
    ):  #simple cause it can be implemented as multicore/multimachine distributed computation technlology using multiprocessing.manager
        try:
            from multiprocessing import Process
            p = Process(target=f, args=(arg, ))
            p.start()
        except:
            raise

    def inParse(self, raw):
        #print "\n"
        #print "[p] parsing..."
        raw_list = list()
        listified = self.f.listfy(raw, "\n")

        for line in listified:
            meta_data, data = self.f.filter_in(line)

            if meta_data == None:
                if raw_list != list():
                    raw_list[-1][1] = raw_list[-1][1] + "\n" + data
                else:
                    #print "-databug in tg_client_API at ln 58 in inParse()-"
                    #print data
                    #print type(data)
                    pass

            else:
                raw_list.append([self.metaInParse(meta_data), data])

        return raw_list

    def outParse(self, meta, data):

        return self.f.filter_out(data, meta)  #switch?

    def metaInParse(self, meta):  #meta: [i/o] [n] [program_name]
        print  #"\n"
        print  #"[p] meta-parsing [%s ]" % (str(meta))

        return meta.split(" ")

    def metaOutParse(self, meta):

        return self.f.stringfy(meta, " ")

        return [data_type, istance, prog_name]

    def identyParse(self, data):  #maybe it can be an API
        pass

    def metaIdentyParse(self, meta):
        data_type, istance, prog_name = meta

        if data_type == "o": return True
        else: return False

    def dataParse(self, data, meta):
        #parsing prog_data oriented to op_data oriented
        try:
            data_type, istance, prog_name = meta

            Parser = self.i._get(prog_name.replace(".", "_") + "_API.py")

            return Parser.P2oParser.Parse(data, meta)

        except:
            raise

    def linker(self, meta):
        data_type, istance, prog_name = meta

        if data_type == "i":
            data_type = "o"
        else:
            data_type = "i"

        prog_name = self.links[prog_name]

        return data_type, istance, prog_name

    def compute(self, raw):
        #bot part:
        #   -[status]> coded but not implemented as compatible script
        #AI part: <- AI stand for artificial intelligence, but can stand for anarchy/ist intelligence
        #   -[status]> not coded and not implemented, suggest: use pybrain neural networks

        #

        #print "\n"
        #print "[c] computing [%s ]" % (str(raw))

        meta = raw[0]
        data = raw[1]
        #if not self.IdentyParse(data) and or self.metaIdentyParse(meta): return
        if not self.metaIdentyParse(meta): return

        data = self.dataParse(data, meta)

        meta = self.linker(meta)  #that does the trick

        data = self.dataParse(data, meta)

        data = self.outParse(self.metaOutParse(meta), data)

        self.output(data)

        print data

    def output(self, data):
        try:
            #print "\n"
            #print "[o] %s" % (str(data))
            self.tm.Write_as_output(self.out_file, data)
        except:
            raise

    def server(self):
        print "[!] running..."
        while True:
            try:
                raw = self.tm.Read_as_input(self.in_file)
                #print "\n"
                #print "[i] %s" % (str(raw))
                raw_list = self.inParse(raw)

                for raw in raw_list:

                    self.simple_spawn(self.compute, raw)

            except KeyboardInterrupt:
                print "\n"
                print "[!] server stopping..."
                break

            except:
                raise
        print "[!] server stopped"
        exit()
Beispiel #26
0
 def setUp(self):
     storage = Storage()
     users = Users()
     formatter = Formatter()
     self.sut = App(storage, users, formatter)
Beispiel #27
0
            #Проверка на наличие шаблонов
            if patterns:
                r = requests.get(url)

                #По статусу get-запроса начинаем прасить и форматировать
                #или выводим код ошибки
                if r.status_code == 200:
                    host = '/'.join(url.split('/')[:3])
                    obj_parser = Parser(content=r.text,
                                        patterns=patterns,
                                        tags_and_classes=tags_and_classes,
                                        host=host)
                    obj_parser.parse()
                    obj_formatter = Formatter(list_texts=obj_parser.list_texts,
                                              url=url,
                                              line_width=line_width,
                                              cur_dir=cur_dir)
                    obj_formatter.formate()
                else:
                    print(f'Код ошибки {r.status_code}')
            else:
                print(
                    "Пожалуйста добавьте шаблон обработки для сайта в config.json"
                )
        else:
            print("Неверный URL-адрес")

        t = input('Желаете продолжить? (y/n) ').lower()
        flag = True if (
            t == 'y'
        ) else False  #при либом вводе, кроме 'y', будет выходить из цикла
Beispiel #28
0
 def __init__(self, **kwargs):
     Formatter.__init__(self, listItemEnd='\n', **kwargs)
Beispiel #29
0
    # System Utility Initialization...
    proc_service = Procs()
    mem_service = MemInfo()
    log_service = Meow()
    network_service = Network()

    log_service.thread_up()

    with open(record_path, "r") as handle:
        for line in handle:
            if line.strip() == "":
                continue
            p, r = line.strip().split(", ")
            pre_status[p] = True if r == "T" else False

    f = Formatter()

    # Set Up Apk
    pp = pprint.PrettyPrinter(indent=4)
    samples_info = {}
    for sample_path in list_dir(sample_path):
        print sample_path
        sample = get_sample_structure(sample_path)
        # pp.pprint(sample)
        run_status = test_can_run(sample, proc_service, test=False)

        continue

        # vendors == ["baidu", "bangcle", ...]
        vendors = [
            k for k in sample.keys()
Beispiel #30
0
    validator.constructRawData()

    if validator.isValidData():
        print("Both players' data is valid")
    else:
        sys.exit("Data is not valid")

    if validator.isSyncedData():
        print("Data is synced between players\n")
    else:
        sys.exit("Data is not synced")

    # print(validator)

    ##### FORMATTING #####
    formatter = Formatter(player1, player2)

    formatter.parseFormatData()
    formatter.addPercent()
    formatter.addSecond()
    formatter.comparePlayersFormat()
    formatter.createJSON()

    # now we have the path to the formatted data, we can start comparing the maps, times, and ranks.
    FORMATTED_DATA_PATH = formatter.getPath(
    )  ### YAY now we can actually start comparing

    ##### COMPARING ######
    ### MAPS COMPARE ###
    compareMaps = CompareMaps(FORMATTED_DATA_PATH)
    player1_uncompleted_maps = compareMaps.uncompletedMaps(1)
Beispiel #31
0
 def __init__(self):
     self.names = []
     self.f = Formatter()
Beispiel #32
0
class Input(object):
    '''
    Stores a bunch of different raw inputs to be used.
    '''

    TYPE_TEXT = "text"
    TYPE_ASCII = "ascii"
    TYPE_IMAGE = "image"
    TYPE_STREAM = "stream"

    mPrinter = None
    mFormatter = None

    def __init__(self):
        '''
        Start input choice.
        '''
        self.mPrinter = Printer()
        self.mFormatter = Formatter()
        inputType = self.chooseInputType()
        if(inputType is None):
            print("Invalid input type.")
            return
        if(inputType == self.TYPE_TEXT):
            print("Text input type selected.")
            #Handle text type input.
            self.chooseTextInput()
            return
        if(inputType == self.TYPE_ASCII):
            print("Ascii art input type selected.")
            #TODO: Handle ascii art type input.
            return
        if(inputType == self.TYPE_IMAGE):
            print("Image input type selected.")
            #TODO: Handle image type input.
            return
        if(inputType == self.TYPE_STREAM):
            print("Stream input type selected.")
            #TODO: Hande stream type input.
            return
        print("Unknown input type.")
        return


    def chooseInputType(self):
        '''
        Ask the user what type of input they want
        '''
        print("Please select an input type.")
        print("Available input types: text, ascii art, image, stream")
        userInput = input("Enter type: ")
        userInputClean = userInput.strip().lower()
        if(userInputClean in ['text']):
            return self.TYPE_TEXT
        if(userInputClean in ['ascii','ascii art','asciiart']):
            return self.TYPE_ASCII
        if(userInputClean in ['image','img','picture','pic']):
            return self.TYPE_IMAGE
        if(userInputClean in ['stream','feed','twitter']):
            return self.TYPE_STREAM
        return None

    def chooseTextInput(self):
        'chooses a text input'
        print("Available text inputs: tech support oath, not my business, HAL9000 warning, raw.")
        userInput = input("Please select: ")
        userInputClean = userInput.lower().strip()
        if(userInputClean in ['tech support oath','techsupportoath','oath']):
            oathOutput = self.techSupportOath()
            self.mPrinter.printRaw(oathOutput)
            print("Printing complete")
            return
        if(userInputClean in ['not my business','notmybusiness']):
            poemOutput = self.notMyBusiness()
            self.mPrinter.printRaw(poemOutput)
            print("Printing complete")
            return
        if(userInputClean in ['hal9000 warning','hal warning','hal']):
            warnOutput = self.halWarning()
            self.mPrinter.printRaw(warnOutput)
            print("Printing complete")
            return

    def techSupportOath(self):
        '''
        Recites the tech support oath.
        Parody of the Night's Watch oath.
        '''
        output = "User issues gather, and now my watch begins. " 
        output += "It shall not end until my death. "
        output += "I shall take no wife (that I will ever see except on weekends), "
        output += "hold no lands (because I don't make nearly enough), "
        output += "father no children (because I will never be home anyway). "
        output += "I shall receive no thanks and win no glory. "
        output += "I shall live and die at my desk. "
        output += "I am the antivirus in the darkness. "
        output += "I am the coder on the walls. "
        output += "I am the password reset that guards the logins of men. "
        output += "I pledge my life and honor to the Help Desk's Watch, "
        output += "for this night and all the nights to come."
        printOutput = self.mFormatter.title("Tech support oath")
        printOutput += self.mFormatter.multiLine(output)
        return printOutput
    
    def notMyBusiness(self):
        '''
        Outputs Niyi Osundere's "Not my business"
        '''
        output = self.mFormatter.title("Not My Business")
        output += self.mFormatter.title("by Niyi Osundere")
        output += b"They picked Akanni up one morning\n"
        output += b"Beat him soft like clay\n"
        output += b"And stuffed him down the belly\n"
        output += b"Of a waiting jeep.\n"
        output += b"What business of mine is it\n"
        output += b"So long they don't take the yam\n"
        output += b"From my savouring mouth?\n\n"
        output += b"They came one night\n"
        output += b"Booted the whole house awake\n"
        output += b"And dragged Danladi out,\n"
        output += b"Then off to a lengthy absence.\n"
        output += b"What business of mine is it\n"
        output += b"So long they don't take the yam\n"
        output += b"From my savouring mouth?\n\n"
        output += b"Chinwe went to work one day\n"
        output += b"Only to find her job was gone:\n"
        output += b"No query, no warning, no probe -\n"
        output += b"Just one neat sack for a stainless record.\n"
        output += b"What business of mine is it\n"
        output += b"So long they don't take the yam\n"
        output += b"From my savouring mouth?\n\n"
        output += b"And then one evening\n"
        output += b"As I sat down to eat my yam\n"
        output += b"A knock on the door froze my hungry hand.\n"
        output += b"The jeep was waiting on my bewildered lawn\n"
        output += b"Waiting, waiting in its usual silence."
        return output
    
    def halWarning(self):
        '''
        Outputs HAL9000's warning from the end of 2010:Odyssey Two
        '''
        output = self.mFormatter.bold(self.mFormatter.centreText("ALL THESE WORLDS ARE YOURS-EXCEPT EUROPA"))
        output += b"\n"
        output += self.mFormatter.bold(self.mFormatter.centreText("ATTEMPT NO LANDING THERE"))
        return output
    
    @staticmethod
    def loadImageFile(fileName):
        fileName = 'Opening_bill_transparent.png'
        image = Image.open(fileName).convert('RGBA')
        width,height = image.size
        newwidth = 400
        scalefactor = width/newwidth
        newheight = height//scalefactor
        endwidth = math.ceil(newwidth/8)*8
        endheight = math.ceil(newheight/8)*8
        image = image.resize((endwidth,endheight),Image.ANTIALIAS)
        
        image_string = b'\x1d\x2a'
        image_string += bytes([endwidth//8,endheight//8])
        pixnum = 0
        pixval = 0
        for x in range(endwidth):
            for y in range(endheight):
                r,g,b,a = image.getpixel((x,y))
                if(r*g*b<100*100*100 and a>50):
                    pixval += 2**(7-pixnum)
                if(pixnum==7):
                    image_string += bytes([pixval])
                    pixnum = 0
                    pixval = 0
                else:
                    pixnum += 1
        return image_string + b'\x1d\x2f\x00'
    
    @staticmethod
    def loadImageSilhouetteFile(fileName):
        image = Image.open(fileName).convert('RGBA')
        width,height = image.size
        newwidth = 400
        scalefactor = width/newwidth
        newheight = height//scalefactor
        endwidth = math.ceil(newwidth/8)*8
        endheight = math.ceil(newheight/8)*8
        image = image.resize((endwidth,endheight),Image.ANTIALIAS)
        
        image_string = b'\x1d\x2a'
        image_string += bytes([endwidth//8,endheight//8])
        pixnum = 0
        pixval = 0
        for x in range(endwidth):
            for y in range(endheight):
                _,_,_,a = image.getpixel((x,y))
                if(a>10):
                    pixval += 2**(7-pixnum)
                if(pixnum==7):
                    image_string += bytes([pixval])
                    pixnum = 0
                    pixval = 0
                else:
                    pixnum += 1
        image_string += b'\x1d\x2f\x00'
        return image_string
Beispiel #33
0
 def __init__(self, **kwargs):
     Formatter.__init__(
         self,
         dataStart='<?xml version="1.0" encoding="UTF-8"?>\n' + '<Data>\n',
         dataEnd='</Data>\n')
Beispiel #34
0
 def __init__(self, groupByAttrs=['type'], *args, **kwargs):
     Formatter.__init__(self, *args, **kwargs)
     self.groupByAttrs = groupByAttrs