def thread(uvm, boardString, threadNumber):
    log.debug('Executing thread command')
    if uvm.currFocusView.site is SITE.FCHAN:
        uvm.currFocusView.updateHistory(FrameFactory(fchanThread.ThreadFrame), [boardString, threadNumber, uvm])
        setattr(uvm.currFocusView, 'frame', fchanThread.ThreadFrame(boardString, threadNumber, uvm))
    elif uvm.currFocusView.site is SITE.LCHAN:
        uvm.currFocusView.updateHistory(FrameFactory(lchanThread.ThreadFrame), [boardString, threadNumber, uvm])
        setattr(uvm.currFocusView, 'frame', lchanThread.ThreadFrame(boardString, threadNumber, uvm))
def board(uvm, boardString):
    log.debug('Executing board command')
    try:
        if uvm.currFocusView.site == SITE.FCHAN:
            setattr(uvm.currFocusView, 'frame', fchanBoard.BoardFrame(boardString, uvm))
            uvm.currFocusView.updateHistory(FrameFactory(fchanBoard.BoardFrame), [boardString, uvm])
        elif uvm.currFocusView.site is SITE.LCHAN:
            setattr(uvm.currFocusView, 'frame', lchanBoard.BoardFrame(boardString, uvm))
            uvm.currFocusView.updateHistory(FrameFactory(lchanBoard.BoardFrame), [boardString, uvm])
    except:
        uvm.currFocusView.frame.headerString = f'Error connecting to board {boardString}, does it exist?'
        log.debug(f'Error connecting to board {boardString}, does it exist?')
def story(uvm, story, page):
    try:
        setattr(uvm.currFocusView, 'frame', StoryFrame(story, page, uvm))
        uvm.currFocusView.updateHistory(FrameFactory(StoryFrame), [story, page, uvm])
    except:
        uvm.currFocusView.frame.headerString = f'Error connecting to story {story}, does it exist?'
        log.debug(f'Error connecting to story {story}, does it exist?')
Beispiel #4
0
def subreddit(uvm, subString, token):
    log.debug('Executing subreddit command')
    subString = '/r/' + subString if not subString.startswith('/r/') else subString
    try:
        setattr(uvm.currFocusView, 'frame', SubredditFrame(subString, token, uvm))
        uvm.currFocusView.updateHistory(FrameFactory(SubredditFrame), [subString, token, uvm])
    except:
        uvm.currFocusView.frame.headerString = f'Error connecting to subreddit {subString}, does it exist?'
        log.debug(f'Error connecting to subreddit {subString}, does it exist?')
Beispiel #5
0
def post(uvm, subString, postNumber):
    log.debug('Executing post command')
    uvm.currFocusView.updateHistory(FrameFactory(RedditThreadFrame), [subString, postNumber, uvm])
    setattr(uvm.currFocusView, 'frame', RedditThreadFrame(subString, postNumber, uvm))
