Exemple #1
0
def display_unread(sess):
    print(hues.huestr('    Unread Messages    ').white.bg_blue.bold.colorized)
    mess = sess.get_unread(sess.get_messages())
    if not mess:
        print(
            hues.huestr(
                '    Nothing new, bro   ').white.bg_black.bold.colorized)
    for msg in mess:
        display_message(msg)
    # print('\n')
    return "displayed"
Exemple #2
0
def display_message(sess, message, pr_name=True):
    usr = sess.get_username(message.from_id)

    if pr_name:
        print(hues.huestr(u' From {}:'.format(usr)).white.bold.colorized)
    with indent(3):
        puts(colored.white(message.body))
    with indent(5):
        for p in message.photos:
            puts(colored.white(p))
Exemple #3
0
def consoleMessage(logtype, message):
    if logtype is VirBotLogType.ERROR:
        hues.log(hues.huestr("[ERROR] " + message).magenta.bold.colorized)
    elif logtype is VirBotLogType.GENERIC:
        hues.log(hues.huestr(message).black.colorized)
    elif logtype is VirBotLogType.GENERICBOLD:
        hues.log(hues.huestr(message).black.bold.colorized)
    elif logtype is VirBotLogType.CHANNEL:
        hues.log(hues.huestr(message).blue.bold.colorized)
    elif logtype is VirBotLogType.NOTICE:
        hues.log(hues.huestr("[NOTICE] " + message).blue.bold.colorized)
    elif logtype is VirBotLogType.RECEIVED:
        hues.log(hues.huestr("[RECEIVED] " + message).green.colorized)
    elif logtype is VirBotLogType.SENT:
        hues.log(hues.huestr("[SENT] " + message).magenta.bold.colorized)
    elif logtype is VirBotLogType.SERVER:
        hues.log(hues.huestr("[SERVER] " + message).cyan.bold.colorized)
Exemple #4
0
    async def handle(self):
        global blockcount, lastblcokzmq

        msg = await self.zmqSubSocket.recv_multipart()
        topic = str(msg[0].decode("utf-8"))
        body = str(binascii.hexlify(msg[1]).decode("utf-8"))
        sequence = "Unknown"

        ts = time.strftime('%Y-%m-%d %H:%M:%S', time.gmtime(now()))

        if len(msg[-1]) == 4:
            msgSequence = struct.unpack('<I', msg[-1])[-1]
            sequence = str(msgSequence)

        if topic == 'rawtxlock':
            x = decoderawtx(body)
            txid = format_hash(double_sha256(binascii.unhexlify(body)))
            if txid not in q:
                q.append(txid)
                n = 0
                for y in x:
                    v = float(Decimal(x[y]['value']))
                    inputno = x[y].get('inputno')
                    outputno = x[y].get('outputno')
                    fromnumberuniq = len(list(set(x[y].get('fromall'))))
                    toaddruniq = len(x)

                    if n == 0:
                        fromaddr = x[y].get('fromall')[n]
                        print(
                            '{} {:34} {:3d} {:4d} {:34} {:16.8f} is {}'.format(
                                ts, fromaddr, inputno, outputno, y, v, txid))

                    else:
                        print('{:58d} {:4d} {:34} {:16.8f} is'.format(
                            inputno, outputno, y, v))

                    n = n + 1

        if topic == 'rawtx':
            txid = format_hash(double_sha256(binascii.unhexlify(body)))
            x = decoderawtx(body)

            #            print(json.dumps(x, sort_keys=True, indent=4, separators=(',', ': ')))

            if txid not in qq:
                qq.append(txid)
                n = 0
                for y in x:
                    v = float(Decimal(x[y]['value']))

                    inputno = x[y].get('inputno')
                    outputno = x[y].get('outputno')

                    fromnumberuniq = len(list(set(x[y].get('fromall'))))
                    toaddruniq = len(x)

                    if n == 0:
                        fromaddr = x[y].get('fromall')[n]
                        print('{} {:34} {:3d} {:4d} {:34} {:16.8f} {}'.format(
                            ts, fromaddr, inputno, outputno, y, v, txid))
                    else:
                        if inputno == outputno and inputno > 3:
                            fromaddr = x[y].get('fromall')[n]
                            if inputno != fromnumberuniq or outputno != toaddruniq:
                                print(
                                    '{:>54} {:3d} {:4d} {:34} {:16.8f} --> **** {:3d} {:4d}'
                                    .format(fromaddr, inputno, outputno, y, v,
                                            fromnumberuniq, toaddruniq))
                            else:
                                print(
                                    '{:>54} {:3d} {:4d} {:34} {:16.8f}'.format(
                                        fromaddr, inputno, outputno, y, v))

                        else:
                            print('{:58d} {:4d} {:34} {:16.8f}'.format(
                                inputno, outputno, y, v))

                    n = n + 1

        if topic == 'rawblock':
            x = decoderawblock(body)
            txno = len(x['txs'])
            binfo = rpcgetblock(x['hash'])
            binfo_time = binfo.get('time')
            curtime = now()

            block_no_colorized = hues.huestr(str(blockcount +
                                                 1)).green.bold.colorized
            block_time_colorized = hues.huestr(str(curtime -
                                                   lastblcokzmq)).red.colorized
            print('{} {} {} {:3d} {:3d} {:5}'.format(ts, block_no_colorized,
                                                     x['hash'], txno,
                                                     curtime - binfo_time,
                                                     block_time_colorized))

            blockcount = blockcount + 1
            lastblcokzmq = curtime

        asyncio.ensure_future(self.handle())
