Esempio n. 1
0
File: ol.py Progetto: donfanning/x84
def saysomething(dumb=True):
    """
    Prompt user to post oneliner, also prompt user to post
    to bbs-scene.org if configured, returning background Thread.
    """
    import time
    from x84.bbs import getsession, getterminal, echo, LineEditor, ini
    session, term = getsession(), getterminal()
    prompt_say = u'SAY WhAt ?! '
    # heard_msg = u'YOUR MESSAGE hAS bEEN VOiCEd.'

    yloc = term.height - 3
    xloc = max(0, ((term.width / 2) - (MAX_INPUT / 2)))
    if dumb:
        echo(u'\r\n\r\n' + term.bold_blue(prompt_say))
    else:
        echo(term.move(yloc, xloc) or u'\r\n\r\n')
        echo(term.bold_blue(prompt_say))
    ole = LineEditor(MAX_INPUT)
    ole.highlight = term.green_reverse
    oneliner = ole.read()
    if oneliner is None or 0 == len(oneliner.strip()):
        if not dumb:
            # clear input line,
            echo(term.normal + term.move(yloc, 0) + term.clear_eol)
        return None

    session.user['lastliner'] = time.time()
    # post local-onlyw hen bbs-scene.org is not configured
    if not ini.CFG.has_section('bbs-scene'):
        add_oneline(oneliner.strip())
        return None
    return post_bbs_scene(oneliner, dumb)
Esempio n. 2
0
def saysomething(dumb=True):
    """
    Prompt user to post oneliner, also prompt user to post
    to bbs-scene.org if configured, returning background Thread.
    """
    import time
    from x84.bbs import getsession, getterminal, echo, LineEditor, ini
    session, term = getsession(), getterminal()
    prompt_say = u'SAY WhAt ?! '
    # heard_msg = u'YOUR MESSAGE hAS bEEN VOiCEd.'

    yloc = term.height - 3
    xloc = max(0, ((term.width / 2) - (MAX_INPUT / 2)))
    if dumb:
        echo(u'\r\n\r\n' + term.bold_blue(prompt_say))
    else:
        echo(term.move(yloc, xloc) or u'\r\n\r\n')
        echo(term.bold_blue(prompt_say))
    ole = LineEditor(MAX_INPUT)
    ole.highlight = term.green_reverse
    oneliner = ole.read()
    if oneliner is None or 0 == len(oneliner.strip()):
        if not dumb:
            # clear input line,
            echo(term.normal + term.move(yloc, 0) + term.clear_eol)
        return None

    session.user['lastliner'] = time.time()
    # post local-onlyw hen bbs-scene.org is not configured
    if not ini.CFG.has_section('bbs-scene'):
        add_oneline(oneliner.strip())
        return None
    return post_bbs_scene(oneliner, dumb)