def systemCommands(cmd, uvm):
    log.debug(cmd)
    cmd, *args = cmd.split()

    if cmd in ('q', 'qa', 'quitall'):
        log.debug('Executing quit command')
        if uvm.cfg.update_file():
            log.debug('updated config')
        sys.exit()

    elif cmd == ('add'):
        if len(args) >= 2:
            log.debug(f'Executing add command with args: {args[:]}')
            if args[0] == '4chan':
                for board in args[1:]:
                    uvm.cfg.add_topic(SITE.FCHAN, board)
                    setattr(uvm.currFocusView, 'frame', fIndex.IndexFrame(uvm))
            elif args[0] == 'reddit':
                for subreddit in args[1:]:
                    uvm.cfg.add_topic(SITE.REDDIT, subreddit)
                    setattr(uvm.currFocusView, 'frame', RedditIndexFrame(uvm))

    elif cmd == ('remove'):
        if len(args) >= 2:
            log.debug(f'Executing remove command with args: {args[:]}')
            if args[0] == '4chan':
                for board in args[1:]:
                    uvm.cfg.remove_topic(SITE.FCHAN, board)
                    setattr(uvm.currFocusView, 'frame', fIndex.IndexFrame(uvm))
            elif args[0] == 'reddit':
                for subreddit in args[1:]:
                    uvm.cfg.remove_topic(SITE.REDDIT, subreddit)
                    setattr(uvm.currFocusView, 'frame', RedditIndexFrame(uvm))

    elif cmd == ('set'):
        # :set key value
        log.debug('set called')
        if len(args) == 2:
            uvm.cfg.set(args[0], args[1])
        # :set SITE key value
        elif len(args) == 3:
            uvm.cfg.deep_set(args[0], args[1], args[2])

    elif cmd == ('source') and len(args) == 1:
        try:
            if (os.path.exists(args[0])):
                with open(args[0], 'r') as rcFile:
                    for command in rcFile:
                        command = command.strip()
                        if command[0] != '#':
                            systemCommands(command, uvm)
        except:
            log.debug(f'ERROR: Unable to source {args[0]}')

    elif cmd in ('h', 'history'):
        if len(args) == 1:
            try:
                val = int(args[0])
                h = uvm.history[val]
                setattr(uvm.currFocusView, 'frame', h[1](h[2]))
            except ValueError:
                log.error('tried feeding string, instead of int to history')

        else:
            for h in uvm.history[1:]:
                if h[0] is uvm.currFocusView.id:
                    log.debug('Executing history command')
                    uvm.history.insert(0, h)
                    setattr(uvm.currFocusView, 'frame', h[1](h[2]))
                    break

    elif cmd in ('s', 'search'):
        h = uvm.history[0]
        newArgs = h[2].copy()
        if len(args) == 1:
            newArgs.append(args[0])

        setattr(uvm.currFocusView, 'frame', h[1](newArgs))

    elif cmd == ('view'):
        log.debug('executing view command')
        log.debug(cmd)

        site = None

        if len(args) == 1:
            if args[0].lower() in ('h', 'history'):
                log.debug('history requested')
                setattr(uvm.currFocusView, 'frame', HistoryFrame(uvm))
            elif args[0].lower() in '4chan':
                log.debug('4chan requested')
                uvm.currFocusView.updateHistory(
                    FrameFactory(fIndex.IndexFrame), [uvm])
                setattr(uvm.currFocusView, 'frame', fIndex.IndexFrame(uvm))

                site = SITE.FCHAN
            elif args[0].lower() in ('lchan', 'lainchan'):
                log.debug('lainchan requested')
                uvm.currFocusView.updateHistory(
                    FrameFactory(lIndex.IndexFrame), [uvm])
                setattr(uvm.currFocusView, 'frame', lIndex.IndexFrame(uvm))

                site = SITE.LCHAN
            elif args[0].lower() in 'reddit':
                log.debug('reddit requested')
                uvm.currFocusView.updateHistory(FrameFactory(RedditIndexFrame),
                                                [uvm])
                setattr(uvm.currFocusView, 'frame', RedditIndexFrame(uvm))

                site = SITE.REDDIT
            elif args[0].lower() in ('hn', 'hackernews'):
                log.debug('HN requested')
                uvm.currFocusView.updateHistory(
                    FrameFactory(HackerNewsIndexFrame), [uvm])
                setattr(uvm.currFocusView, 'frame', HackerNewsIndexFrame(uvm))

                site = SITE.HACKERNEWS
            elif args[0].lower() in ('ls', 'lobsters'):
                log.debug('lobster requested')
                uvm.currFocusView.updateHistory(
                    FrameFactory(LobsterIndexFrame), [uvm])
                setattr(uvm.currFocusView, 'frame', LobsterIndexFrame(uvm))

                site = SITE.LOBSTERS
            elif args[0].lower() in 'watcher':
                log.debug('wather requested')
                setattr(uvm.currFocusView, 'frame', WatcherFrame(uvm))

        uvm.currFocusView.site = site

    elif cmd == ('split'):
        if type(uvm.splitTuple) is Row:
            uvm.splitTuple.widgets.append(View(uvm))
        else:
            t = uvm.splitTuple
            uvm.splitTuple = Row()
            uvm.splitTuple.widgets.append(t)
            uvm.splitTuple.widgets.append(View(uvm))

    elif cmd == ('vsplit'):
        if type(uvm.splitTuple) is Column:
            uvm.splitTuple.widgets.append(View(uvm))
        t = uvm.splitTuple
        uvm.splitTuple = Column()
        uvm.splitTuple.widgets.append(t)
        uvm.splitTuple.widgets.append(View(uvm))

    elif cmd == ('unsplit'):
        if len(uvm.splitTuple.widgets) > 1:
            uvm.splitTuple.widgets.pop(
            )  # doesn't work for mix of split and vsplit

    elif cmd in ('w', 'watch'):
        if type(uvm.currFocusView.frame) == ThreadFrame:
            wT = {}
            url = uvm.currFocusView.frame.url
            if url not in uvm.watched:
                wT['board'] = uvm.currFocusView.frame.boardString
                wT['op'] = uvm.currFocusView.frame.comments[0].content
                wT['numReplies'] = len(uvm.currFocusView.frame.comments)
                uvm.watched[url] = wT
def hnpost(uvm, story, postID):
    log.debug('Executing HN post command')
    uvm.currFocusView.updateHistory(FrameFactory(HackerNewsThreadFrame), [story, postID, uvm])
    setattr(uvm.currFocusView, 'frame', HackerNewsThreadFrame(story, postID, uvm))