def conferences(): li = read_conferences_data() # debug(li) # return for index, e in enumerate(li[1:], start=1): print("({pos}) {id:20}[{url}]".format(pos=index, id=e[0], url=e[1])) print("[q] <<") while True: try: inp = raw_input("~~> ").strip() except (KeyboardInterrupt, EOFError): print() return None if len(inp) == 0: continue elif inp == "q": return elif inp == "qq": common.my_exit(0) try: index = int(inp) if index < 1: raise IndexError common.open_url(li[index][1]) return except IndexError: print("out of range...") except ValueError: print("Wat?")
def prepare_lc_opener(): opener = prepare_opener(config['lc_url']) # Request used to initialize cookie. open_url(config['lc_url'], opener) return opener
def cmd_go1(keyword, site=None): if not site: q = keyword else: q = "site:{site} {kw}".format(site=site, kw=keyword) # url = first_google_hit(q) open_url(url)
def show(): text = clipboard.read_primary() if not text: print("Warning! The primary clipboard is empty.") return # context = {"link": text} fname = "/tmp/{id}.html".format(id=simpleflake.simpleflake(hexa=True)) with open(fname, "w") as f: html = render_template("link.html", context) f.write(html) common.open_url(fname)
def perform_action(key): global last_key last_key = key # o = hdict[key] action = o["action"] verb = action[0] if verb == 'cat': cat(action[1], o) elif verb == 'open_url': open_url(action[1], o["doc"]) else: print("Error: unknown action: {a}.".format(a=verb)) my_exit(1)
def perform_action(key, search_term=""): global last_key last_key = key # o = hdict[key] action = o["action"] verb = action[0] if verb == 'cat': fname = fname_to_abs(action[1]) colored_line_numbers.cat(fname, o, search_term) process_extras(fname, o) elif verb == 'open_url': open_url(action[1], o["doc"]) else: print("Error: unknown action: {a}.".format(a=verb)) my_exit(1)
def net_location(self): if not self._net_location: # Get base url from redirect. self._net_location = get_url_net_location( # Get redirect url from site response open_url(self.data["url"], self.opener).geturl() ) return self._net_location
def show_urls(key): o = hdict[key] # action = o["action"] verb = action[0] if verb == 'cat': fname = "data/" + action[1] else: return # OK, we have the fname li = extract_urls(fname) for index, url in enumerate(li, start=1): print("[{i}] {url}".format(i=index, url=url)) print("[q] <<") while True: try: inp = raw_input("~~> ").strip() except (KeyboardInterrupt, EOFError): print() return None if len(inp) == 0: continue if inp == 'q': return None if inp == 'qq': my_exit(0) try: index = int(inp) - 1 if index < 0: raise IndexError open_url(li[index]) return except IndexError: print("out of range...") except ValueError: print('Wat?')
def prepare_gr_opener(): gr_url = 'http://www.goodreads.com/' opener = prepare_opener(gr_url) # Request used to initialize cookie. open_url(gr_url, opener) return opener
def open_subreddit(sr): url = "http://www.reddit.com/r/{sr}".format(sr=sr) open_url(url)
def open_pep(num): url = 'http://www.python.org/dev/peps' if num: url = "{url}/pep-{num}".format(url=url, num=num.zfill(4)) # open_url(url)
def cmd_youtube(keyword): open_url("https://www.youtube.com/results?search_query=" + keyword)
def cmd_google(keyword): open_url("https://www.google.com/search?q=" + keyword)
def menu(): print("[{0:.3f}s]".format(time.time() - start_time), end='\n') # while True: try: #inp = raw_input(bold('pc> ')).strip() inp = raw_input(bold('{prompt}> '.format(prompt=os.getcwd()))).strip() except (KeyboardInterrupt, EOFError): print() my_exit(0) if len(inp) == 0: continue if inp in ('h', 'help()'): info() elif inp in ('q', 'qq', ':q', ':x', 'quit()', 'exit()'): my_exit(0) elif inp in ('c', 'clear()'): os.system('clear') print_header() elif inp in ('light()', 'dark()'): if inp == 'light()': cfg.g.BACKGROUND = cfg.LIGHT else: cfg.g.BACKGROUND = cfg.DARK elif inp in ('t', 'tags()', 'all()', 'd'): SearchHits.show_tag_list(tag2keys.keys()) elif inp == 'p': os.system("python") elif inp == 'p3': os.system("python3") elif inp == 'bpy': os.system("bpython") elif inp == 'last()': print(last_key) elif inp == '!!': if last_key: perform_action(last_key) elif inp.startswith('!'): cmd = inp[1:] os.system(cmd) elif inp == 'edit()': if last_key: edit(last_key) elif inp == 'gedit()': if last_key: gedit(last_key) elif inp == 'less()': if last_key: less(last_key) elif inp in ('urls()', 'links()'): if last_key: show_urls(last_key) elif inp in ('cb()', 'tocb()'): if last_key: to_clipboards(last_key) elif inp == 'path()': if last_key: path_to_clipboards(last_key) elif inp == "doc()": if last_key: show_doc(last_key) elif inp == 'json.reload()': read_json() elif inp in ('json.view()', 'json.edit()'): if last_key: view_edit_json(last_key) read_json() elif inp in ("json.edit(this)", "jet()"): if last_key: edit_entry(last_key) elif inp == 'reddit()': reddit.reddit() elif inp == 'conferences()': conferences.conferences() elif inp == 'mute()': apps.radio.radio(None, stop=True) elif inp == 'myip()': my_ip.show_my_ip() elif inp in ('v', 'version()'): version() elif inp == 'commands()': show_commands() elif inp == 'add()': add_item() read_json() elif inp == 'hits()': SearchHits.show_tag_list() elif inp.startswith("pymotw:"): site = "pymotw.com" cmd_go1(inp[inp.find(':')+1:], site=site) elif inp.startswith("go:"): cmd_google(inp[inp.find(':')+1:]) elif inp.startswith("go1:"): cmd_go1(inp[inp.find(':')+1:]) elif inp.startswith("imdb:"): site = "imdb.com" cmd_go1(inp[inp.find(':')+1:], site=site) elif inp.startswith("amazon:"): site = "amazon.com" cmd_go1(inp[inp.find(':')+1:], site=site) elif inp.startswith("youtube:"): cmd_youtube(inp[inp.find(':')+1:]) elif inp.startswith("wp:"): site = "wikipedia.org" cmd_go1(inp[inp.find(':')+1:], site=site) elif inp.startswith("lib:") or inp.startswith("lib2:"): site = "docs.python.org/2/library/" cmd_go1(inp[inp.find(':')+1:], site=site) elif inp.startswith("lib3:"): site = "docs.python.org/3/library/" cmd_go1(inp[inp.find(':')+1:], site=site) elif inp.startswith("golib:"): site = "http://golang.org/pkg/" lib = inp[inp.find(':')+1:] open_url(urljoin(site, lib)) elif inp.startswith("shorten:"): urlshortener.shorten_url(inp[inp.find(':')+1:]) elif inp.startswith("def:"): cmd_def(inp[inp.find(':')+1:]) elif inp.startswith("pep:"): open_pep(inp[inp.find(':')+1:]) elif inp == 'pep()': open_pep(None) elif inp == 'show()': show.show() elif inp == 'numbers()': toggle_line_numbers() elif re.search(r"^l([\d,-]+)\.(sh|py|py2|py3|cb|cb\(>\))$", inp): fname = key_to_file(last_key) selected_lines.process_selected_lines(inp, fname) elif inp == 'cd' or inp.startswith('cd '): change_dir(inp) elif inp == 'pwd()': print(os.getcwd()) elif inp == 'userpass()': username_password() elif inp == 'apps()': apps.menu.main() elif inp == 'k': os.system("konsole 2>/dev/null &") elif inp.startswith("filter:"): term = inp[inp.find(':')+1:] if last_key: perform_action(last_key, term) elif inp.startswith("app:"): val = inp[inp.find(':')+1:] if not val: apps.menu.main() else: apps.menu.start_app(val) # shortcuts elif inp == 'radio()': apps.menu.start_app_by_shortcut('radio') # disabled, always show the search hits #elif inp in tag2keys: # tag = inp # command(tag) elif re.search(r'^\d+$', inp): try: index = int(inp) - 1 if index < 0: raise IndexError tag = SearchHits.hits[index].tag command(tag) except IndexError: print("out of range...") elif re.search(r'^\d+\.(doc|action|tags|json|url|link|key|jet|edit)(\(\))?$', inp): try: pos = inp.find('.') index = int(inp[:pos]) - 1 what = inp[pos+1:].rstrip("()") if index < 0: raise IndexError hit = SearchHits.hits[index] hit.inspect(what) except IndexError: print("out of range...") elif re.search(r'^this.(doc|action|tags|json|url|link|key|jet|edit)(\(\))?$', inp): try: if not last_key: raise NoLastKeyError pos = inp.find('.') what = inp[pos+1:].rstrip("()") hit = Hit(tag=None, key=last_key) hit.inspect(what) except NoLastKeyError: pass elif inp == 'pid()': pidcheck.pid_alert() elif inp == 'debug()': debug(None) elif inp == 'song()': print("Playing:", apps.radio.get_song()) else: if len(inp) == 1: print("too short...") else: inp = inp.lower() SearchHits.show_hint(inp)
def prepare_ncbi_opener(): opener = prepare_opener(NCBI_URL) # Request used to initialize cookie. open_url(NCBI_URL, opener) return opener