Esempio n. 3
0
def prompt_recipient(msg):
    """ Prompt for recipient of message. """
    # pylint: disable=R0914
    #         Too many local variables
    from x84.bbs import getterminal, LineEditor, echo, ini, list_users
    from x84.bbs import Selector
    import difflib
    term = getterminal()
    echo(u"ENtER %s, OR '%s' tO AddRESS All. %s to exit" % (
        term.bold_yellow(u'hANdlE'),
        term.bold_yellow(u'None'),
        term.bold_yellow_underline('Escape'),))
    echo(u'\r\n\r\n')
    max_user = ini.CFG.getint('nua', 'max_user')
    lne = LineEditor(max_user, msg.recipient or u'None')
    lne.highlight = term.yellow_reverse
    echo(term.clear_eol + u'   RECiPiENt: ')
    recipient = lne.read()
    if recipient is None or lne.quit:
        return False
    userlist = list_users()
    if recipient in userlist:
        msg.recipient = recipient
        return True
    elif len(recipient) != 0 and recipient != 'None':
        for match in difflib.get_close_matches(recipient, userlist):
            blurb = u'did YOU MEAN: %s ?' % (match,)
            inp = Selector(yloc=term.height - 1,
                           xloc=term.width - 22,
                           width=20, left=u'YES', right=u'NO')
            echo(u''.join((
                u'\r\n',
                term.move(inp.yloc, inp.xloc - len(blurb)),
                term.clear_eol,
                term.bold_yellow(blurb))))
            selection = inp.read()
            echo(term.move(inp.yloc, 0) + term.clear_eol)
            if selection == u'YES':
                msg.recipient = match
                return True
            if selection is None or inp.quit:
                return False
    else:
        blurb = u' NO RECiPiENT; POSt tO PUbliC? '
        inp = Selector(yloc=term.height - 1,
                       xloc=term.width - 22,
                       width=20, left=u'YES', right=u'NO')
        echo(u''.join((
            u'\r\n',
            term.move(inp.yloc, inp.xloc - len(blurb)),
            term.clear_eol,
            term.bold_yellow(blurb))))
        selection = inp.read()
        echo(term.move(inp.yloc, 0) + term.clear_eol)
        if selection == u'YES':
            msg.recipient = None
            return True
Esempio n. 4
0
def prompt_recipient(msg):
    """ Prompt for recipient of message. """
    # pylint: disable=R0914
    #         Too many local variables
    from x84.bbs import getterminal, LineEditor, echo, ini, list_users
    from x84.bbs import Selector
    import difflib
    term = getterminal()
    echo(u"ENtER %s, OR '%s' tO AddRESS All. %s to exit" % (
        term.bold_yellow(u'hANdlE'),
        term.bold_yellow(u'None'),
        term.bold_yellow_underline('Escape'),
    ))
    echo(u'\r\n\r\n')
    max_user = ini.CFG.getint('nua', 'max_user')
    lne = LineEditor(max_user, msg.recipient or u'None')
    lne.highlight = term.yellow_reverse
    echo(term.clear_eol + u'   RECiPiENt: ')
    recipient = lne.read()
    if recipient is None or lne.quit:
        return False
    userlist = list_users()
    if recipient in userlist:
        msg.recipient = recipient
        return True
    elif len(recipient) != 0 and recipient != 'None':
        for match in difflib.get_close_matches(recipient, userlist):
            blurb = u'did YOU MEAN: %s ?' % (match, )
            inp = Selector(yloc=term.height - 1,
                           xloc=term.width - 22,
                           width=20,
                           left=u'YES',
                           right=u'NO')
            echo(u''.join((u'\r\n', term.move(inp.yloc, inp.xloc - len(blurb)),
                           term.clear_eol, term.bold_yellow(blurb))))
            selection = inp.read()
            echo(term.move(inp.yloc, 0) + term.clear_eol)
            if selection == u'YES':
                msg.recipient = match
                return True
            if selection is None or inp.quit:
                return False
    else:
        blurb = u' NO RECiPiENT; POSt tO PUbliC? '
        inp = Selector(yloc=term.height - 1,
                       xloc=term.width - 22,
                       width=20,
                       left=u'YES',
                       right=u'NO')
        echo(u''.join((u'\r\n', term.move(inp.yloc, inp.xloc - len(blurb)),
                       term.clear_eol, term.bold_yellow(blurb))))
        selection = inp.read()
        echo(term.move(inp.yloc, 0) + term.clear_eol)
        if selection == u'YES':
            msg.recipient = None
            return True
Esempio n. 5
0
def prompt_subject(msg):
    """ Prompt for subject of message. """
    from x84.bbs import getterminal, LineEditor, echo, ini
    term = getterminal()
    max_subject = int(ini.CFG.getint('msg', 'max_subject'))
    lne = LineEditor(max_subject, msg.subject)
    lne.highlight = term.yellow_reverse
    echo(u'\r\n\r\n     SUBjECt: ')
    subject = lne.read()
    if subject is None or 0 == len(subject):
        return False
    msg.subject = subject
    return True
