Skip to content

Scraper For Stock Information From Yahoo Finance Website

Notifications You must be signed in to change notification settings

hemanta212/stock-scraper

Repository files navigation

S-IN-S: Stock Info Scraper

Tests

Scrapes the stock information off the YahooAPI and StockAnalysis.com.

  • Supports SQLITE and PostgresQL database and allows exporting to CSVs

  • The Scraping Job runs every 6 hours here on github actions, saves to remote postgres and sqlite databases.

  • The postgresql database is hosted live at custom azure vps @ v.hemantasharma.com.np

  • You can obtain the build artifacts of data.csv and database.sqlite in releases section.

Instructions for local installation

  • Clone this repository
cd Stock-Scraper
python -m venv .venv
source .venv/bin/activate
python -m pip install -r requirements.txt
playwright install
python main.py

Sqlite db output will be created at data directory in current folder

Setting up Postgresql Database [Optional]

  1. Install postgres client and server:
sudo apt-get install postgresql postgresql-contrib postgresql-client
  1. Start the postgres service
sudo service postgresql start
  1. Login to the psql shell
sudo -i -u postgres psql
  1. Now create a user and password
CREATE USER sammy WITH PASSWORD 'password';

NOTE: Don't forget the ; semicolon, You should see the output CREATE ROLE

  1. And create a database using created user account
CREATE DATABASE sammydb OWNER sammy;
  1. Quit the psql shell
\q
  1. You can access created database with created user by,
psql -U name_of_user -d name_of_database
  1. Populate the .env file, Fill the dbname, username and password according to your above steps.
POSTGRES_HOST=localhost
POSTGRES_PORT=5432
POSTGRES_DB=yourDbName
POSTGRES_USER=yourUserName
POSTGRES_PASSWORD=yourPassword
  1. Run the script again.
python main.py
  1. Exporting Postgres to csv
python export.py

CSV file will be created inside data folder.