Develop a crawler and an API to represent data to clients
- Install django:
pip install django
- Instal django rest framework:
pip install djangorestframework
- Install numpy:
pip install numpy
- Install matplotlib:
pip install matplotlib
- Install selenium:
pip install selenium
- Download a webdriver
We go randomly because getLetter()
function returns a string with a length equal to 2 that generates randomly, and then it sends to the search box and we choose the first result, besides crawl data.
The important thing is to get ricCode or company ticker, we must get data from network tab in to inspect for example for the apple company the data is returned https://www.refinitiv.com/bin/esg/esgsearchresult?ricCode=AAPL.O
but we need APPL.O
. After all these, we have 5 thread that helps us in timing.
There are 2 apps, one is an account for authentication, and the second is for getting data to show clients. Two substantial point:
- after create apps, add to the settings
- put
AUTH_USER_MODEL = 'account.Account'
in settings to django knows about new user model.
There are two approaches to reading and showing data to clients, the first is converting CSV to SQLite, and Django ORM handles for us, but the other approach is to work with CSV.
- Add
ALLOWED_HOSTS = ['*']
to the settings. - build and run container:
sudo docker-compose up --build
- Through the container running, go inside the container to convert CSV to SQLite
- Command for go inside:
sudo docker exec -it CONTAINER_ID bash
- Run these commands:
apt update
,apt install sqlite3
,sqlite3 db.sqlite3
- Now you are inside the database, for convert run these commands:
.mode csv
,.import dataCompanies.csv refinitiv_refinitiv