Esempio n. 6
0
def prompt_subject(msg):
    """ Prompt for subject of message. """
    from x84.bbs import getterminal, LineEditor, echo, ini
    term = getterminal()
    max_subject = int(ini.CFG.getint('msg', 'max_subject'))
    lne = LineEditor(max_subject, msg.subject)
    lne.highlight = term.yellow_reverse
    echo(u'\r\n\r\n     SUBjECt: ')
    subject = lne.read()
    if subject is None or 0 == len(subject):
        return False
    msg.subject = subject
    return True
Esempio n. 7
0
def add_bbs():
    """
    Prompt user for details and to add bbs to list.
    """
    # pylint: disable=R0914,R0915
    #        Too many local variables
    #        Too many statements
    from x84.bbs import getsession, getterminal, echo, LineEditor, DBProxy, ini
    from x84.bbs import getch
    session, term = getsession(), getterminal()
    echo(term.move(term.height, 0))
    empty_msg = u'\r\n\r\nVAlUE iS NOt OPtiONAl.'
    cancel_msg = u"\r\n\r\nENtER 'quit' tO CANCEl."
    saved_msg = u'\r\n\r\nSAVED AS RECORd id %s.'
    logger = logging.getLogger()
    bbs = dict()
    for bkey in DB_KEYS:
        if bkey == 'timestamp':
            value = time.strftime('%Y-%m-%d %H:%M:%S')
            bbs[bkey] = value
            continue
        elif bkey == 'ansi':
            # todo: upload ansi with xmodem .. lol !?
            value = u''
            continue
        splice = len(bkey) - (len(bkey) / 3)
        prefix = (u'\r\n\r\n  '
                  + (term.bold_red('* ') if bkey in XML_REQNOTNULL else u'')
                  + term.bold_blue(bkey[:splice])
                  + term.bold_black(bkey[splice:])
                  + term.bold_white(': '))
        led = LineEditor(40)  # !?
        led.highlight = term.green_reverse
        while True:
            echo(prefix)
            value = led.read()
            if value is not None and (value.strip().lower() == 'quit'):
                return
            if bkey in XML_REQNOTNULL:
                if value is None or 0 == len(value.strip()):
                    echo(term.bold_red(empty_msg))
                    echo(u'\r\n' + cancel_msg)
                    continue
            if bkey in ('port') and value is None or 0 == len(value):
                value = u'23'
            # TODO: telnet connect test, of course !
            bbs[bkey] = value
            break
    key = max([int(_key) for _key in DBProxy('bbslist').keys()] or [0]) + 1
    DBProxy('bbslist')[key] = bbs
    DBProxy('bbslist', 'comments')[key] = list()
    DBProxy('bbslist', 'ratings')[key] = list()
    echo('\r\n\r\n' + saved_msg % (key) + '\r\n')
    session.send_event('global', ('bbslist_update', None,))
    session.buffer_event('bbslist_update')
    if ini.CFG.has_section('bbs-scene'):
        # post to bbs-scene.org
        posturl = 'http://bbs-scene.org/api/bbslist.xml'
        usernm = ini.CFG.get('bbs-scene', 'user')
        passwd = ini.CFG.get('bbs-scene', 'pass')
        data = {'name': bbs['bbsname'],
                'sysop': bbs['sysop'],
                'software': bbs['software'],
                'address': bbs['address'],
                'port': bbs['port'],
                'location': bbs['location'],
                'notes': bbs['notes'],
                }
        req = requests.post(posturl, auth=(usernm, passwd), data=data)
        if req.status_code != 200:
            echo(u'\r\n\r\nrequest failed,\r\n')
            echo(u'%r' % (req.content,))
            echo(u'\r\n\r\n(code : %s).\r\n' % (req.status_code,))
            echo(u'\r\nPress any key ..')
            logger.warn('bbs post failed: %s' % (posturl,))
            getch()
            return
        logger.info('bbs-scene.org api (%d): %r/%r',
                    req.status_code, session.user.handle, bbs)
        # spawn a thread to re-fetch bbs entries,
        thread = FetchUpdates()
        thread.start()
        wait_for(thread)
        return chk_thread(thread)
