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 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?')
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 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?')
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))
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 == ('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) 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)) 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)) elif args[0].lower() in 'reddit': log.debug('reddit requested') uvm.currFocusView.updateHistory(FrameFactory(RedditIndexFrame), [uvm]) setattr(uvm.currFocusView, 'frame', RedditIndexFrame(uvm)) elif args[0].lower() in ('hn', 'hackernews'): log.debug('HN requested') uvm.currFocusView.updateHistory( FrameFactory(HackerNewsIndexFrame), [uvm]) setattr(uvm.currFocusView, 'frame', HackerNewsIndexFrame(uvm)) elif args[0].lower() in 'watcher': log.debug('wather requested') setattr(uvm.currFocusView, 'frame', WatcherFrame(uvm)) 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.keys(): 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 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): cmd = cmd.split() if cmd[0] in ('qa', 'quitall'): log.debug('Executing quit command') if uvm.cfg.update_file(): log.debug('updated config') sys.exit() elif cmd[0] == ('add'): if len(cmd) >= 3: log.debug(f'Executing add command with args: {cmd[1:]}') if cmd[1] == '4chan': for board in cmd[2:]: uvm.cfg.add_topic(SITE.FCHAN, board) setattr(uvm.currFocusView, 'frame', fIndex.IndexFrame(uvm)) elif cmd[1] == 'reddit': for subreddit in cmd[2:]: uvm.cfg.add_topic(SITE.REDDIT, subreddit) setattr(uvm.currFocusView, 'frame', RedditIndexFrame(uvm)) elif cmd[0] == ('set'): # :set key value if len(cmd) == 3: uvm.cfg.set(cmd[1], cmd[2]) # :set SITE key value elif len(cmd) == 4: uvm.cfg.deep_set(cmd[1], cmd[2], cmd[3]) elif cmd[0] == ('source'): pass try: with open(cmd[1], 'r') as rcFile: for command in rcFile: command = command.strip() if command[0] != '#': systemCommands(command, uvm) except: log.debug(f'ERROR: Unable to source {cmd[1]}') elif cmd[0] in ('h', 'history'): if len(cmd) is 2: h = uvm.history[int(cmd[1])] setattr(uvm.currFocusView, 'frame', h[1](h[2])) 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[0] in ('s', 'search'): h = uvm.history[0] newArgs = h[2].copy() if len(cmd) is 2: newArgs.append(cmd[1]) setattr(uvm.currFocusView, 'frame', h[1](newArgs)) elif cmd[0] == ('view'): log.debug('executing site command') log.debug(cmd) if len(cmd) == 2: if cmd[1] in 'history': setattr(uvm.currFocusView, 'frame', HistoryFrame(uvm)) elif cmd[1] == '4chan': log.debug('4chan requested') uvm.currFocusView.updateHistory( FrameFactory(fIndex.IndexFrame), [uvm]) setattr(uvm.currFocusView, 'frame', fIndex.IndexFrame(uvm)) elif cmd[1] == 'lainchan' or cmd[1] == 'lchan': log.debug('lainchan requested') uvm.currFocusView.updateHistory( FrameFactory(lIndex.IndexFrame), [uvm]) setattr(uvm.currFocusView, 'frame', lIndex.IndexFrame(uvm)) elif cmd[1] in ['reddit', 'Reddit']: log.debug('reddit requested') uvm.currFocusView.updateHistory(FrameFactory(RedditIndexFrame), [uvm]) setattr(uvm.currFocusView, 'frame', RedditIndexFrame(uvm)) elif cmd[1].lower() in ['hn', 'hackernews']: log.debug('HN requested') uvm.currFocusView.updateHistory( FrameFactory(HackerNewsIndexFrame), [uvm]) setattr(uvm.currFocusView, 'frame', HackerNewsIndexFrame(uvm)) elif cmd[0] == ('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[0] == ('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[0] == ('unsplit'): if len(uvm.splitTuple.widgets) > 1: uvm.splitTuple.widgets.pop( ) # doesn't work for mix of split and vsplit