Problem Statement: It’s tedious to copy a street address to the clipboard and bring up a map of it on Google Maps. You could take a few steps out of this task by writing a simple script to automatically launch the map in your browser using the contents of your clipboard. This way, you only have to copy the address to a clipboard and run the script, and the map will be loaded for you. This is what your program does: Gets a street address from the command line arguments or clipboard. Opens the web browser to the Google Maps page for the address. This means your code will need to do the following: Read the command line arguments from sys.argv . Read the clipboard contents. Call the webbrowser.open() function to open the web browser. import webbrowser webbrowser.open('http://inventwithpython.com/') #! python3 # mapIt.py - Launches a map in the browser using an address from the # command line or clipboard. import webbrowser, sys if len(sys.argv) > 1: # Get address from command line. address = ' '.join(sys.argv[1:]) # TODO: Get address from clipboard.
! python3# mapIt.py - Launches a map in the browser using an address from the# command line or clipboard.import webbrowser, sys, pyperclip if len(sys.argv) > 1: # Get address from command line. address = ' '.join(sys.argv[1:]) else: # Get address from clipboard. address = pyperclip.paste() webbrowser.open('https://www.google.com/maps/place/' + address)
0 comments:
Post a Comment