Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__pycache__
1 change: 1 addition & 0 deletions Procfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
web: gunicorn server:app
73 changes: 56 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,57 @@
# Fundamentus
Esta é uma pequena API feita em python3 para análise de ações da BOVESPA utilizando o site fundamentus (www.fundamentus.com.br), que retorna os
principais indicadores fundamentalistas em formato JSON.
A API utiliza o microframework Flask.
Também é possível utilizar via linha de comando.

# Linha de comando
$ python3 fundamentus.py

# API
Execute o server.py e conecte no endereço (ex.: http://127.0.0.1:5000/) com seu browser

# Requirements
Flask
lxml

Install with:
pip3 install -r required.txt

This is a simple Python3 API to help analysing BOVESPA stocks, it collects data (scraping) from the Fundamentus website (www.fundamentus.com.br), which contains important "fundamental indicators", and return it as JSON.

This API uses the Flask microframework, but it can also be used directly on command line.

## Development env setup

Install the dependencies:

`$ pip3 install -r requirements.txt`

## Command line usage

`$ python3 fundamentus.py`

## HTTP API

### Development API

`$ python3 server.py`

After starting the server, access the <http://127.0.0.1:5000/> URL on your browser.

### Production API

`$ gunicorn server:app`

After starting the server, access the <http://127.0.0.1:8000/> URL on your browser.

## Production deploy

You can easily deploy this API to production, using [Heroku](https://www.heroku.com/):

### Heroku initial setup

* First, you need to install the Heroku CLI, if you haven't yet: <https://devcenter.heroku.com/articles/heroku-cli>
* Then, you need to login to it `$ heroku login`
* Lastly, you need to create a heroku app `$ heroku create your-api-name-here`

### Deploy

You can deploy to heroku, with:

* `$ git push heroku master`

In case you are in a different branch, ex `develop`, you can deploy with:

* `$ git push heroku develop:master`

After deploying to heroku, you can access the API on <http://your-api-name-here.herokuapp.com/>

### Production troubleshooting

In case the production API on Heroku fails, you can visualize the logs with this command:

`$ heroku logs --tail`
7 changes: 0 additions & 7 deletions required.txt

This file was deleted.

8 changes: 8 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
click==7.1.2
Flask==1.1.2
gunicorn==20.0.4
itsdangerous==1.1.0
Jinja2==2.11.3
lxml==4.6.2
MarkupSafe==1.1.1
Werkzeug==1.0.1
5 changes: 3 additions & 2 deletions server.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
@app.route("/")
def json_api():
global lista, dia

# Then only update once a day
if dia == datetime.strftime(datetime.today(), '%d'):
return jsonify(lista)
Expand All @@ -22,4 +22,5 @@ def json_api():
lista = {outer_k: {inner_k: float(inner_v) for inner_k, inner_v in outer_v.items()} for outer_k, outer_v in lista.items()}
return jsonify(lista)

app.run(debug=True)
if __name__ == '__main__':
app.run(debug=True)