import hues

_default = hues.huestr('{}').white.colorized
_accent = hues.huestr('{}').green.colorized
_accent2 = hues.huestr('{}').yellow.colorized
_not_ok = hues.huestr('{}').red.colorized
_muted = hues.huestr('{}').black.colorized


def base(content):
    return '{}'.format(
        _default.format(content)
    )


def base_accent(content):
    return '{}'.format(
        _accent.format(content)
    )


def base_accent2(content):
    return '{}'.format(
        _accent2.format(content)
    )


def base_not_ok(content):
    return '{}'.format(
        _not_ok.format(content)
    )
Exemple #6
0
def white(*msg, sep=' ', end='\n'):
    print(hues.huestr(" ".join([str(i) for i in msg])).white.colorized,
          sep=sep,
          end=end)
Exemple #7
0
def cyan(*msg, sep=' ', end='\n'):
    print(hues.huestr(" ".join([str(i) for i in msg])).cyan.colorized,
          sep=sep,
          end=end)
Exemple #8
0
def magenta(*msg, sep=' ', end='\n'):
    print(hues.huestr(" ".join([str(i) for i in msg])).magenta.colorized,
          sep=sep,
          end=end)
Exemple #9
0
def yellow(*msg, sep=' ', end='\n'):
    print(hues.huestr(" ".join([str(i) for i in msg])).yellow.colorized,
          sep=sep,
          end=end)
Exemple #10
0
def black(*msg, sep=' ', end='\n'):
    print(hues.huestr(" ".join([str(i) for i in msg])).black.colorized,
          sep=sep,
          end=end)
Exemple #11
0
def display_all(sess):
    print(hues.huestr('    All Messages    ').white.bg_blue.bold.colorized)
    mess = sess.get_messages()
    for i in range(len(mess)):
        display_message(mess[i], not (mess[i].from_id == mess[i - 1].from_id))
    return "displayed"
Exemple #12
0
def col(a: Any, c: Callable[[huestr], huestr]) -> str:
    return c(huestr(str(a))).colorized
Exemple #13
0
def test_usage():
    assert huestr(
        'unicorn').red.bg_black.colorized == '\033[31;40municorn\033[0m'