google-stocks/README.md
2026-02-17 15:00:11 +00:00

75 lines
1.8 KiB
Markdown

# Google Stock Index Lookup
Small command-line tools that query Google Search for an index and print a single summary line.
## What It Does
- Runs a Google search for an index (currently `FTSE All Share` and `SPTMI`).
- Parses the finance summary from the results page.
- Prints one line in this format:
```text
<Index title>: <price> (<percent_change>%) <timestamp>
```
Examples:
```shell
$ ./ftse_all_share
FTSE All-Share Index: 5650.94 (0.31%) 17 Feb, 14:57 GMT
$ ./s_and_p_total_market
S&P Total Market Index (TMI): 6789.00 (-0.60%) 17 Feb, 09:57 GMT
```
## Requirements
- Python 3
- `playwright`
- `lxml`
- Playwright Chromium browser
## Installation
```shell
git clone https://git.4angle.com/edward/google-stocks.git
cd google-stocks
python3 -m pip install playwright lxml
python3 -m playwright install chromium
```
## Usage
Run from the repository root:
```shell
./ftse_all_share
./s_and_p_total_market
```
## How It Works
- Entrypoints:
- `ftse_all_share` (query: `FTSE All Share`)
- `s_and_p_total_market` (query: `SPTMI`)
- Core logic: `google_stocks/__init__.py`
- launches headless Chromium via Playwright
- saves raw SERP HTML to `~/lib/google_stocks/*_serp.html`
- parses the `data-attrid="Price"` section into structured fields
## Local Data and Auth
The tool uses and writes files in your home directory:
- auth state: `~/lib/auth/google.json`
- captured SERP HTML: `~/lib/google_stocks/`
Create directories if needed:
```shell
mkdir -p ~/lib/auth ~/lib/google_stocks
```
## Notes
- Parsing depends on Google SERP markup, which can change.
- If output breaks, inspect the newest saved SERP in `~/lib/google_stocks/`.
- Values and timestamps are reported in the market context shown by Google (for this project, `gl=uk`).
## Contributing
Issues and PRs are welcome.
## License
MIT. See `LICENSE`.