Esempio n. 8
0
def add_bbs():
    """
    Prompt user for details and to add bbs to list.
    """
    # pylint: disable=R0914,R0915
    #        Too many local variables
    #        Too many statements
    from x84.bbs import getsession, getterminal, echo, LineEditor, DBProxy, ini
    from x84.bbs import getch
    session, term = getsession(), getterminal()
    echo(term.move(term.height, 0))
    empty_msg = u'\r\n\r\nVAlUE iS NOt OPtiONAl.'
    cancel_msg = u"\r\n\r\nENtER 'quit' tO CANCEl."
    saved_msg = u'\r\n\r\nSAVED AS RECORd id %s.'
    logger = logging.getLogger()
    bbs = dict()
    for bkey in DB_KEYS:
        if bkey == 'timestamp':
            value = time.strftime('%Y-%m-%d %H:%M:%S')
            bbs[bkey] = value
            continue
        elif bkey == 'ansi':
            # todo: upload ansi with xmodem .. lol !?
            value = u''
            continue
        splice = len(bkey) - (len(bkey) / 3)
        prefix = (u'\r\n\r\n  ' +
                  (term.bold_red('* ') if bkey in XML_REQNOTNULL else u'') +
                  term.bold_blue(bkey[:splice]) +
                  term.bold_black(bkey[splice:]) + term.bold_white(': '))
        led = LineEditor(40)  # !?
        led.highlight = term.green_reverse
        while True:
            echo(prefix)
            value = led.read()
            if value is not None and (value.strip().lower() == 'quit'):
                return
            if bkey in XML_REQNOTNULL:
                if value is None or 0 == len(value.strip()):
                    echo(term.bold_red(empty_msg))
                    echo(u'\r\n' + cancel_msg)
                    continue
            if bkey in ('port') and value is None or 0 == len(value):
                value = u'23'
            # TODO: telnet connect test, of course !
            bbs[bkey] = value
            break
    key = max([int(_key) for _key in DBProxy('bbslist').keys()] or [0]) + 1
    DBProxy('bbslist')[key] = bbs
    DBProxy('bbslist', 'comments')[key] = list()
    DBProxy('bbslist', 'ratings')[key] = list()
    echo('\r\n\r\n' + saved_msg % (key) + '\r\n')
    session.send_event('global', (
        'bbslist_update',
        None,
    ))
    session.buffer_event('bbslist_update')
    if ini.CFG.has_section('bbs-scene'):
        # post to bbs-scene.org
        posturl = 'http://bbs-scene.org/api/bbslist.xml'
        usernm = ini.CFG.get('bbs-scene', 'user')
        passwd = ini.CFG.get('bbs-scene', 'pass')
        data = {
            'name': bbs['bbsname'],
            'sysop': bbs['sysop'],
            'software': bbs['software'],
            'address': bbs['address'],
            'port': bbs['port'],
            'location': bbs['location'],
            'notes': bbs['notes'],
        }
        req = requests.post(posturl, auth=(usernm, passwd), data=data)
        if req.status_code != 200:
            echo(u'\r\n\r\nrequest failed,\r\n')
            echo(u'%r' % (req.content, ))
            echo(u'\r\n\r\n(code : %s).\r\n' % (req.status_code, ))
            echo(u'\r\nPress any key ..')
            logger.warn('bbs post failed: %s' % (posturl, ))
            getch()
            return
        logger.info('bbs-scene.org api (%d): %r/%r', req.status_code,
                    session.user.handle, bbs)
        # spawn a thread to re-fetch bbs entries,
        thread = FetchUpdates()
        thread.start()
        wait_for(thread)
        return chk_thread(thread)