Search basic company data and copy to clipboard.
Checking a company's registered name, address, and number is something we might do several times a day. This script lets us search for a company name and quickly paste it to our clipboard from the command line.
- Install the required modules
- Write the script
- Use the script from the terminal
1. Install modules
For this example we need to employ the use of several pre-written modules, namely:
BeautifulSoup4 - an excellent module for easily grabbing content from websites (so long as the website it nicely written)
click - used to let us add 'arguments' to our python script when we ask for it (in this case, we the name of the company we are searching for)
pyperclip - provides functionality for copying data on to the clipboard (for copy and pasting)
If you are unsure how to install these modules, check the guide at python basics.
2. Write the script
This step is as simple as pasting the code below into a new python file.
Make a new file called company.py. in the terminal you can simply enter:
$ touch company.py
Now open it in your favourite text editor and enter the following:
3. Use the script from the terminal
Open your terminal, and go to the directory you saved company.py in. Use the
cd command to change directories.
We're going to do go over an important bit of know-how here, making the script generally executable. You can do so by entering the following command (for more detail on this, see setting up):
$ chmod 755 company.py
Now run the script by entering the following (note the inclusiong of the --c argument, which indicates that the next word enter is the company name we are searching for).
$ ./company.py --c greggs
If you entered the script correctly, you should see a number of options for the popular vendor of baked good with a corresponding number. Obviously, you can change the search term to any company you would like the information for. Here is what the output should look like:
Now that we have the output, we can enter the corresponding number in to the terminal to paste those details on to our clipboard, ready to paste into our document.