I wish there was a way to bulk upload a spreadsheet of bond serial numbers to https://www.treasurydirect.gov/BC/SBCPrice. There isn't. So I wrote a python script with Selenium Webdriver to parse a CSV containing the info needed to fill out the form and run it automatically.
Then, you just need to click save and copy and paste the table back into a spreadsheet for fiddling.
- Use Python 3.2+
- pip install -r requirements.txt
- Install geckodriver on your PATH for Firefox support
- copy your bonds.csv file to the root. don't add it to git, please. I don't want to know
- python bond_scraper.py --value_as_of=<month and year you want to calculate the value for> --bond_csv=<the file with the list of bonds to calculate>
- --value_as_of=11/2017
- --bond_csv=sample_bonds.csv (see included sample_bonds.csv for reference format)
- Once the script is done, you should be able to go to the Firefox instance that Selenium opened and save the results as a file