PyInvestAnalyser is a Python project that uses web scraping to obtain data on financial assets. With the help of Selenium, Docker, and Pyenv libraries, you can analyze relevant information about different assets in an automated manner.
Before you start, make sure you have the following prerequisites installed:
- Python (recommended to use Pyenv for package management)
- Docker
Follow the steps below to install the project:
-
Clone this repository:
$ git clone https://github.com/ericksonlopes/PyInvestAnalyser.git
-
Access the project directory:
$ cd PyInvestAnalyser
-
Create and Install project dependencies:
$ pip install pipenv $ pipenv install
-
activate a virtual environment with Pyenv:
$ pipenv shell
-
Make sure Docker is running.
-
Run Docker Compose to start the execution environment:
$ docker-compose up -d
To use PyInvestAnalyser, follow these steps:
Import the ExtractInfoFromStock class for the respective type of asset you want to analyze (stocks, real estate funds, and DBRs):
Here is an example of how to import the ExtractInfoFromStock class to obtain information about the B3SA3 stock:
from src.services import ExtractInfoFromStock
stock = ExtractInfoFromStock().get_info_active('B3SA3')
print(stock)
# Stock(name='B3SA3', company_nam...
Additionally, providing context to a more complex example, you can execute a multi-threaded script to obtain information about multiple assets at the same time:
In this case, the script will obtain information about the stocks B3SA3, BBDC3, BBSE3, and BMGB4 and save the results in a CSV file.
import concurrent.futures
import csv
from src.models import Stock
from src.services import ExtractInfoFromStock
actives = [
'B3SA3',
'BBDC3',
'BBSE3',
'BMGB4'
]
result_actives = []
with concurrent.futures.ThreadPoolExecutor() as executor:
futures = [executor.submit(ExtractInfoFromStock().get_info_active, active) for active in actives]
for future in concurrent.futures.as_completed(futures):
try:
active = future.result()
if isinstance(active, str):
active = ExtractInfoFromStock().get_active_keys_indicators(active)
result_actives.append(active)
except Exception as e:
print(f'Error1: {str(e)}')
with open('result_for_actives.csv', 'w', newline='', encoding="utf-8") as file:
writer = csv.writer(file)
writer.writerow(Stock().get_meaning_of_fields().values())
for active in result_actives:
writer.writerow(active.__dict__.values())
If you want to contribute to the PyInvestAnalyser project, follow the steps below:
-
Fork the project
-
Create a new branch (git checkout -b feature/new-feature)
-
Make your changes
-
Commit your changes (git commit -am 'Add new feature')
-
Push to the branch (git push origin feature/new-feature)
-
Open a Pull Request
This project is licensed under the MIT License.