Python webbrowser.open() Examples
The following are 30
code examples of webbrowser.open().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
webbrowser
, or try the search function
.

Example #1
Source File: web.py From svviz with MIT License | 6 votes |
def run(port=None): import webbrowser, threading if port is None: port = getRandomPort() # load() url = "http://127.0.0.1:{}/".format(port) logging.info("Starting browser at {}".format(url)) # webbrowser.open_new(url) threading.Timer(1.25, lambda: webbrowser.open(url) ).start() app.run( port=port#, # debug=True )
Example #2
Source File: window.py From LPHK with GNU General Public License v3.0 | 6 votes |
def __init__(self, master=None): tk.Frame.__init__(self, master) self.master = master self.init_window() self.about_image = ImageTk.PhotoImage(Image.open(PATH + "/resources/LPHK-banner.png")) self.info_image = ImageTk.PhotoImage(Image.open(PATH + "/resources/info.png")) self.warning_image = ImageTk.PhotoImage(Image.open(PATH + "/resources/warning.png")) self.error_image = ImageTk.PhotoImage(Image.open(PATH + "/resources/error.png")) self.alert_image = ImageTk.PhotoImage(Image.open(PATH + "/resources/alert.png")) self.scare_image = ImageTk.PhotoImage(Image.open(PATH + "/resources/scare.png")) self.grid_drawn = False self.grid_rects = [[None for y in range(9)] for x in range(9)] self.button_mode = "edit" self.last_clicked = None self.outline_box = None
Example #3
Source File: kegg.py From bioservices with GNU General Public License v3.0 | 6 votes |
def show_module(self, modId): """Show a given module inside a web browser :param str modId: a valid module Id. See :meth:`moduleIds` Validity of modId is not checked but if wrong the URL will not open a proper web page. """ if modId.startswith("md:"): modId = modId.split(":")[1] url = "http://www.kegg.jp/module/" + modId self.logging.info(url) res = webbrowser.open(url) return res # wrapper of all databases to ease access to them (buffered)
Example #4
Source File: auth_fitbit.py From fitbit-googlefit with GNU General Public License v3.0 | 6 votes |
def headless_authorize(self): """ Authorize without a display using only TTY. """ url, _ = self.oauth.authorize_token_url(redirect_uri=self.redirect_uri) # Ask the user to open this url on a system with browser print('\n-------------------------------------------------------------------------') print('\t\tOpen the below URL in your browser\n') print(url) print('\n-------------------------------------------------------------------------\n') print('NOTE: After authenticating on Fitbit website, you will redirected to a URL which ') print('throws an ERROR. This is expected! Just copy the full redirected here.\n') redirected_url = input('Full redirected URL: ') params = urlparse.parse_qs(urlparse.urlparse(redirected_url).query) print(params['code'][0]) self.authenticate_code(code=params['code'][0])
Example #5
Source File: auth_fitbit.py From fitbit-googlefit with GNU General Public License v3.0 | 6 votes |
def main(): # Arguments parsing parser = argparse.ArgumentParser("Client ID and Secret are mandatory arguments") parser.add_argument("-i", "--id", required=True, help="Client id", metavar='<client-id>') parser.add_argument("-s", "--secret", required=True, help="Client secret", metavar='<client-secret>') parser.add_argument("-c", "--console", default=False, help="Authenticate only using console (for headless systems)", action="store_true") args = parser.parse_args() server = OAuth2Server(args.id, args.secret) if args.console: server.headless_authorize() else: server.browser_authorize() credentials = dict( client_id=args.id, client_secret=args.secret, access_token=server.oauth.token['access_token'], refresh_token=server.oauth.token['refresh_token']) json.dump(credentials, open('fitbit.json', 'w'))
Example #6
Source File: ModelingCloth.py From Modeling-Cloth with MIT License | 6 votes |
def collision_series(paperback=True, kindle=True): import webbrowser import imp if paperback: webbrowser.open("https://www.createspace.com/6043857") imp.reload(webbrowser) webbrowser.open("https://www.createspace.com/7164863") return if kindle: webbrowser.open("https://www.amazon.com/Resolve-Immortal-Flesh-Collision-Book-ebook/dp/B01CO3MBVQ") imp.reload(webbrowser) webbrowser.open("https://www.amazon.com/Formulacrum-Collision-Book-Rich-Colburn-ebook/dp/B0711P744G") return webbrowser.open("https://www.paypal.com/donate/?token=G1UymFn4CP8lSFn1r63jf_XOHAuSBfQJWFj9xjW9kWCScqkfYUCdTzP-ywiHIxHxYe7uJW&country.x=US&locale.x=US") # ============================================================================================
Example #7
Source File: RPSLS.py From Python-Scripts-and-Games with MIT License | 6 votes |
def main(): print('====== Menu ======') print('1. Play') print('2. See Source Code') print('3. Rules') print('4. Rules dictation by Sheldon Lee Cooper') print('5. Exit') inp = int(input('Enter Choice :')) if inp is 1: rpsls() elif inp is 3: rules() elif inp is 4: webbrowser.open('https://goo.gl/kR2653') elif inp is 5: exit() elif inp is 2: webbrowser.open('https://goo.gl/4TStoZ') if inp is not 5: main()
Example #8
Source File: pydoc.py From jawfish with MIT License | 6 votes |
def importfile(path): """Import a Python source file or compiled file given its path.""" magic = imp.get_magic() with open(path, 'rb') as file: if file.read(len(magic)) == magic: kind = imp.PY_COMPILED else: kind = imp.PY_SOURCE file.seek(0) filename = os.path.basename(path) name, ext = os.path.splitext(filename) try: module = imp.load_module(name, file, path, (ext, 'r', kind)) except: raise ErrorDuringImport(path, sys.exc_info()) return module
Example #9
Source File: client.py From Jike-Metro with MIT License | 6 votes |
def open_in_browser(url_or_message): if isinstance(url_or_message, str): url = url_or_message elif hasattr(url_or_message, 'linkInfo'): url = url_or_message.linkInfo['linkUrl'] elif 'linkInfo' in url_or_message: url = url_or_message['linkInfo']['linkUrl'] elif hasattr(url_or_message, 'content'): urls = extract_url(url_or_message.content) if urls: for url in urls: webbrowser.open(url) return else: raise ValueError('No url found') if not URL_VALIDATION_PATTERN.match(url): raise ValueError('Url invalid') else: webbrowser.open(url)
Example #10
Source File: notebook.py From pyGSTi with Apache License 2.0 | 6 votes |
def launch(self, outputFilename, templateFilename=DefaultTemplate, port='auto'): ''' Save and then launch this notebook Parameters ---------- outputFilename : str filename to save this notebook to templateFilename : str, optional filename to build this notebook from (see save_to) ''' self.save_to(outputFilename, templateFilename) outputFilename = _os.path.abspath(outputFilename) # for path manips below from notebook import notebookapp servers = list(notebookapp.list_running_servers()) for serverinfo in servers: rel = _os.path.relpath(outputFilename, serverinfo['notebook_dir']) if ".." not in rel: # notebook servers don't allow moving up directories if port == 'auto' or int(serverinfo['port']) == port: url = _os.path.join(serverinfo['url'], 'notebooks', rel) _browser.open(url); break else: print("No running notebook server found that is rooted above %s" % outputFilename)
Example #11
Source File: runTests.py From pyGSTi with Apache License 2.0 | 6 votes |
def run_mpi_coverage_tests(coverage_cmd, nproc=4): shutil.copy('mpi/setup.cfg.mpi', 'setup.cfg') #OLD: worked with python2.7, but not with 3 (where .coverage files turned to JSON) #mpicommands = ('time mpiexec -np %s python%s mpi/runtests.py -v ' % (str(nproc), '' if version is None else version)+ # '--with-coverage --cover-package=pygsti --cover-erase mpi/testmpi*.py ' + # '> ../output/coverage_tests_mpi.out 2>&1') mpicommands = ('time mpiexec -np %s %s run -p ' % (str(nproc), coverage_cmd) + '--source=pygsti mpi/runtests.py -v mpi/testmpi*.py ' + '> ../output/coverage_tests_mpi.out 2>&1') with open('../output/mpi_output.txt', 'w') as output: returned = subprocess.call(mpicommands, shell=True, stdout=output, stderr=output) with open('../output/mpi_output.txt', 'r') as output: print(output.read()) os.remove('setup.cfg') return returned
Example #12
Source File: ptinstaller.py From pythonista-tools-installer with MIT License | 6 votes |
def install(self, url, target_folder): tmp_zipfile = self.download(url) base_dir = os.path.splitext(os.path.basename(tmp_zipfile))[0] + '/' with open(tmp_zipfile, 'rb') as ins: zipfp = zipfile.ZipFile(ins) for name in zipfp.namelist(): data = zipfp.read(name) name = name.split(base_dir, 1)[-1] # strip the top-level target_folder if name == '': # skip top-level target_folder continue fname = os.path.join(target_folder, name) if fname.endswith('/'): # A target_folder if not os.path.exists(fname): os.makedirs(fname) else: with open(fname, 'wb') as fp: fp.write(data)
Example #13
Source File: application.py From sk1-wx with GNU General Public License v3.0 | 6 votes |
def call_after(self, *args): if config.make_font_cache_on_start: font_cache_update() if self.docs: return docs = self._get_docs() if config.new_doc_on_start and not docs: self.load_plugins() self.new() else: txt = _('To start, create new document or open existing') events.emit(events.APP_STATUS, txt) self.load_plugins() if not wal.IS_WX2: events.emit(events.NO_DOCS) self.update_actions() for item in docs: self.open(item)
Example #14
Source File: web.py From svviz with MIT License | 5 votes |
def display(): req = request.args.get('req', 0) if req == "progress": return jsonify(result="done") if req in ["alt", "ref", "amb"]: allele = req results = [] for name, sample in dataHub.samples.items(): # svg = open("{}.{}.svg".format(req, name)).read() track = sample.tracks[allele] track.render() svg = track.svg.asString("web") results.append({"name":name, "svg":svg}) for annotation in dataHub.alleleTracks[allele]: track = dataHub.alleleTracks[allele][annotation] track.render(spacing=5) annoSVG = track.svg.asString("web") results.append({"name":annotation, "svg":annoSVG}) return jsonify(results=results) if req == "counts": return jsonify(result=dataHub.getCounts()) return jsonify(result="unknown request: {}".format(req))
Example #15
Source File: help.py From vergeml with MIT License | 5 votes |
def __call__(self, args, env): _AI, topic = args topic = " ".join(topic) if topic == "tutorial": if webbrowser.open(_TUTORIAL_URL, new=2): print("Opened {} in a new browser tab.".format(_TUTORIAL_URL)) else: print("Could not access the web browser. Please use this URL to access the tutorial:") print(_TUTORIAL_URL) else: print(self.get_help(env, topic))
Example #16
Source File: picasa.py From pkmeter with BSD 3-Clause "New" or "Revised" License | 5 votes |
def open_current_image(self, widget): url = 'https://plus.google.com/photos/%(userid)s/albums/%(albumid)s/%(photoid)s' % { 'userid': self.data['user']['id'], 'albumid': self.data['album']['id'], 'photoid': self.data['photo']['id'], } log.info('Opening Picasa Image: %s', url) webbrowser.open(url)
Example #17
Source File: picasa.py From pkmeter with BSD 3-Clause "New" or "Revised" License | 5 votes |
def open_albums(self, widget): url = 'https://plus.google.com/photos/%s/albums' % self.data['user']['id'] log.info('Opening Picasa Albums: %s', url) webbrowser.open(url)
Example #18
Source File: sickbeard.py From pkmeter with BSD 3-Clause "New" or "Revised" License | 5 votes |
def open_sickbeard(self, widget): log.info('Opening Sickbeard: %s', self.host) webbrowser.open(self.host)
Example #19
Source File: wunderground.py From pkmeter with BSD 3-Clause "New" or "Revised" License | 5 votes |
def open_wunderground(self, widget): url = utils.rget(self.data, 'current_observation.ob_url', 'http://www.wunderground.com') #url = WEBSITE_URL % {'location':self.location} log.info('Opening WUnderground page: %s', url) webbrowser.open(url)
Example #20
Source File: gcal.py From pkmeter with BSD 3-Clause "New" or "Revised" License | 5 votes |
def open_gcal(self, widget): url = 'http://google.com/calendar' log.info('Opening Google Calendar: %s', url) webbrowser.open(url)
Example #21
Source File: sonarr.py From pkmeter with BSD 3-Clause "New" or "Revised" License | 5 votes |
def open_sonarr(self, widget): log.info('Opening Sonarr: %s', self.host) webbrowser.open(self.host)
Example #22
Source File: kegg.py From bioservices with GNU General Public License v3.0 | 5 votes |
def show_entry(self, entry): """Opens URL corresponding to a valid entry :: s.www_bget("path:hsa05416") """ url = "http://www.kegg.jp/dbget-bin/www_bget?" + entry self.logging.info(url) webbrowser.open(url)
Example #23
Source File: wikipathway.py From bioservices with GNU General Public License v3.0 | 5 votes |
def savePathwayAs(self, pathwayId, filename, revision=0, display=True): """Save a pathway. :param str pathwayId: the pathway identifier. :param str filename: the name of the file. If a filename extension is not provided the pathway will be saved as a pdf (default). :param int revisionNumb: the revision number of the pathway (use '0 for most recent version). :param bool display: if True the pathway will be displayed in your browser. .. note:: Method from bioservices. Not a WikiPathways function .. versionchanged:: 1.7 return PNG by default instead of PDF. PDF not working as of 20 Feb 2020 even on wikipathway website. """ if filename.find('.') == -1: filename = "%s.%s" %(filename,'pdf') filetype = filename.split('.')[-1] res = self.getPathwayAs(pathwayId, filetype=filetype, revision=revision) with open(filename,'wb') as f: import binascii try: #python3 newres = binascii.a2b_base64(bytes(res, "utf-8")) except: newres = binascii.a2b_base64(res) f.write(newres) if display: webbrowser.open(filename) f.close()
Example #24
Source File: services.py From bioservices with GNU General Public License v3.0 | 5 votes |
def pubmed(self, Id): """Open a pubmed Id into a browser tab :param Id: a valid pubmed Id in string or integer format. The URL is a concatenation of the pubmed URL http://www.ncbi.nlm.nih.gov/pubmed/ and the provided Id. """ url = "http://www.ncbi.nlm.nih.gov/pubmed/" import webbrowser webbrowser.open(url + str(Id))
Example #25
Source File: services.py From bioservices with GNU General Public License v3.0 | 5 votes |
def on_web(self, url): """Open a URL into a browser""" import webbrowser webbrowser.open(url)
Example #26
Source File: services.py From bioservices with GNU General Public License v3.0 | 5 votes |
def save_str_to_image(self, data, filename): """Save string object into a file converting into binary""" with open(filename,'wb') as f: import binascii try: #python3 newres = binascii.a2b_base64(bytes(data, "utf-8")) except: newres = binascii.a2b_base64(data) f.write(newres)
Example #27
Source File: ksp_plugin.py From SublimeKSP with GNU General Public License v3.0 | 5 votes |
def read_file_function(self, filepath): if filepath.startswith('http://'): from urllib.request import urlopen s = urlopen(filepath, timeout=5).read().decode('utf-8') return re.sub('\r+\n*', '\n', s) if self.base_path: filepath = os.path.join(self.base_path, filepath) filepath = os.path.abspath(filepath) view = CompileKspThread.find_view_by_filename(filepath, self.base_path) if view is None: s = codecs.open(filepath, 'r', 'utf-8').read() return re.sub('\r+\n*', '\n', s) else: return view.substr(sublime.Region(0, view.size()))
Example #28
Source File: ksp_plugin.py From SublimeKSP with GNU General Public License v3.0 | 5 votes |
def run(self): webbrowser.open('https://github.com/nojanath/SublimeKSP/wiki')
Example #29
Source File: ksp_plugin.py From SublimeKSP with GNU General Public License v3.0 | 5 votes |
def on_load(self, view): if self.is_probably_ksp_file(view): s = codecs.open(view.file_name(), 'r', 'latin-1').read() mixed_line_endings = re.search(r'\r(?!\n)', s) and '\r\n' in s if mixed_line_endings: s, changes = re.subn(r'\r+\n', '\n', s) # normalize line endings if changes: s = '\n'.join(x.rstrip() for x in s.split('\n')) # strip trailing white-space too while we're at it view.run_command('replace_text_with', {'new_text': s}) sublime.set_timeout(lambda: sublime.status_message('EOL characters automatically fixed. Please save to keep the changes.'), 100) self.set_ksp_syntax(view)
Example #30
Source File: auth_fitbit.py From fitbit-googlefit with GNU General Public License v3.0 | 5 votes |
def browser_authorize(self): """ Open a browser to the authorization url and spool up a CherryPy server to accept the response """ url, _ = self.oauth.authorize_token_url(redirect_uri=self.redirect_uri) # Open the web browser in a new thread for command-line browser support threading.Timer(1, webbrowser.open, args=(url,)).start() cherrypy.quickstart(self)